line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Smoke::App::AppOption; |
2
|
10
|
|
|
10
|
|
261166
|
use warnings; |
|
10
|
|
|
|
|
42
|
|
|
10
|
|
|
|
|
306
|
|
3
|
10
|
|
|
10
|
|
45
|
use strict; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
164
|
|
4
|
10
|
|
|
10
|
|
39
|
use Carp; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
588
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
7
|
|
|
|
|
|
|
|
8
|
10
|
|
|
10
|
|
59
|
use base 'Test::Smoke::ObjectBase'; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
5994
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $HTFMT = "%-30s - %s\n"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Test::Smoke::App::AppOption - Object that represents an Application Option. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Test::Smoke::App::AppOption; |
19
|
|
|
|
|
|
|
my $o = Test::Smoke::App::AppOption->new( |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
printf "%s\n", $o->gol_option; |
22
|
|
|
|
|
|
|
print $o->show_helptext; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 Test::Smoke::App::AppOption->new(%arguments) |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head3 Arguments |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Named: |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=over |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=item name => $basic_option_name [required] |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item option => $option_extention (see L) |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item allow => $arrary_ref_with alternatives |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item default => $default_value |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item helptext => $text_to_show_with help |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=back |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head3 Returns |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
An instance. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head3 Exceptions |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
croak()s when: |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=over |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item B |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item B |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=back |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { |
65
|
746
|
|
|
746
|
1
|
3359
|
my $class = shift; |
66
|
746
|
|
|
|
|
2750
|
my %args = @_; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $struct = { |
69
|
|
|
|
|
|
|
_name => undef, |
70
|
|
|
|
|
|
|
_option => "", |
71
|
|
|
|
|
|
|
_allow => undef, |
72
|
|
|
|
|
|
|
_default => undef, |
73
|
|
|
|
|
|
|
_helptext => "", |
74
|
|
|
|
|
|
|
_configtext => "", |
75
|
|
|
|
|
|
|
_configtype => "prompt", |
76
|
0
|
|
|
0
|
|
0
|
_configalt => sub { [] }, |
77
|
|
|
|
0
|
|
|
_configdft => sub { }, |
78
|
746
|
|
|
|
|
5741
|
_configfnex => 0, |
79
|
|
|
|
|
|
|
_configord => 0, |
80
|
|
|
|
|
|
|
}; |
81
|
746
|
|
|
|
|
1644
|
$struct->{_had_default} = exists $args{default}; |
82
|
746
|
|
|
|
|
2352
|
for my $known (keys %$struct) { |
83
|
8952
|
|
|
|
|
18355
|
(my $key = $known) =~ s/^_//; |
84
|
8952
|
100
|
|
|
|
17638
|
$struct->{$known} = delete $args{$key} if exists $args{$key}; |
85
|
|
|
|
|
|
|
} |
86
|
746
|
100
|
100
|
|
|
2530
|
if (!defined($struct->{_name}) || !length($struct->{_name})) { |
87
|
2
|
|
|
|
|
244
|
croak("Required option 'name' not given."); |
88
|
|
|
|
|
|
|
} |
89
|
744
|
100
|
100
|
|
|
1953
|
if ( defined($struct->{_allow}) |
90
|
|
|
|
|
|
|
and (ref($struct->{_allow}) !~ /^(?:ARRAY|Regexp|CODE)$/)) |
91
|
|
|
|
|
|
|
{ |
92
|
1
|
|
|
|
|
89
|
croak("Option 'allow' must be an ArrayRef|CodeRef|RegExp when set"); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
# had_default(): order == code < configfile < commandline |
95
|
|
|
|
|
|
|
|
96
|
743
|
|
|
|
|
3973
|
return bless $struct, $class; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 $option->allowed($value[, $allow]) |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Checks if a value is in a set of allowed values. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head3 Arguments |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Positional. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=over |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item $value (the value to check) |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item $allow [optional] |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
C<$allow> can be: |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=over 8 |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item * ArrayRef => a list of allowed() items |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item * Regex => a regex to test C<$value> against. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item * CodeRef => a coderef that is executed with C<$value> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item * other_value => $value eq $other_value (checks for definedness) |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=back |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head3 Returns |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
(perl) True of False. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub allowed { |
136
|
773
|
|
|
773
|
1
|
1760
|
my $self = shift; |
137
|
773
|
100
|
|
|
|
1932
|
return 1 if !defined $self->allow; |
138
|
|
|
|
|
|
|
|
139
|
443
|
|
|
|
|
760
|
my ($value, $allow) = @_; |
140
|
443
|
100
|
|
|
|
870
|
$allow = $self->allow if @_ == 1; |
141
|
|
|
|
|
|
|
GIVEN: { |
142
|
443
|
|
|
|
|
509
|
local $_ = ref($allow); |
|
443
|
|
|
|
|
645
|
|
143
|
|
|
|
|
|
|
|
144
|
443
|
100
|
|
|
|
837
|
/^ARRAY$/ && do { |
145
|
112
|
|
|
|
|
312
|
return scalar grep $self->allowed($value, $_), @$allow; |
146
|
|
|
|
|
|
|
}; |
147
|
331
|
100
|
|
|
|
552
|
/^Regexp$/ && do { |
148
|
46
|
|
100
|
|
|
481
|
return ($value || '') =~ $allow; |
149
|
|
|
|
|
|
|
}; |
150
|
285
|
100
|
|
|
|
486
|
/^CODE$/ && do { |
151
|
13
|
|
|
|
|
86
|
return $allow->($value); |
152
|
|
|
|
|
|
|
}; |
153
|
|
|
|
|
|
|
# default |
154
|
272
|
|
|
|
|
295
|
do { |
155
|
272
|
100
|
|
|
|
420
|
if (!defined $value) { |
156
|
1
|
|
|
|
|
7
|
return !defined $allow; |
157
|
|
|
|
|
|
|
} |
158
|
271
|
100
|
|
|
|
443
|
return 0 if !defined $allow; |
159
|
244
|
|
|
|
|
699
|
return $value eq $allow; |
160
|
|
|
|
|
|
|
}; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 $opt->gol_option |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Getopt::Long compatible option string. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub gol_option { |
171
|
14674
|
|
|
14674
|
1
|
17512
|
my $self = shift; |
172
|
|
|
|
|
|
|
|
173
|
14674
|
|
|
|
|
33255
|
my $gol = $self->name; |
174
|
14674
|
100
|
|
|
|
36327
|
if ($self->option !~ /^(=|!|\||$)/) { |
175
|
2083
|
|
|
|
|
2833
|
$gol .= "|"; |
176
|
|
|
|
|
|
|
} |
177
|
14674
|
|
|
|
|
40032
|
$gol .= $self->option; |
178
|
14674
|
|
|
|
|
30622
|
return $gol; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 $opt->show_helptext() |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sprintf "%-30s - %s", $option_with_allowd, $self->helptext |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub show_helptext { |
188
|
631
|
|
|
631
|
1
|
1175
|
my $self = shift; |
189
|
|
|
|
|
|
|
|
190
|
631
|
|
|
|
|
759
|
my $prefix = '--'; |
191
|
631
|
100
|
|
|
|
1602
|
if ($self->option =~ /!$/) { |
192
|
74
|
|
|
|
|
117
|
$prefix .= '[no]'; |
193
|
|
|
|
|
|
|
} |
194
|
631
|
|
|
|
|
1071
|
my @option = ($prefix . $self->gol_option); |
195
|
|
|
|
|
|
|
|
196
|
631
|
100
|
100
|
|
|
1720
|
if ( defined($self->allow) |
|
|
|
100
|
|
|
|
|
197
|
131
|
|
|
|
|
423
|
&& ref($self->allow) eq 'ARRAY' && @{$self->allow}) |
198
|
|
|
|
|
|
|
{ |
199
|
|
|
|
|
|
|
my @values = sort { |
200
|
307
|
|
|
|
|
725
|
lc($a) cmp lc($b) |
201
|
|
|
|
|
|
|
} map |
202
|
|
|
|
|
|
|
defined($_) ? $_ : "'undef'" |
203
|
130
|
100
|
|
|
|
186
|
, @{$self->allow}; |
|
130
|
|
|
|
|
353
|
|
204
|
130
|
|
|
|
|
302
|
my $allowed = join('|', @values); |
205
|
130
|
|
|
|
|
296
|
push @option, "<$allowed>"; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
631
|
|
|
|
|
1178
|
my $text = join(" ", @option); |
209
|
|
|
|
|
|
|
|
210
|
631
|
100
|
|
|
|
1826
|
return $text if !$self->helptext; |
211
|
630
|
|
|
|
|
1754
|
return sprintf($HTFMT, $text, $self->helptext); |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
1; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 COPYRIGHT |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
(c) 2002-2013, Abe Timmerman All rights reserved. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
With contributions from Jarkko Hietaniemi, Merijn Brand, Campo |
221
|
|
|
|
|
|
|
Weijerman, Alan Burlison, Allen Smith, Alain Barbet, Dominic Dunlop, |
222
|
|
|
|
|
|
|
Rich Rauenzahn, David Cantrell. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
225
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
See: |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=over 4 |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item * L |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item * L |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=back |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
238
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
239
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=cut |