App/ParsedArgv/Element.pm

filter: Statementstmt 71.4% 30 / 42 Branchbran 31.2% 5 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 10 / 12 Podpod 100% 7 / 7 totaltotal 64.6% 53 / 82 CC 10 SCAR 21.7
CC
10
Cov
59%
serialize
30.0
original
3.8
add_value
3.0
CRAP 8.7
« App/Exporter.pm ↑ Summary App/Plugin/Man/Command.pm »
1 # ============================================================================
2 package MooseX::App::ParsedArgv::Element;
3 # ============================================================================
4  
5 17 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 17 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 17 has 'key' => (
11 is => 'ro',
12 isa => 'Str',
13 required => 1,
14 );
15  
16 has 'value' => (
17 is => 'ro',
18 isa => 'ArrayRef[MooseX::App::ParsedArgv::Value]',
19 traits => ['Array'],
20 154 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
21 17 handles => {
22 push_value => 'push',
23 count_values => 'count',
24 list_values => 'elements',
25 }
26 );
27  
28 has 'consumed' => (
29 is => 'rw',
30 isa => 'Bool',
31 154 ▶ default => sub {0},
Subroutine __ANON__: called CC=1 SCAR=0.0
32 17 );
33  
34 17 has 'type' => (
35 is => 'ro',
36 isa => 'Str',
37 required => 1,
38 );
39  
40  
41 2 ▶sub original {
Subroutine original: called CC=3 SCAR=13.3
Pod documented
42 2 my ($self) = @_;
43  
44 # TODO fixthis
45 2 ▶ if ($self->count_values && $self->value->[-1]->has_raw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->count_values and $self->value->[-1]->has_raw) { } 0 2 2
Condition33%1/3
$self->count_values and $self->value->[-1]->has_raw
!ll&&!rl&&r
020
MC/DC0%0/2
$self->count_values and $self->value->[-1]->has_raw
$self->count_values $self->value->[-1]->has_raw
Truth table33%1/3
A and B
A= $self->count_valuesB= $self->value->[-1]->has_raw
ABresult
0X0
100
111
46 0 return $self->value->[-1]->has_raw;
47 } else {
48 2 return $self->key;
49 }
50 }
51  
52 129 ▶sub add_value {
Subroutine add_value: called CC=3 SCAR=11.1
Pod documented
53 129 my ($self,$value,$position,$raw) = @_;
54  
55 129 ▶ $self->push_value(MooseX::App::ParsedArgv::Value->new(
Branch: 2 branches
BranchTrueFalseTotal
defined $position ? : 129 0 129
defined $raw ? : 63 66 129
56 value => $value,
57 (defined $position ? (position => $position):()),
58 (defined $raw ? (raw => $raw):()),
59 ));
60 129 return $value;
61 }
62  
63 3 ▶sub all_scalar_values { ## no perlcritic(RequireArgUnpacking)
Subroutine all_scalar_values: called CC=1 SCAR=0.0
Pod documented
64 3 return map { $_->value }
65 $_[0]->all_values;
66 }
67  
68 103 ▶sub all_values { ## no perlcritic(RequireArgUnpacking)
Subroutine all_values: called CC=1 SCAR=0.0
Pod documented
69 103 return sort { $a->position <=> $b->position }
70 $_[0]->list_values;
71 }
72  
73 0 ▶sub last_value {
Subroutine last_value: not called CC=1 SCAR=6.9
Pod documented
74 0 my ($self) = @_;
75 0 return ($self->all_values)[-1];
76 }
77  
78 126 ▶sub consume {
Subroutine consume: called CC=2 SCAR=7.0
Pod documented
79 126 my ($self,$attribute) = @_;
80  
81 126 ▶ Moose->throw_error('Element '.$self->type.' '.$self->key.' is already consumed')
Branch: 1 branch
BranchTrueFalseTotal
if $self->consumed 0 126 126
82 if $self->consumed;
83 126 $self->consumed(1);
84  
85 126 return $self;
86 }
87  
88 0 ▶sub serialize {
Subroutine serialize: not called CC=5 SCAR=34.0
Pod documented
89 0 my ($self) = @_;
90 0 my $type = $self->type;
91 0 ▶ if ($type eq 'extra') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'extra') { } 0 0 0
elsif ($type eq 'parameter') { } 0 0 0
elsif ($type eq 'option') { } 0 0 0
92 0 return $self->key;
93 } elsif ($type eq 'parameter') {
94 0 return $self->key;
95 } elsif ($type eq 'option') {
96 0 ▶ my $key = (length $self->key == 1 ? '-':'--').$self->key;
Branch: 1 branch
BranchTrueFalseTotal
length $self->key == 1 ? : 0 0 0
97 0 return join(' ',map { $key.' '.$_->value } $self->all_values);
98 }
99  
100 0 return;
101 }
102  
103 17 __PACKAGE__->meta->make_immutable();
104 17 1;
105  
106 =pod
107  
108 =head1 NAME
109  
110 MooseX::App::ParsedArgv::Element - Parsed logical element from @ARGV
111  
112 =head1 DESCRIPTION
113  
114 Every instance of this class represents a logical entity from @ARGV
115  
116 =head1 METHODS
117  
118 =head2 key
119  
120 Parameter value or option key
121  
122 =head2 value
123  
124 Arrayref of values. A value is represented by a L<MooseX::App::ParsedArgv::Value>
125 object.
126  
127 =head2 add_value
128  
129 Append a value
130  
131 =head2 all_scalar_values
132  
133 All values as scalars (in supplied order)
134  
135 =head2 all_values
136  
137 All values as L<MooseX::App::ParsedArgv::Value> objects (in supplied order)
138  
139 =head2 last_value
140  
141 Last value as L<MooseX::App::ParsedArgv::Value> object (as given by supplied order)
142  
143 =head2 type
144  
145 Type of element. Can be 'option', 'parameter' or 'extra'
146  
147 =head2 consumed
148  
149 Flag that indicates if element was already consumed
150  
151 =head2 consume
152  
153 Consumes element. Dies if element is already consumed
154  
155 =head2 serialize
156  
157 Serializes element (Does not procuce output that is identical with original @ARGV)
158  
159 =head2 original
160  
161 Tries to re-create the original input
162  
163 =cut
« App/Exporter.pm ↑ Summary App/Plugin/Man/Command.pm »