App/Meta/Role/Attribute/Option.pm

filter: Statementstmt 80.8% 139 / 172 Branchbran 66.1% 78 / 118 Conditioncond 44.6% 29 / 65 MC/DCmcdc 22.8% 8 / 35 Subroutinesub 95.2% 20 / 21 Podpod 100% 9 / 9 totaltotal 67.3% 283 / 420 CC 82 SCAR 41.7
CC
82
Cov
69%
cmd_check
171.7
cmd_type_constraint_description
83.9
cmd_tags_list
24.9
CRAP 65.0
« App/Plugin/Term/Meta/Attribute.pm ↑ Summary App/Meta/Role/Class/Base.pm »
1 # ============================================================================
2 package MooseX::App::Meta::Role::Attribute::Option;
3 # ============================================================================
4  
5 16 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 16 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 16 ▶use List::Util qw(uniq first);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 16 has 'cmd_type' => (
14 is => 'rw',
15 isa => 'MooseX::App::Types::CmdTypes',
16 predicate => 'has_cmd_type',
17 );
18  
19 16 has 'cmd_tags' => (
20 is => 'rw',
21 isa => 'MooseX::App::Types::List',
22 coerce => 1,
23 predicate => 'has_cmd_tags',
24 );
25  
26 16 has 'cmd_flag' => (
27 is => 'rw',
28 isa => 'MooseX::App::Types::Identifier',
29 predicate => 'has_cmd_flag',
30 );
31  
32 16 has 'cmd_aliases' => (
33 is => 'rw',
34 isa => 'MooseX::App::Types::IdentifierList',
35 predicate => 'has_cmd_aliases',
36 coerce => 1,
37 );
38  
39 16 has 'cmd_split' => (
40 is => 'rw',
41 isa => Moose::Util::TypeConstraints::union([qw(Str RegexpRef)]),
42 predicate => 'has_cmd_split',
43 );
44  
45 has 'cmd_count' => (
46 is => 'rw',
47 isa => 'Bool',
48 189 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 16 );
50  
51 16 has 'cmd_negate' => (
52 is => 'rw',
53 isa => 'MooseX::App::Types::IdentifierList',
54 coerce => 1,
55 predicate => 'has_cmd_negate',
56 );
57  
58 16 has 'cmd_env' => (
59 is => 'rw',
60 isa => 'MooseX::App::Types::Env',
61 predicate => 'has_cmd_env',
62 );
63  
64 has 'cmd_position' => (
65 is => 'rw',
66 isa => 'Int',
67 150 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
68 16 );
69  
70 16 my $GLOBAL_COUNTER = 1;
71  
72 190 ▶around 'new' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
73 190 my $orig = shift;
74 190 my $class = shift;
75  
76 190 my $self = $class->$orig(@_);
77  
78 190 ▶ if ($self->has_cmd_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_cmd_type) 163 27 190
79 163 ▶ if ($self->cmd_position == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cmd_position == 0) 122 41 163
80 122 $GLOBAL_COUNTER++;
81 122 $self->cmd_position($GLOBAL_COUNTER);
82 }
83 }
84  
85 190 return $self;
86 16 };
87  
88 204 ▶sub cmd_check {
Subroutine cmd_check: called CC=27 SCAR=51.5
Pod documented
89 204 my ($self) = @_;
90  
91 204 my $name = $self->name;
92 204 my $from_constraint;
93 204 my $type_constraint = $self->type_constraint;
94 204 ▶ $from_constraint = $type_constraint->parameterized_from
Branch: 1 branch
BranchTrueFalseTotal
if $type_constraint and $type_constraint->isa("Moose::Meta::TypeConstraint::Parameterized") 0 204 204
Condition66%2/3
$type_constraint and $type_constraint->isa("Moose::Meta::TypeConstraint::Parameterized")
!ll&&!rl&&r
241800
MC/DC0%0/2
$type_constraint and $type_constraint->isa("Moose::Meta::TypeConstraint::Parameterized")
$type_constraint $type_constraint->isa("Moose::Meta::TypeConstraint::Parameterized")
Truth table66%2/3
A and B
A= $type_constraintB= $type_constraint->isa("Moose::Meta::TypeConstraint::Parameterized")
ABresult
0X0
100
111
95 if $type_constraint && $type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized');
96  
97 204 my $cmd_type = ucfirst($self->cmd_type);
98  
99 # Check for useless flags
100 204 ▶ if ($self->cmd_type eq 'parameter') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cmd_type eq 'parameter') { } 0 204 204
101 0 ▶ if ($self->cmd_count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cmd_count) 0 0 0
102 0 Moose->throw_error("Parameter $name has 'cmd_count'. This attribute only works with options");
103 }
104 0 ▶ if ($self->has_cmd_negate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_cmd_negate) 0 0 0
105 0 Moose->throw_error("Parameter $name has 'cmd_negate'. This attribute only works with options");
106 }
107 0 ▶ if ($self->has_cmd_negate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_cmd_negate) 0 0 0
108 0 Moose->throw_error("Parameter $name has 'cmd_negate'. This attribute only works with options");
109 }
110 0 ▶ if (defined $type_constraint
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type_constraint and $type_constraint->is_a_type_of("Bool")) 0 0 0
Condition0%0/3
defined $type_constraint and $type_constraint->is_a_type_of("Bool")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $type_constraint and $type_constraint->is_a_type_of("Bool")
defined $type_constraint $type_constraint->is_a_type_of("Bool")
Truth table0%0/3
A and B
A= defined $type_constraintB= $type_constraint->is_a_type_of("Bool")
ABresult
0X0
100
111
111 && $type_constraint->is_a_type_of('Bool')) {
112 0 Moose->throw_error("Parameter $name has 'cmd_negate'. This attribute only works with options");
113 }
114 0 ▶ if (($from_constraint && $from_constraint->is_a_type_of('Ref'))
Branch: 1 branch
BranchTrueFalseTotal
if ($from_constraint and $from_constraint->is_a_type_of("Ref") or $type_constraint and $type_constraint->is_a_type_of("Ref")) 0 0 0
Condition0%0/9
$from_constraint and $from_constraint->is_a_type_of("Ref") or $type_constraint and $type_constraint->is_a_type_of("Ref")
l!l&&r!l&&!r
000
$from_constraint and $from_constraint->is_a_type_of("Ref")
!ll&&!rl&&r
000
$type_constraint and $type_constraint->is_a_type_of("Ref")
!ll&&!rl&&r
000
MC/DC0%0/4
$from_constraint and $from_constraint->is_a_type_of("Ref") or $type_constraint and $type_constraint->is_a_type_of("Ref")
$from_constraint $from_constraint->is_a_type_of("Ref") $type_constraint $type_constraint->is_a_type_of("Ref")
Truth table0%0/7
A and B or C and D
A= $from_constraintB= $from_constraint->is_a_type_of("Ref")C= $type_constraintD= $type_constraint->is_a_type_of("Ref")
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
115 || ($type_constraint && $type_constraint->is_a_type_of('Ref'))) {
116 0 Moose->throw_error("Parameter $name may not have Ref type constraints");
117 }
118 } else {
119 204 ▶ if ((!$type_constraint || ! $type_constraint->is_a_type_of('Bool'))
Branch: 1 branch
BranchTrueFalseTotal
if (not $type_constraint && $type_constraint->is_a_type_of("Bool") and &first(sub { length $_ == 1; } , $self->cmd_name_list)) 1 203 204
Condition100%6/6
not $type_constraint && $type_constraint->is_a_type_of("Bool") and &first(sub { length $_ == 1; } , $self->cmd_name_list)
!ll&&!rl&&r
146571
$type_constraint && $type_constraint->is_a_type_of('Bool')
!ll&&!rl&&r
2434146
MC/DC66%2/3
not $type_constraint && $type_constraint->is_a_type_of("Bool") and &first(sub { length $_ == 1; } , $self->cmd_name_list)
$type_constraint $type_constraint->is_a_type_of('Bool') &first(sub { length $_ == 1; } , $self->cmd_name_list)
Truth table80%4/5
not(A && B) and C
A= $type_constraintB= $type_constraint->is_a_type_of('Bool')C= &first(sub { length $_ == 1; } , $self->cmd_name_list)
ABCresult
11X0
0X00
1000
0X11
1011
120 59 ▶ && first { length($_) == 1 } $self->cmd_name_list) {
Subroutine __ANON__: called CC=1 SCAR=0.0
121 1 Moose->throw_error("Option $name has a single letter flag but no Bool type constraint");
122 }
123  
124 # Check negate
125 203 ▶ if ($self->has_cmd_negate
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_cmd_negate and not $type_constraint && $type_constraint->is_a_type_of("Bool")) 0 203 203
Condition50%3/6
$self->has_cmd_negate and not $type_constraint && $type_constraint->is_a_type_of("Bool")
!ll&&!rl&&r
19760
$type_constraint && $type_constraint->is_a_type_of('Bool')
!ll&&!rl&&r
006
MC/DC0%0/3
$self->has_cmd_negate and not $type_constraint && $type_constraint->is_a_type_of("Bool")
$self->has_cmd_negate $type_constraint $type_constraint->is_a_type_of('Bool')
Truth table50%2/4
A and not(B && C)
A= $self->has_cmd_negateB= $type_constraintC= $type_constraint->is_a_type_of('Bool')
ABCresult
0XX0
1110
10X1
1101
126 && (!$type_constraint || ! $type_constraint->is_a_type_of('Bool'))) {
127 0 Moose->throw_error("Option $name has 'cmd_negate' but has no Bool type constraint");
128 }
129 }
130  
131 # Check type constraints
132 203 ▶ if (defined $type_constraint) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type_constraint) 179 24 203
133 179 ▶ if ($self->cmd_count
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cmd_count and not $type_constraint->is_a_type_of("Num")) 0 179 179
Condition33%1/3
$self->cmd_count and not $type_constraint->is_a_type_of("Num")
!ll&&!rl&&r
17900
MC/DC0%0/2
$self->cmd_count and not $type_constraint->is_a_type_of("Num")
$self->cmd_count not $type_constraint->is_a_type_of("Num")
Truth table33%1/3
A and not(B)
A= $self->cmd_countB= not $type_constraint->is_a_type_of("Num")
ABresult
0X0
100
111
134 && ! $type_constraint->is_a_type_of('Num')) {
135 0 Moose->throw_error("$cmd_type $name has 'cmd_count' but has no Num/Int type constraint");
136 }
137 179 ▶ if ($self->has_cmd_split
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_cmd_split and not $from_constraint && $from_constraint->is_a_type_of("ArrayRef") || $type_constraint->is_a_type_of("ArrayRef")) 0 179 179
Condition11%1/9
$self->has_cmd_split and not $from_constraint && $from_constraint->is_a_type_of("ArrayRef") || $type_constraint->is_a_type_of("ArrayRef")
!ll&&!rl&&r
17900
$from_constraint && $from_constraint->is_a_type_of('ArrayRef') || $type_constraint->is_a_type_of('ArrayRef')
l!l&&r!l&&!r
000
$from_constraint and $from_constraint->is_a_type_of("ArrayRef")
!ll&&!rl&&r
000
MC/DC0%0/4
$self->has_cmd_split and not $from_constraint && $from_constraint->is_a_type_of("ArrayRef") || $type_constraint->is_a_type_of("ArrayRef")
$self->has_cmd_split $from_constraint $from_constraint->is_a_type_of("ArrayRef") $type_constraint->is_a_type_of('ArrayRef')
Truth table16%1/6
A and not(B and C || D)
A= $self->has_cmd_splitB= $from_constraintC= $from_constraint->is_a_type_of("ArrayRef")D= $type_constraint->is_a_type_of('ArrayRef')
ABCDresult
0XXX0
111X0
10X10
11010
10X01
11001
138 && ! (
139 ($from_constraint && $from_constraint->is_a_type_of('ArrayRef'))
140 || $type_constraint->is_a_type_of('ArrayRef'))
141 ) {
142 0 Moose->throw_error("$cmd_type $name has 'cmd_split' but has no ArrayRef type constraint");
143 }
144 }
145  
146 # Check for uniqness
147 203 my @names = $self->cmd_name_possible;
148 203 ▶ if (scalar(uniq(@names)) != scalar(@names)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar &uniq(@names) != scalar @names) 0 203 203
149 0 Moose->throw_error("$cmd_type $name has duplicate names/aliases");
150 }
151  
152 203 return;
153 }
154  
155 5 ▶sub cmd_type_constraint_description {
Subroutine cmd_type_constraint_description: called CC=15 SCAR=44.3
Pod documented
156 5 my ($self,$type_constraint,$singular) = @_;
157  
158 5 ▶ $type_constraint //= $self->type_constraint;
Condition33%1/3
$type_constraint //= $self->type_constraint
l!l&&r!l&&!r
500
MC/DC0%0/2
$type_constraint //= $self->type_constraint
$type_constraint $self->type_constraint
Truth table33%1/3
A //= B
A= $type_constraintB= $self->type_constraint
ABresult
1X1
011
000
159 5 ▶ $singular //= 1;
Condition50%1/2
$singular //= 1
l!l
05
MC/DC0%0/1
$singular //= 1
$singular
Truth table50%1/2
A
A= $singular
Aresult
11
00
160  
161 5 ▶ if ($type_constraint->isa('Moose::Meta::TypeConstraint::Enum')) {
Branch: 6 branches
BranchTrueFalseTotal
if ($type_constraint->isa('Moose::Meta::TypeConstraint::Enum')) { } 0 5 5
elsif ($type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) { } 0 5 5
elsif ($type_constraint->equals('Int')) { } 4 1 5
elsif ($type_constraint->equals('Num')) { } 1 0 1
elsif ($type_constraint->equals('Str')) { } 0 0 0
elsif ($type_constraint->equals('HashRef')) { } 0 0 0
162 0 return 'one of these values: '.join(', ',@{$type_constraint->values});
163 } elsif ($type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
164 0 my $from = $type_constraint->parameterized_from;
165 0 ▶ if ($from->is_a_type_of('ArrayRef')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($from->is_a_type_of('ArrayRef')) { } 0 0 0
elsif ($from->is_a_type_of('HashRef')) { } 0 0 0
166 0 return $self->cmd_type_constraint_description($type_constraint->type_parameter);
167 } elsif ($from->is_a_type_of('HashRef')) {
168 0 return 'key-value pairs of '.$self->cmd_type_constraint_description($type_constraint->type_parameter,0);
169 }
170 # TODO union
171 } elsif ($type_constraint->equals('Int')) {
172 4 ▶ return $singular ? 'an integer':'integers'; # LOCALIZE
Branch: 1 branch
BranchTrueFalseTotal
$singular ? : 4 0 4
173 } elsif ($type_constraint->equals('Num')) {
174 1 ▶ return $singular ? 'a number':'numbers'; # LOCALIZE
Branch: 1 branch
BranchTrueFalseTotal
$singular ? : 1 0 1
175 } elsif ($type_constraint->equals('Str')) {
176 0 ▶ return $singular ? 'a string':'strings';
Branch: 1 branch
BranchTrueFalseTotal
$singular ? : 0 0 0
177 } elsif ($type_constraint->equals('HashRef')) {
178 0 return 'key-value pairs'; # LOCALIZE
179 }
180  
181 0 ▶ if ($type_constraint->has_parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_constraint->has_parent) 0 0 0
182 0 return $self->cmd_type_constraint_description($type_constraint->parent);
183 }
184  
185 0 return;
186 }
187  
188 112 ▶sub cmd_type_constraint_check {
Subroutine cmd_type_constraint_check: called CC=8 SCAR=22.4
Pod documented
189 112 my ($self,$value) = @_;
190  
191 return
192 112 ▶ unless ($self->has_type_constraint);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_type_constraint 0 112 112
193 112 my $type_constraint = $self->type_constraint;
194  
195 112 ▶ if ($type_constraint->has_coercion) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_constraint->has_coercion) 2 110 112
196 2 $value = $type_constraint->coerce($value)
197 }
198  
199 # Check type constraints
200 112 ▶ unless ($type_constraint->check($value)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type_constraint->check($value)) 7 105 112
201 7 ▶ if (ref($value) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 7 7
elsif (ref $value eq 'HASH') { } 0 7 7
202 0 $value = join(', ',grep { defined } @$value);
203 } elsif (ref($value) eq 'HASH') {
204 0 $value = join(', ',map { $_.'='.$value->{$_} } keys %$value)
205 }
206  
207 # We have a custom message
208 7 ▶ if ($type_constraint->has_message) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_constraint->has_message) { } 2 5 7
209 2 return $type_constraint->get_message($value);
210 # No message
211 } else {
212 5 my $message_human = $self->cmd_type_constraint_description($type_constraint);
213 5 ▶ if (defined $message_human) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $message_human) { } 5 0 5
214 5 return "Value must be ". $message_human ." (not '$value')";
215 } else {
216 0 return $type_constraint->get_message($value);
217 }
218 }
219 }
220  
221 105 return;
222 }
223  
224 195 ▶sub cmd_usage_description {
Subroutine cmd_usage_description: called CC=4 SCAR=13.9
Pod documented
225 195 my ($self) = @_;
226  
227 195 ▶ my $description = ($self->has_documentation) ? $self->documentation : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->has_documentation ? : 93 102 195
228 195 my @tags = $self->cmd_tags_list();
229 195 ▶ if (scalar @tags) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @tags) 145 50 195
230 145 ▶ $description .= ' '
Branch: 1 branch
BranchTrueFalseTotal
if $description 76 69 145
231 if $description;
232 145 $description .= '['.join('; ',@tags).']';
233 }
234 195 return $description
235 }
236  
237 251 ▶sub cmd_usage_name {
Subroutine cmd_usage_name: called CC=3 SCAR=11.0
Pod documented
238 251 my ($self) = @_;
239  
240 251 ▶ if ($self->cmd_type eq 'parameter') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cmd_type eq 'parameter') { } 42 209 251
241 42 return $self->cmd_name_primary;
242 } else {
243 return join(' ',
244 209 ▶ map { (length($_) == 1) ? "-$_":"--$_" }
Branch: 1 branch
BranchTrueFalseTotal
length $_ == 1 ? : 90 250 340
245 $self->cmd_name_possible
246 );
247 }
248 }
249  
250 1257 ▶sub cmd_name_primary {
Subroutine cmd_name_primary: called CC=2 SCAR=6.9
Pod documented
251 1257 my ($self) = @_;
252  
253 1257 ▶ if ($self->has_cmd_flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_cmd_flag) { } 342 915 1257
254 342 return $self->cmd_flag;
255 } else {
256 915 return $self->name;
257 }
258 }
259  
260 1158 ▶sub cmd_name_list {
Subroutine cmd_name_list: called CC=2 SCAR=6.9
Pod documented
261 1158 my ($self) = @_;
262  
263 1158 my @names = ($self->cmd_name_primary);
264  
265 1158 ▶ if ($self->has_cmd_aliases) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_cmd_aliases) 276 882 1158
266 276 push(@names, @{$self->cmd_aliases});
267 }
268  
269 1158 return @names;
270 }
271  
272 748 ▶sub cmd_name_possible {
Subroutine cmd_name_possible: called CC=3 SCAR=11.1
Pod documented
273 748 my ($self) = @_;
274  
275 748 ▶ if ($self->cmd_type eq 'parameter') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cmd_type eq "parameter") 0 748 748
276 0 return $self->cmd_name_primary;
277 }
278  
279 748 my @names = $self->cmd_name_list();
280  
281 # TODO check boolean type constraint
282 748 ▶ if ($self->has_cmd_negate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_cmd_negate) 18 730 748
283 18 push(@names, @{$self->cmd_negate});
284 }
285  
286 748 return @names;
287 }
288  
289 198 ▶sub cmd_tags_list {
Subroutine cmd_tags_list: called CC=24 SCAR=32.2
Pod documented
290 198 my ($self) = @_;
291  
292 198 my @tags;
293  
294 198 ▶ if ($self->is_required
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_required and not $self->is_lazy_build and not $self->has_default) 25 173 198
Condition83%5/6
$self->is_required and not $self->is_lazy_build and not $self->has_default
!ll&&!rl&&r
170325
$self->is_required and not $self->is_lazy_build
!ll&&!rl&&r
170028
MC/DC66%2/3
$self->is_required and not $self->is_lazy_build and not $self->has_default
$self->is_required not $self->is_lazy_build not $self->has_default
Truth table75%3/4
A and not(B) and not(C)
A= $self->is_requiredB= not $self->is_lazy_buildC= not $self->has_default
ABCresult
0XX0
10X0
1100
1111
295 && ! $self->is_lazy_build
296 && ! $self->has_default) {
297 25 push(@tags,'Required')
298 }
299  
300 198 ▶ if ($self->has_default && ! $self->is_default_a_coderef) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_default and not $self->is_default_a_coderef) 1 197 198
Condition100%3/3
$self->has_default and not $self->is_default_a_coderef
!ll&&!rl&&r
19431
MC/DC100%2/2
$self->has_default and not $self->is_default_a_coderef
$self->has_default not $self->is_default_a_coderef
Truth table100%3/3
A and not(B)
A= $self->has_defaultB= not $self->is_default_a_coderef
ABresult
0X0
100
111
301 1 ▶ if ($self->has_type_constraint
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_type_constraint and $self->type_constraint->is_a_type_of('Bool')) { } 1 0 1
Condition33%1/3
$self->has_type_constraint and $self->type_constraint->is_a_type_of("Bool")
!ll&&!rl&&r
001
MC/DC0%0/2
$self->has_type_constraint and $self->type_constraint->is_a_type_of("Bool")
$self->has_type_constraint $self->type_constraint->is_a_type_of("Bool")
Truth table33%1/3
A and B
A= $self->has_type_constraintB= $self->type_constraint->is_a_type_of("Bool")
ABresult
0X0
100
111
302 && $self->type_constraint->is_a_type_of('Bool')) {
303 # if ($attribute->default) {
304 # push(@tags,'Default:Enabled');
305 # } else {
306 # push(@tags,'Default:Disabled');
307 # }
308 } else {
309 0 push(@tags,'Default:"'.$self->default.'"');
310 }
311 }
312  
313 198 ▶ if ($self->has_cmd_split) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_cmd_split) 5 193 198
314 5 my $split = $self->cmd_split;
315 5 ▶ if (ref($split) eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $split eq "Regexp") 5 0 5
316 5 $split = "$split";
317 5 $split =~ s/^\(\?\^\w*:(.+)\)$/$1/x;
318 }
319 5 push(@tags,'Multiple','Split by "'.$split.'"');
320 }
321  
322 198 ▶ if ($self->has_type_constraint) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_type_constraint) 171 27 198
323 171 my $type_constraint = $self->type_constraint;
324 171 ▶ if ($type_constraint->is_a_type_of('ArrayRef')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type_constraint->is_a_type_of('ArrayRef')) { } 10 161 171
elsif ($type_constraint->is_a_type_of('HashRef')) { } 5 156 161
325 10 ▶ if (! $self->has_cmd_split) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_cmd_split) 5 5 10
326 5 push(@tags,'Multiple');
327 }
328 } elsif ($type_constraint->is_a_type_of('HashRef')) {
329 5 push(@tags,'Key-Value');
330 }
331 171 ▶ unless ($self->should_coerce) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->should_coerce) 166 5 171
332 166 ▶ if ($type_constraint->is_a_type_of('Int')) {
Branch: 4 branches
BranchTrueFalseTotal
if ($type_constraint->is_a_type_of('Int')) { } 39 127 166
elsif ($type_constraint->is_a_type_of('Num')) { } 5 122 127
elsif ($type_constraint->is_a_type_of('Bool')) { } 60 62 122
elsif ($type_constraint->isa('Moose::Meta::TypeConstraint::Enum')) { } 9 53 62
333 39 push(@tags,'Integer');
334 } elsif ($type_constraint->is_a_type_of('Num')) {
335 5 push(@tags ,'Number');
336 } elsif ($type_constraint->is_a_type_of('Bool')) {
337 60 push(@tags ,'Flag');
338 } elsif ($type_constraint->isa('Moose::Meta::TypeConstraint::Enum')) {
339 9 push(@tags ,'Possible values: '.join(', ',@{$type_constraint->values}));
340 }
341 }
342 }
343  
344 198 ▶ if ($self->can('has_cmd_env')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("has_cmd_env") and $self->has_cmd_env) 14 184 198
Condition66%2/3
$self->can("has_cmd_env") and $self->has_cmd_env
!ll&&!rl&&r
018414
MC/DC50%1/2
$self->can("has_cmd_env") and $self->has_cmd_env
$self->can("has_cmd_env") $self->has_cmd_env
Truth table66%2/3
A and B
A= $self->can("has_cmd_env")B= $self->has_cmd_env
ABresult
0X0
100
111
345 && $self->has_cmd_env) {
346 14 push(@tags,'Env: '.$self->cmd_env)
347 }
348  
349 198 ▶ if ($self->can('cmd_tags')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("cmd_tags") and $self->can("cmd_tags") and $self->has_cmd_tags) 29 169 198
Condition50%3/6
$self->can("cmd_tags") and $self->can("cmd_tags") and $self->has_cmd_tags
!ll&&!rl&&r
016929
$self->can("cmd_tags") and $self->can("cmd_tags")
!ll&&!rl&&r
00198
MC/DC33%1/3
$self->can("cmd_tags") and $self->can("cmd_tags") and $self->has_cmd_tags
$self->can("cmd_tags") $self->can("cmd_tags") $self->has_cmd_tags
Truth table50%2/4
A and B and C
A= $self->can("cmd_tags")B= $self->can("cmd_tags")C= $self->has_cmd_tags
ABCresult
0XX0
10X0
1100
1111
350 && $self->can('cmd_tags')
351 && $self->has_cmd_tags) {
352 29 push(@tags,@{$self->cmd_tags});
353 }
354  
355 198 return @tags;
356 }
357  
358 {
359 package Moose::Meta::Attribute::Custom::Trait::AppOption;
360  
361 16 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
362 16 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
363  
364 0 ▶ sub register_implementation { return 'MooseX::App::Meta::Role::Attribute::Option' }
Subroutine register_implementation: not called CC=1 SCAR=6.9
365 }
366  
367 16 1;
368  
369 =pod
370  
371 =encoding utf8
372  
373 =head1 NAME
374  
375 MooseX::App::Meta::Role::Attribute::Option - Meta attribute role for options
376  
377 =head1 DESCRIPTION
378  
379 This meta attribute role will automatically be applied to all attributes
380 that should be used as options.
381  
382 =head1 ACCESSORS
383  
384 In your app and command classes you can
385 use the following attributes in option or parameter definitions.
386  
387 option 'myoption' => (
388 is => 'rw',
389 isa => 'ArrayRef[Str]',
390 documentation => 'My special option',
391 cmd_flag => 'myopt',
392 cmd_aliases => [qw(mopt localopt)],
393 cmd_tags => [qw(Important!)],
394 cmd_env => 'MY_OPTION',
395 cmd_position => 1,
396 cmd_split => qr/,/,
397 cmd_negate => 'notoption'
398 );
399  
400 =head2 cmd_flag
401  
402 Use this name instead of the attribute name as the option name
403  
404 =head2 cmd_type
405  
406 Option to mark if this attribute should be used as an option or parameter value.
407  
408 Allowed values are:
409  
410 =over
411  
412 =item * option - Command line option
413  
414 =item * proto - Command line option that should be processed prior to other
415 options (eg. a config-file option that sets other attribues) Usually only
416 used for plugin developmemt
417  
418 =item * parameter - Positional parameter command line value
419  
420 =back
421  
422 =head2 cmd_env
423  
424 Environment variable name (only uppercase letters, numeric and underscores
425 allowed). If variable was not specified otherwise the value will be
426 taken from %ENV.
427  
428 =head2 cmd_aliases
429  
430 Arrayref of alternative option names
431  
432 =head2 cmd_tags
433  
434 Extra option tags displayed in the usage information (in brackets)
435  
436 =head2 cmd_position
437  
438 Override the order of the parameters in the usage message.
439  
440 =head2 cmd_split
441  
442 Splits multiple values at the given separator string or regular expression.
443 Only works in conjunction with an 'ArrayRef[*]' type constraint.
444 ie. '--myattr value1,value2' with cmd_split set to ',' would produce an
445 arrayref with to elements.
446  
447 =head2 cmd_count
448  
449 Similar to the Getopt::Long '+' modifier, cmd_count turns the attribute into
450 a counter. Every occurrence of the attribute in @ARGV (without any value)
451 would increment the resulting value by one
452  
453 =head2 cmd_negate
454  
455 Sets names for the negated variant of a boolean field. Only works in conjunction
456 with a 'Bool' type constraint.
457  
458 =head1 METHODS
459  
460 These methods are only of interest to plugin authors.
461  
462 =head2 cmd_check
463  
464 Runs sanity checks on options and parameters. Will usually only be executed if
465 either HARNESS_ACTIVE or APP_DEVELOPER environment are set.
466  
467 =head2 cmd_name_possible
468  
469 my @names = $attribute->cmd_name_possible();
470  
471 Returns a list of all possible option names.
472  
473 =head2 cmd_name_list
474  
475 my @names = $attribute->cmd_name_list();
476  
477 Similar to cmd_name_possible this method returns a list of option names,
478 except for names set via cmd_negate.
479  
480 =head2 cmd_name_primary
481  
482 my $name = $attribute->cmd_name_primary();
483  
484 Returns the primary option name
485  
486 =head2 cmd_usage_name
487  
488 my $name = $attribute->cmd_usage_name();
489  
490 Returns the name as used by the usage text
491  
492 =head2 cmd_usage_description
493  
494 my $name = $attribute->cmd_usage_description();
495  
496 Returns the description as used by the usage text
497  
498 =head2 cmd_tags_list
499  
500 my @tags = $attribute->cmd_tags_list();
501  
502 Returns a list of tags
503  
504 =head2 cmd_type_constraint_check
505  
506 $attribute->cmd_type_constraint_check($value)
507  
508 Checks the type constraint. Returns an error message if the check fails
509  
510 =head2 cmd_type_constraint_description
511  
512 $attribute->cmd_type_constraint_description($type_constraint,$singular)
513  
514 Creates a description of the selected type constraint.
515  
516 =cut
517  
« App/Plugin/Term/Meta/Attribute.pm ↑ Summary App/Meta/Role/Class/Base.pm »