Skip Menu |

This queue is for tickets about the MooseX-Getopt CPAN distribution.

Report information
The Basics
Id: 30570
Status: resolved
Priority: 0/
Queue: MooseX-Getopt

People
Owner: stevan.little [...] gmail.com
Requestors: rkrimen [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Option conflicts with method names?
I want a command-line option of --from, so I define like so: has from => qw/is rw isa DateTime/; But when I try to instantiate via ->new_with_options I get this error: Prototype mismatch: sub Example::CLI::from ($) vs none at /usr/lib64/perl5/site_perl/5.8.8/Class/MOP/Package.pm line 101. I'm guessing because my option name conflicts with an existing Moose method. How would one get the command-line parser to recognize --from without a warning? The whole module is very basic: use Moose; use Moose::Util::TypeConstraints; use DateTimeX::Easy; with qw/MooseX::Getopt/; subtype 'DateTime' => as 'Object' => where { $_->isa('DateTime') }; coerce 'DateTime' => from 'Str' => via { datetime($_) }; has tally => qw/is rw isa Bool/; has edit => qw/is rw isa Bool/; has punch => qw/is rw isa Bool/; has from => qw/is rw isa Str/; has to => qw/is rw isa Str/; Hmm, I guess I could not import "from" from Moose::Util::TypeConstraints It might be better if the warning was clearer, though.
Putting in "no Moose::Util::TypeConstraints;" fixes it, but this may still be a problem if someone wants a --new option, etc.
Does something like this work for you? has 'foo_from' => ( # something more descriptive that "from" metaclass => 'MooseX::Getopt::Meta::Attribute', is => 'rw', isa => 'Str', cmd_flag => 'from', cmd_aliases => 'f', ); (IIRC, you have to do the explicit metaclass to get the cmd_* options). -- Brandon
not a bug, just needed better explaination of the feature.