Created
May 29, 2010 12:10
-
-
Save j1n3l0/418248 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Modern::Perl; | |
use Test::Most; | |
{ | |
package Some::Role; | |
use Moose::Role; | |
use MooseX::Types::Moose qw( Str ); | |
has attribute => ( is => 'ro', isa => Str, default => 'default' ); | |
no Moose::Role; | |
} | |
{ | |
package Some::Class::With::Override; | |
use Moose; | |
with qw( Some::Role MooseX::Getopt ); | |
has '+attribute' => ( traits => ['NoGetopt'] ); | |
no Moose; | |
} | |
{ | |
package Some::Class::No::Override; | |
use Moose; | |
with qw( Some::Role MooseX::Getopt ); | |
no Moose; | |
} | |
{ | |
local @ARGV = (); | |
ok my $object = Some::Class::With::Override->new_with_options, | |
'can create object without attribute'; | |
is $object->attribute, 'default', '... and has default value'; | |
} | |
{ | |
local @ARGV = qw( --attribute test ); | |
dies_ok { Some::Class::With::Override->new_with_options } | |
'cannot create object with option "attribute"'; | |
} | |
{ | |
local @ARGV = qw( --attribute value ); | |
ok my $object = Some::Class::No::Override->new_with_options, | |
'can create object with attribute'; | |
is $object->attribute, 'value', '... and has provided value'; | |
} | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some times you want to consume a role into a command line application but you don't want it's attributes to show up on as command line options. This is a simple way to override the default traits of the attribute ... although I'm not sure if this will update or override the attributes original traits ;)