line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ============================================================================ |
2
|
|
|
|
|
|
|
package MooseX::App::ParsedArgv::Element; |
3
|
|
|
|
|
|
|
# ============================================================================ |
4
|
|
|
|
|
|
|
|
5
|
16
|
|
|
16
|
|
317
|
use 5.010; |
|
16
|
|
|
|
|
66
|
|
6
|
16
|
|
|
16
|
|
99
|
use utf8; |
|
16
|
|
|
|
|
36
|
|
|
16
|
|
|
|
|
112
|
|
7
|
|
|
|
|
|
|
|
8
|
16
|
|
|
16
|
|
374
|
use Moose; |
|
16
|
|
|
|
|
39
|
|
|
16
|
|
|
|
|
111
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
default => sub { [] }, |
21
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
default => sub {0}, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has 'type' => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
isa => 'Str', |
37
|
|
|
|
|
|
|
required => 1, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub original { |
42
|
2
|
|
|
2
|
1
|
8
|
my ($self) = @_; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# TODO fixthis |
45
|
2
|
50
|
33
|
|
|
77
|
if ($self->count_values && $self->value->[-1]->has_raw) { |
46
|
0
|
|
|
|
|
0
|
return $self->value->[-1]->has_raw; |
47
|
|
|
|
|
|
|
} else { |
48
|
2
|
|
|
|
|
88
|
return $self->key; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub add_value { |
53
|
127
|
|
|
127
|
1
|
420
|
my ($self,$value,$position,$raw) = @_; |
54
|
|
|
|
|
|
|
|
55
|
127
|
50
|
|
|
|
4106
|
$self->push_value(MooseX::App::ParsedArgv::Value->new( |
|
|
100
|
|
|
|
|
|
56
|
|
|
|
|
|
|
value => $value, |
57
|
|
|
|
|
|
|
(defined $position ? (position => $position):()), |
58
|
|
|
|
|
|
|
(defined $raw ? (raw => $raw):()), |
59
|
|
|
|
|
|
|
)); |
60
|
127
|
|
|
|
|
321
|
return $value; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub all_scalar_values { ## no perlcritic(RequireArgUnpacking) |
64
|
3
|
|
|
3
|
1
|
8
|
return map { $_->value } |
|
6
|
|
|
|
|
147
|
|
65
|
|
|
|
|
|
|
$_[0]->all_values; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub all_values { ## no perlcritic(RequireArgUnpacking) |
69
|
101
|
|
|
101
|
1
|
3987
|
return sort { $a->position <=> $b->position } |
|
15
|
|
|
|
|
434
|
|
70
|
|
|
|
|
|
|
$_[0]->list_values; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub last_value { |
74
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
75
|
0
|
|
|
|
|
0
|
return ($self->all_values)[-1]; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub consume { |
79
|
124
|
|
|
124
|
1
|
303
|
my ($self,$attribute) = @_; |
80
|
|
|
|
|
|
|
|
81
|
124
|
50
|
|
|
|
3556
|
Moose->throw_error('Element '.$self->type.' '.$self->key.' is already consumed') |
82
|
|
|
|
|
|
|
if $self->consumed; |
83
|
124
|
|
|
|
|
3609
|
$self->consumed(1); |
84
|
|
|
|
|
|
|
|
85
|
124
|
|
|
|
|
251
|
return $self; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub serialize { |
89
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
90
|
0
|
|
|
|
|
|
my $type = $self->type; |
91
|
0
|
0
|
|
|
|
|
if ($type eq 'extra') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return $self->key; |
93
|
|
|
|
|
|
|
} elsif ($type eq 'parameter') { |
94
|
0
|
|
|
|
|
|
return $self->key; |
95
|
|
|
|
|
|
|
} elsif ($type eq 'option') { |
96
|
0
|
0
|
|
|
|
|
my $key = (length $self->key == 1 ? '-':'--').$self->key; |
97
|
0
|
|
|
|
|
|
return join(' ',map { $key.' '.$_->value } $self->all_values); |
|
0
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
104
|
|
|
|
|
|
|
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 |