Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: MooseX::GetOpt disable in role

by tobyink (Canon)
on Jun 21, 2013 at 10:58 UTC ( [id://1040125]=note: print w/replies, xml ) Need Help??


in reply to MooseX::GetOpt disable in role

You haven't posted the code for your disable_getopt_attribute function, but I guess it looks a little like this:

package My::App; use Moose::Role; # ... etc sub disable_getopt_attribute { has("+$_", traits => ['NoGetopt']) for @_; }

And you're calling it like this from classes:

package My::Script; use Moose; with "My::App"; My::App::disable_getopt_attribute(qw/ foo bar /);

Try changing the definition to this:

package My::App; use Moose::Role; # ... etc sub disable_getopt_attribute { my $class = shift; my $has = $class->can("has"); $has->("+$_", traits => ['NoGetopt']) for @_; }

And calling it like this:

package My::Script; use Moose; with "My::App"; __PACKAGE__->disable_getopt_attribute(qw/ foo bar /);

This way, the has function that gets called, is My::Script's copy of has; not My::App's copy of it.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Replies are listed 'Best First'.
Re^2: MooseX::GetOpt disable in role
by Boldra (Deacon) on Jun 21, 2013 at 11:54 UTC

    Thanks Tobyink!

    Your guess about how I was calling it was spot-on, and your solution works beautifully. I'm very grateful!



    - Boldra
Re^2: MooseX::GetOpt disable in role
by markjugg (Curate) on Aug 06, 2013 at 19:25 UTC
    If you always want to disable the same attributes for MooseX::Getopt from your role, then this worked for me:
    package My::Role::Getopt { use Moose::Role; with 'My::Role::DB'; with 'My::Role::Log'; with 'MooseX::Getopt::Dashes'; before 'process_argv' => sub { my $self = shift; my @attrs_to_exclude_from_getopt = ( '+db', ... ); for my $attr (@attrs_to_exclude_from_getopt) { $self->meta->add_attribute($attr => (traits => ['NoGetopt' +])); } }; no Moose::Role; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1040125]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-25 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found