Cmd/Meta/Attribute/Trait.pm untested

filter: Statementstmt 0.0% 0 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 19 CC 1 SCAR 6.9
CC
1
Cov
0%
register_implementation
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package MooseX::Role::Cmd::Meta::Attribute::Trait;
2 use Moose::Role;
3 use Moose::Util::TypeConstraints;
4  
5 =pod
6  
7 =head1 NAME
8  
9 MooseX::Role::Cmd::Meta::Attribute::Trait - Optional meta attribute trait for custom option names
10  
11 =head1 SYNOPSIS
12  
13 package MyApp::Cmd::SomeScript;
14
15 with 'MooseX::Role::Cmd';
16
17 has 'basic' => (
18 isa => 'Str',
19 is => 'rw',
20 );
21
22 has 'prefix' => (
23 traits => [ 'CmdOpt' ],
24 isa => 'Str',
25 is => 'rw',
26 cmdopt_prefix => '-',
27 );
28
29 has 'rename' => (
30 traits => [ 'CmdOpt' ],
31 isa => 'Str',
32 is => 'rw',
33 cmdopt_name => '+alt_name',
34 );
35
36
37 $cmd = MyApp::Cmd::SomeScript->new( basic => 'foo', prefix => 'bar', rename => 'foobar' );
38
39 $cmd->run();
40
41 # somescript --basic foo -prefix bar +alt_name foobar
42  
43 =head1 DESCRIPTION
44  
45 Provides some extra markup to help MooseX::Role::Cmd decide how to use command line parameters.
46  
47 =head1 ATTRIBUTES
48  
49 =head2 cmdopt_prefix
50  
51 Forces the command prefix to be a certain character. This was introduced to allow
52 parameters to be specified as "-param" or "--param"
53  
54 =head2 has_cmdopt_prefix
55  
56 Test for attribute above
57  
58 =cut
59  
60 has 'cmdopt_prefix' => (
61 is => 'rw',
62 isa => 'Str',
63 predicate => 'has_cmdopt_prefix',
64 );
65  
66 =head2 cmdopt_name
67  
68 Forces the command options name to be the passed string. This was introduced to allow
69 parameters to have a different name to the attribute.
70  
71 This option will override the L<cmdopt_prefix> attribute.
72  
73 =head2 has_cmdopt_name
74  
75 Test for attribute above
76  
77 =cut
78  
79 has 'cmdopt_name' => (
80 is => 'rw',
81 isa => 'Str',
82 predicate => 'has_cmdopt_name',
83 );
84  
85 =head2 cmdopt_env
86  
87 This attribute trait can be used to specify an environment variable rather
88 than a command line option.
89  
90 has 'home_dir' => (
91 traits => [ 'CmdOpt' ],
92 is => 'rw',
93 isa => 'Str',
94 cmdopt_env => 'APP_HOME',
95 default => '/my/app/home'
96 );
97
98 # $ENV{APP_HOME} = /my/app/home
99  
100 =cut
101  
102 =head2 has_cmdopt_env
103  
104 Test for attribute above
105  
106 =cut
107  
108 has 'cmdopt_env' => (
109 is => 'rw',
110 isa => 'Str',
111 predicate => 'has_cmdopt_env',
112 );
113  
114 no Moose::Role;
115  
116 # register this as a metaclass alias ...
117 package # stop confusing PAUSE
118 Moose::Meta::Attribute::Custom::Trait::CmdOpt;
119 sub register_implementation { 'MooseX::Role::Cmd::Meta::Attribute::Trait' }
120  
121 1;
122  
123 __END__