blib/lib/Getopt/Euclid.pm

filter: Statementstmt 94.4% 649 / 687 Branchbran 87.3% 297 / 340 Conditioncond 75.2% 64 / 85 MC/DCmcdc 61.2% 30 / 49 Subroutinesub 97.1% 68 / 70 Podpod 100% 7 / 7 totaltotal 90.0% 1115 / 1238 CC 237 SCAR 30.8
CC
237
Cov
91%
_verify_args
45.7
_process_euclid_specs
42.1
process_args
35.0
CRAP 21.7
↑ Summary
1 package Getopt::Euclid;
2  
3 65 ▶use version; our $VERSION = version->declare('0.4.5');
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 65 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 65 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 65 ▶use 5.005000; # perl 5.5.0
Subroutine BEGIN: called CC=1 SCAR=0.0
8 65 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 65 ▶use Symbol ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 65 ▶use re 'eval'; # for matcher regex
Subroutine BEGIN: called CC=1 SCAR=0.0
11 65 ▶use Pod::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 65 ▶use Pod::PlainText;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 65 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 65 ▶use File::Spec::Functions qw(splitpath catpath catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 65 ▶use List::Util qw( first );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 65 ▶use Text::Balanced qw(extract_multiple extract_bracketed extract_variable extract_delimited);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19 # Set some module variables
20 65 my $skip_keyword = 'Getopt::Euclid'; # Ignore files with a first line containing this keyword.
21 65 my $pod_file_msg = "# This file was generated dynamically by $skip_keyword. Do not edit it.";
22  
23 65 my $has_run = 0;
24 65 my $has_processed_pod = 0;
25 65 my $export_lvl = 1;
26 65 my @pod_names;
27 my $minimal_keys;
28 65 my $vars_prefix;
29 65 my $defer = 0;
30 65 my $matcher;
31 my %requireds;
32 65 my %options;
33 65 my %longnames;
34 65 our $man; # --man message
35 65 my $help; # --help message
36 my $usage; # --usage message
37 65 my $version; # --version message
38  
39 65 my $optional_re;
40 65 $optional_re = qr{ \[ [^[]* (?: (??{$optional_re}) [^[]* )* \] }xms;
41  
42  
43 # Global variables
44 65 our $SCRIPT_NAME;
45 65 our $SCRIPT_VERSION; # for ticket # 55259
46  
47  
48 # Convert arg specification syntax to Perl regex syntax
49  
50 65 my %std_matcher_for = (
51 integer => '[+-]?\\d+(?:[eE][+]?\d+)?',
52 number => '[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:[eE][+-]?\d+)?',
53 input => '\S+',
54 output => '\S+',
55 string => '\S+',
56 q{} => '\S+',
57 );
58  
59 65 _make_equivalent(
60 \%std_matcher_for,
61 integer => [qw( int i +int +i 0+int 0+i +integer 0+integer )],
62 number => [qw( num n +num +n 0+num 0+n +number 0+number )],
63 input => [qw( readable in )],
64 output => [qw( writable writeable out )],
65 string => [qw( str s )],
66 );
67  
68 my %std_constraint_for = (
69 11 ▶ 'string' => sub { 1 }, # Always okay (matcher ensures this)
Subroutine __ANON__: called CC=1 SCAR=0.0
70 34 ▶ 'integer' => sub { 1 }, # Always okay (matcher ensures this)
Subroutine __ANON__: called CC=1 SCAR=0.0
71 10 ▶ '+integer' => sub { $_[0] > 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
72 12 ▶ '0+integer' => sub { $_[0] >= 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
73 27 ▶ 'number' => sub { 1 }, # Always okay (matcher ensures this)
Subroutine __ANON__: called CC=1 SCAR=0.0
74 18 ▶ '+number' => sub { $_[0] > 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
75 21 ▶ '0+number' => sub { $_[0] >= 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
76 33 ▶ 'input' => sub { $_[0] eq '-' || -r $_[0] },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] eq "-" or -r $_[0] 33 0 33
77 'output' => sub {
78 34 ▶ my ( $vol, $dir ) = splitpath( $_[0] );
Subroutine __ANON__: called CC=5 SCAR=16.8
79 34 ▶ $dir = ($vol && $dir) ? catpath($vol, $dir) : '.';
Branch: 1 branch
BranchTrueFalseTotal
$vol && $dir ? : 0 34 34
Condition33%1/3
$vol and $dir
!ll&&!rl&&r
3400
MC/DC0%0/2
$vol and $dir
$vol $dir
Truth table33%1/3
A and B
A= $volB= $dir
ABresult
0X0
100
111
80 34 ▶ $_[0] eq '-' ? 1 : -e $_[0] ? -w $_[0] : -w $dir;
Branch: 2 branches
BranchTrueFalseTotal
$_[0] eq '-' ? : 1 33 34
-e $_[0] ? : 32 1 33
81 },
82 65 );
83  
84 65 _make_equivalent(
85 \%std_constraint_for,
86 'integer' => [qw( int i )],
87 '+integer' => [qw( +int +i )],
88 '0+integer' => [qw( 0+int 0+i )],
89 'number' => [qw( num n )],
90 '+number' => [qw( +num +n )],
91 '0+number' => [qw( 0+num 0+n )],
92 'string' => [qw( str s )],
93 'input' => [qw( in readable )],
94 'output' => [qw( out writable writeable )],
95 );
96  
97  
98 sub Getopt::Euclid::Importer::DESTROY {
99 0 ▶ return if $has_run || $^C; # No errors when only compiling
Subroutine DESTROY: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if $has_run or $^C 0 0 0
Condition0%0/3
$has_run or $^C
l!l&&r!l&&!r
000
MC/DC0%0/2
$has_run or $^C
$has_run $^C
Truth table0%0/3
A or B
A= $has_runB= $^C
ABresult
1X1
011
000
100 0 croak '.pm file cannot define an explicit import() when using Getopt::Euclid';
101 }
102  
103  
104 sub import {
105 68 ▶ shift @_;
Subroutine import: called CC=10 SCAR=23.0
106 68 ▶ @_ = grep { !( /:minimal_keys/ and $minimal_keys = 1 ) } @_;
Condition100%2/2
/:minimal_keys/ && ($minimal_keys = 1)
!ll
65
MC/DC100%1/1
/:minimal_keys/ && ($minimal_keys = 1)
/:minimal_keys/
Truth table100%2/2
A
A= /:minimal_keys/
Aresult
00
11
107 68 ▶ @_ = grep { !( /:vars(?:<(\w+)>)?/ and $vars_prefix = $1 || 'ARGV_' ) } @_;
Condition80%4/5
/:vars(?:<(\w+)>)?/ && ($vars_prefix = $1 || 'ARGV_')
!ll&&!rl&&r
402
$1 || 'ARGV_'
l!l
11
MC/DC100%2/2
/:vars(?:<(\w+)>)?/ && ($vars_prefix = $1 || 'ARGV_')
/:vars(?:<(\w+)>)?/ $1
Truth table100%3/3
A && B
A= /:vars(?:<(\w+)>)?/B= $1
ABresult
0X0
100
111
108 68 ▶ @_ = grep { !( /:defer/ and $defer = 1 ) } @_;
Condition100%2/2
/:defer/ && ($defer = 1)
!ll
13
MC/DC100%1/1
/:defer/ && ($defer = 1)
/:defer/
Truth table100%2/2
A
A= /:defer/
Aresult
00
11
109 68 croak "Unknown mode ('$_')" for @_;
110 67 ▶ $export_lvl++ if not $defer;
Branch: 1 branch
BranchTrueFalseTotal
unless $defer 64 3 67
111  
112 # No POD parsing and argument processing in Perl compile mode (ticket 34195)
113 67 ▶ return if $^C;
Branch: 1 branch
BranchTrueFalseTotal
if $^C 1 66 67
114  
115 # Get name of caller program and its modules in @pod_names
116 66 ▶ return unless _get_pod_names();
Branch: 1 branch
BranchTrueFalseTotal
unless _get_pod_names() 4 62 66
117  
118 # Extract POD of given files
119 62 __PACKAGE__->process_pods( [reverse @pod_names] );
120 62 undef @pod_names;
121 62 $has_run = 1;
122  
123 # Parse POD + parse and export arguments
124  
125 ######
126 #use Data::Dumper; print "ARGV: ".Dumper(\@ARGV);
127 ######
128  
129 62 ▶ __PACKAGE__->process_args( \@ARGV ) unless $defer;
Branch: 1 branch
BranchTrueFalseTotal
unless $defer 59 3 62
130  
131 35 return 1;
132 }
133  
134  
135 sub process_pods {
136 # Extract POD content from list of Perl scripts (.pl) and modules (.pm) and
137 # their corresponding .pod file if available. When given the argument
138 # {-strict => 1}, do not look for .pod files.
139 63 ▶ my ($self, $perl_files, $args) = @_;
Subroutine process_pods: called CC=10 SCAR=23.1
Pod documented
140  
141 63 my $pod_string = '';
142 63 ▶ open my $pod_fh, '>', \$pod_string
Branch: 1 branch
BranchTrueFalseTotal
open my $pod_fh, ">", \$pod_string or croak("Could not open filehandle to variable because $!") 0 63 63
143 or croak "Could not open filehandle to variable because $!";
144 63 for my $perl_file (@$perl_files) {
145  
146 66 my $got_pod_file = 0;
147  
148 66 ▶ if ( not $args->{-strict} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"-strict"}) 66 0 66
149  
150 # Find corresponding .pod file
151 66 my ($name_re, $path, $suffix) = fileparse($perl_file, qr/\.[^.]*/);
152 66 my $pod_file = catfile( $path, $name_re.'.pod' );
153  
154 # Get POD either from .pod file (preferably) or from Perl file
155 66 ▶ if ( -e $pod_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $pod_file) 6 60 66
156 # Get .pod file content
157 6 ▶ open my $in, '<', $pod_file
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<", $pod_file or croak("Could not open file $pod_file because $!") 0 6 6
158 or croak "Could not open file $pod_file because $!";
159 6 my $first_line = <$in>;
160 6 chomp $first_line;
161 6 ▶ if ( not ($first_line =~ m/$skip_keyword/) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($first_line =~ /$skip_keyword/) 4 2 6
162 # Skip G::E auto-generated files since they lack important data
163 4 print $pod_fh "$first_line\n";
164 4 ▶ print $pod_fh $_ while <$in>;
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline $in) and do { print $pod_fh $_ } 169 4 173
165 4 $got_pod_file = 1;
166 }
167 6 close $in;
168 }
169 }
170  
171 66 ▶ if (not $got_pod_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($got_pod_file) 62 4 66
172 # Parse POD content of Perl file
173 62 podselect( {-output => $pod_fh}, $perl_file );
174 }
175 66 ▶ print $pod_fh "\n" if $pod_string;
Branch: 1 branch
BranchTrueFalseTotal
if $pod_string 62 4 66
176  
177 }
178 63 close $pod_fh;
179 63 $man = $pod_string;
180 63 return 1;
181 }
182  
183  
184 sub process_args {
185 # First, parse the POD specifications. Then, parse the given array of
186 # arguments (\@ARGV or other) and populate %ARGV (or export specific
187 # variable names).
188 68 ▶ my ($self, $args, $options) = @_;
Subroutine process_args: called CC=33 SCAR=35.6
Pod documented
189  
190 # Parse POD
191 68 ▶ if (not $has_processed_pod) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_processed_pod) 63 5 68
192 63 _parse_pod();
193 50 $has_processed_pod = 1;
194 }
195  
196 # Set options for argument parsing
197 55 ▶ if (defined $options) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options) 2 53 55
198 2 ▶ if (exists $options->{-minimal_keys}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options->{"-minimal_keys"}) 1 1 2
199 1 $minimal_keys = 1;
200 }
201 2 ▶ if (exists $options->{-vars}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options->{"-vars"}) 1 1 2
202 1 $vars_prefix = $options->{-vars};
203 }
204 }
205  
206 55 %ARGV = ();
207  
208 # Handle standard args...
209 55 ▶ if ( first { $_ eq '--man' } @$args ) {
Subroutine __ANON__: called CC=1 SCAR=0.7
Branch: 5 branches
BranchTrueFalseTotal
if (&first(sub { $_ eq '--man'; } , @$args)) { } 0 55 55
elsif (&first(sub { $_ eq '--usage'; } , @$args)) { } 0 55 55
elsif (&first(sub { $_ eq '--help'; } , @$args)) { } 0 55 55
elsif (&first(sub { $_ eq '--version'; } , @$args)) { } 0 55 55
elsif (&first(sub { $_ eq '--podfile'; } , @$args)) { } 0 55 55
210 0 _print_pod( __PACKAGE__->man(), 'paged' );
211 0 exit;
212 615 ▶ } elsif ( first { $_ eq '--usage' } @$args ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
213 0 print __PACKAGE__->usage();
214 0 exit;
215 615 ▶ } elsif ( first { $_ eq '--help' } @$args ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
216 0 _print_pod( __PACKAGE__->help(), 'paged' );
217 0 exit;
218 615 ▶ } elsif ( first { $_ eq '--version' } @$args ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
219 0 print __PACKAGE__->version();
220 0 exit;
221 615 ▶ } elsif ( first { $_ eq '--podfile' } @$args ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
222 # Option meant for authors
223 0 my $podfile = podfile( );
224 0 print "Wrote POD manual in file $podfile\n";
225 0 exit;
226 }
227  
228 # Subroutine to report problems during parsing...
229 *_bad_arglist = sub {
230 16 ▶ my (@msg) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
231 16 my $msg = join q{}, @msg;
232 16 $msg = _rectify_arg($msg);
233 16 $msg =~ s/\n?\z/\n/xms;
234 16 warn "$msg\nTry this for usage help: $SCRIPT_NAME --help\n".
235 "Or this for full manual: $SCRIPT_NAME --man\n\n";
236 16 exit 2; # Traditional "bad arg list" value
237 55 };
238  
239 # Run matcher...
240 55 my $argv = join( q{ }, map { $_ = _escape_arg($_) } @$args );
241 55 my $all_args_ref = { %options, %requireds };
242 55 ▶ if ( my $error = _doesnt_match( $matcher, $argv, $all_args_ref ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = _doesnt_match($matcher, $argv, $all_args_ref)) 7 48 55
243 7 _bad_arglist($error);
244 }
245  
246 # Check that all requireds have been found...
247 48 my @missing;
248 48 ▶ while ( my ($req) = each %requireds ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($req) = each %requireds) 101 48 149
249 101 ▶ push @missing, "\t$req\n" if !exists $ARGV{$req};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ARGV{$req} 1 100 101
250 }
251 _bad_arglist(
252 48 ▶ 'Missing required argument',
Branch: 2 branches
BranchTrueFalseTotal
if @missing 1 47 48
@missing == 1 ? : 1 0 1
253 ( @missing == 1 ? q{} : q{s} ),
254 ":\n", @missing
255 ) if @missing;
256  
257 # Back-translate \0-quoted spaces and \1-quoted tabs...
258 47 _rectify_all_args();
259  
260 # Check exclusive variables, variable constraints and fill in defaults...
261 47 _verify_args($all_args_ref);
262  
263 # Clean up @$args since everything must have been parsed
264 39 @$args = ();
265  
266 # Clean up %ARGV
267 39 for my $arg_name ( keys %ARGV ) {
268  
269 # Flatten non-repeatables...
270 252 my $vals = delete $ARGV{$arg_name};
271 252 my $repeatable = $all_args_ref->{$arg_name}{is_repeatable};
272 252 ▶ if ($repeatable) {
Branch: 1 branch
BranchTrueFalseTotal
if ($repeatable) 4 248 252
273 4 pop @{$vals};
274 }
275  
276 252 for my $val ( @{$vals} ) {
277 253 my $var_count = keys %{$val};
278 $val = $var_count == 0
279 ? 1 # Boolean -> true
280 : $var_count == 1
281 253 ▶ ? ( values %{$val} )[0] # Single var -> var's val
Branch: 2 branches
BranchTrueFalseTotal
$var_count == 0 ? : 0 253 253
$var_count == 1 ? : 211 42 253
282 : $val # Otherwise keep hash
283 ;
284 253 my $false_vals = $all_args_ref->{$arg_name}{false_vals};
285 253 my %vars_opt_vals;
286  
287 253 for my $arg_flag ( _get_variants($arg_name) ) {
288 465 my $variant_val = $val;
289 465 ▶ if ( $false_vals && $arg_flag =~ m{\A $false_vals \z}xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($false_vals and $arg_flag =~ /\A $false_vals \z/msx) 14 451 465
Condition100%3/3
$false_vals and $arg_flag =~ /\A $false_vals \z/msx
!ll&&!rl&&r
444714
MC/DC100%2/2
$false_vals and $arg_flag =~ /\A $false_vals \z/msx
$false_vals $arg_flag =~ /\A $false_vals \z/msx
Truth table100%3/3
A and B
A= $false_valsB= $arg_flag =~ /\A $false_vals \z/msx
ABresult
0X0
100
111
290 14 ▶ $variant_val = $variant_val ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$variant_val ? : 1 13 14
291 }
292  
293 465 ▶ if ($repeatable) {
Branch: 1 branch
BranchTrueFalseTotal
if ($repeatable) { } 25 440 465
294 25 push @{ $ARGV{$arg_flag} }, $variant_val;
295 } else {
296 440 $ARGV{$arg_flag} = $variant_val;
297 }
298 465 ▶ $vars_opt_vals{$arg_flag} = $ARGV{$arg_flag} if $vars_prefix;
Branch: 1 branch
BranchTrueFalseTotal
if $vars_prefix 54 411 465
299 }
300  
301 253 ▶ if ($vars_prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars_prefix) 28 225 253
302 28 _minimize_entries_of( \%vars_opt_vals );
303 28 my $maximal = _longestname( keys %vars_opt_vals );
304 28 _export_var( $vars_prefix, $maximal, $vars_opt_vals{$maximal} );
305 28 delete $longnames{$maximal};
306 }
307 }
308 }
309  
310 39 ▶ if ($vars_prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vars_prefix) 3 36 39
311  
312 # Export any unspecified options to keep use strict happy
313 3 ▶ while ( my ($opt_name, $arg_name) = each %longnames ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %longnames) 17 3 20
314 17 my $arg_info = $all_args_ref->{$arg_name};
315 17 my $val;
316 17 ▶ if ( $arg_info->{is_repeatable} or $arg_name =~ />\.\.\./ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_info->{'is_repeatable'} or $arg_name =~ />\.\.\./) { } 3 14 17
Condition100%3/3
$arg_info->{"is_repeatable"} or $arg_name =~ />\.\.\./
l!l&&r!l&&!r
2114
MC/DC100%2/2
$arg_info->{"is_repeatable"} or $arg_name =~ />\.\.\./
$arg_info->{"is_repeatable"} $arg_name =~ />\.\.\./
Truth table100%3/3
A or B
A= $arg_info->{"is_repeatable"}B= $arg_name =~ />\.\.\./
ABresult
1X1
011
000
317 # Empty arrayref for repeatable options
318 3 $val = [];
319 } else {
320 14 ▶ if (keys %{ $arg_info->{var} } > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$arg_info{"var"};} > 1) 1 13 14
321 # Empty hashref for non-repeatable options with multiple placeholders
322 1 $val = {};
323 }
324 }
325 17 _export_var( $vars_prefix, $opt_name, $val );
326 }
327 }
328  
329  
330 39 ▶ if ($minimal_keys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($minimal_keys) 6 33 39
331 6 _minimize_entries_of( \%ARGV );
332 }
333  
334 39 return 1;
335 }
336  
337  
338 sub podfile {
339 # Write the given POD doc into a .pod file, overwriting any existing .pod file
340 1 ▶ return if not -e $0;
Subroutine podfile: called CC=3 SCAR=11.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless -e $0 0 1 1
341 1 my ($name_re, $path, $suffix) = fileparse($0, qr/\.[^.]*/);
342 1 my $pod_file = catfile( $path, $name_re.'.pod' );
343 1 ▶ open my $out_fh, '>', $pod_file or croak "Could not write file $pod_file because $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $out_fh, ">", $pod_file or croak("Could not write file $pod_file because $!") 0 1 1
344 1 print $out_fh $pod_file_msg."\n\n".__PACKAGE__->man();
345 1 close $out_fh;
346 1 return $pod_file;
347 }
348  
349  
350 sub man {
351 6 ▶ return $man;
Subroutine man: called CC=1 SCAR=0.0
Pod documented
352 }
353  
354  
355 sub usage {
356 1 ▶ return $usage;
Subroutine usage: called CC=1 SCAR=0.0
Pod documented
357 }
358  
359  
360 sub help {
361 2 ▶ return $help;
Subroutine help: called CC=1 SCAR=0.0
Pod documented
362 }
363  
364  
365 sub version {
366 1 ▶ return $version;
Subroutine version: called CC=1 SCAR=0.0
Pod documented
367 }
368  
369  
370 # # # # # # # # Utility subs # # # # # # # #
371  
372 # Recursively remove decorations on %ARGV keys
373  
374 sub AUTOLOAD {
375 9 ▶ our $AUTOLOAD;
Subroutine AUTOLOAD: called CC=1 SCAR=0.0
376 9 $AUTOLOAD =~ s{.*::}{main::}xms;
377 65 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
378 9 goto &$AUTOLOAD;
379 }
380  
381  
382 sub _parse_pod {
383 # Set up parsing rules...
384 63 ▶ my $space_re = qr{ [^\S\n]* }xms;
Subroutine _parse_pod: called CC=31 SCAR=34.4
385 63 my $head_start_re = qr{ ^=head1 }xms;
386 63 my $head_end_re = qr{ (?= $head_start_re | \z) }xms;
387 63 my $pod_cmd_re = qr{ = [^\W\d]\w+ [^\n]* (?= \n\n )}xms;
388 63 my $pod_cut_re = qr{ (?! \n\n ) = cut $space_re (?= \n\n )}xms;
389  
390 63 my $name_re = qr{ $space_re NAME $space_re \n }xms;
391 63 my $vers_re = qr{ $space_re VERSION $space_re \n }xms;
392 63 my $usage_re = qr{ $space_re USAGE $space_re \n }xms;
393  
394 63 my $std_re = qr{ STANDARD | STD | PROGRAM | SCRIPT | CLI | COMMAND(?:-|\s)?LINE }xms;
395 63 my $arg_re = qr{ $space_re (?:PARAM(?:ETER)?|ARG(?:UMENT)?)S? }xms;
396  
397 63 my $options_re = qr{ $space_re $std_re? $space_re OPTION(?:AL|S)? $arg_re? $space_re \n }xms;
398 63 my $required_re = qr{ $space_re $std_re? $space_re (?:REQUIRED|MANDATORY) $arg_re? $space_re \n }xms;
399  
400 63 my $euclid_arg = qr{ ^=item \s* ([^\n]*?) \s* \n\s*\n
401 (
402 .*?
403 (?:
404 ^=for \s* (?i: Euclid) .*? \n\s*\n
405 | (?= ^=[^\W\d]\w* | \z)
406 )
407 )
408 }xms;
409  
410 # Clean up line delimiters
411 63 $man =~ s{ [\n\r] }{\n}gx;
412  
413 # Clean up significant entities...
414 63 $man =~ s{ E<lt> }{<}gxms;
415 63 $man =~ s{ E<gt> }{>}gxms;
416  
417 # Put program name in man
418 63 ▶ $SCRIPT_NAME = (-e $0) ? (splitpath $0)[-1] : 'one-liner';
Branch: 1 branch
BranchTrueFalseTotal
-e $0 ? : 62 1 63
419 63 $man =~ s{ ($head_start_re $name_re \s*) .*? (- .*)? $head_end_re }
420 51 ▶ {$1.$SCRIPT_NAME.($2 ? " $2" : "\n\n")}xems;
Branch: 1 branch
BranchTrueFalseTotal
$2 ? : 50 1 51
421  
422 # Put version number in man
423 63 ($SCRIPT_VERSION) =
424 $man =~ m/$head_start_re $vers_re .*? (\d+(?:[._]\d+)+) .*? $head_end_re /xms;
425 63 ▶ if ( !defined $SCRIPT_VERSION ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Getopt::Euclid::SCRIPT_VERSION) 14 49 63
426 14 $SCRIPT_VERSION = $main::VERSION;
427 }
428 63 ▶ if ( !defined $SCRIPT_VERSION ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Getopt::Euclid::SCRIPT_VERSION) 14 49 63
429 14 ▶ $SCRIPT_VERSION = (-e $0) ? localtime((stat $0)[9]) : 'one-liner';
Branch: 1 branch
BranchTrueFalseTotal
-e $0 ? : 13 1 14
430 }
431 63 $man =~ s{ ($head_start_re $vers_re \s*) .*? (\s*) $head_end_re }
432 {$1This document refers to $SCRIPT_NAME version $SCRIPT_VERSION $2}xms;
433  
434 # Extra info from PODs
435 63 my ($options, $opt_name, $required, $req_name, $licence);
436 63 ▶ while ($man =~ m/$head_start_re ($required_re) (.*?) $head_end_re /gxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Getopt::Euclid::man =~ /$head_start_re ($required_re) (.*?) $head_end_re /gmsx) 51 63 114
437 # Required arguments
438 51 my ( $more_req_name, $more_required ) = ($1, $2);
439 51 ▶ $req_name = $more_req_name if not defined $req_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $req_name 51 0 51
440 51 ▶ $required = ( $more_required || q{} ) . ( $required || q{} );
Condition50%2/4
$more_required || ''
l!l
510
$required || ''
l!l
051
MC/DC0%0/1
$more_required || ''
$more_required
MC/DC0%0/1
$required || ''
$required
Truth table50%1/2
A
A= $more_required
Aresult
11
00
Truth table50%1/2
A
A= $required
Aresult
11
00
441 }
442 63 ▶ while ($man =~ m/$head_start_re ($options_re) (.*?) $head_end_re /gxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Getopt::Euclid::man =~ /$head_start_re ($options_re) (.*?) $head_end_re /gmsx) 54 63 117
443 # Optional arguments
444 54 my ( $more_opt_name, $more_options ) = ($1, $2);
445 54 ▶ $opt_name = $more_opt_name if not defined $opt_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt_name 54 0 54
446 54 ▶ $options = ( $more_options || q{} ) . ( $options || q{} );
Condition50%2/4
$more_options || ''
l!l
540
$options || ''
l!l
054
MC/DC0%0/1
$more_options || ''
$more_options
MC/DC0%0/1
$options || ''
$options
Truth table50%1/2
A
A= $more_options
Aresult
11
00
Truth table50%1/2
A
A= $options
Aresult
11
00
447 }
448 63 ▶ while ($man =~ m/$head_start_re [^\n]+ (?i: licen[sc]e | copyright ) .*? \n \s* (.*?) \s* $head_end_re /gxms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Getopt::Euclid::man =~ /$head_start_re [^\n]+ (?i: licen[sc]e | copyright ) .*? \n \s* (.*?) \s* $head_end_re /gmsx) 46 63 109
449 # License information
450 46 my ($more_licence) = ($1, $2);
451 46 ▶ $licence = ( $more_licence || q{} ) . ( $licence || q{} );
Condition50%2/4
$more_licence || ''
l!l
460
$licence || ''
l!l
046
MC/DC0%0/1
$more_licence || ''
$more_licence
MC/DC0%0/1
$licence || ''
$licence
Truth table50%1/2
A
A= $more_licence
Aresult
11
00
Truth table50%1/2
A
A= $licence
Aresult
11
00
452 }
453  
454 # Clean up interface titles...
455 63 for my $name_re ( $opt_name, $req_name ) {
456 126 ▶ next if !defined $name_re;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name_re 21 105 126
457 105 $name_re =~ s{\A \s+ | \s+ \z}{}gxms;
458 }
459  
460 # Extract the actual interface and store each arg entry into a hash of specifications...
461 63 my $seq = 0;
462 63 my $seen = {};
463 63 ▶ while ( ( $required || q{} ) =~ m{ $euclid_arg }gxms ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($required || "") =~ / $euclid_arg /gmsx) 120 63 183
Condition100%2/2
$required || ''
l!l
17112
MC/DC100%1/1
$required || ''
$required
Truth table100%2/2
A
A= $required
Aresult
11
00
464 120 $seen = _register_specs( $1, $2, $seq, \%requireds, \%longnames, $seen );
465 120 $seq++;
466 }
467 63 ▶ while ( ( $options || q{} ) =~ m{ $euclid_arg }gxms ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($options || "") =~ / $euclid_arg /gmsx) 410 62 472
Condition100%2/2
$options || ''
l!l
4639
MC/DC100%1/1
$options || ''
$options
Truth table100%2/2
A
A= $options
Aresult
11
00
468 410 $seen = _register_specs( $1, $2, $seq, \%options, \%longnames, $seen );
469 409 $seq++;
470 }
471 62 undef $seen;
472 62 _minimize_entries_of( \%longnames );
473  
474 # Extract Euclid information...
475 62 my $all_specs = {%requireds, %options};
476 62 _process_euclid_specs( $all_specs );
477  
478 # Insert default values (if any) in the program's documentation
479 51 $required = _insert_default_values(\%requireds);
480 50 $options = _insert_default_values(\%options );
481  
482 # One-line representation of interface...
483 my $arg_summary = join ' ', (sort
484 50 { $requireds{$a}{'seq'} <=> $requireds{$b}{'seq'} }
485 (keys %requireds));
486  
487 50 ▶ 1 while $arg_summary =~ s/\[ [^][]* \]//gxms;
Branch: 1 branch
BranchTrueFalseTotal
$arg_summary =~ s/\[ [^][]* \]//gmsx and do { '???' } 35 50 85
488  
489 50 ▶ if ($opt_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_name) 41 9 50
490 41 ▶ $arg_summary .= ' ' if $arg_summary;
Branch: 1 branch
BranchTrueFalseTotal
if $arg_summary 33 8 41
491 41 $arg_summary .= lc "[$opt_name]";
492 }
493 50 $arg_summary =~ s/\s+/ /gxms;
494  
495 # Manual message
496 50 $man =~ s{ ($head_start_re $usage_re \s*) .*? (\s*) $head_end_re } {$1$SCRIPT_NAME $arg_summary$2}xms;
497 50 $man =~ s{ ($head_start_re $required_re \s*) .*? (\s*) $head_end_re } {$1$required$2}xms;
498 50 $man =~ s{ ($head_start_re $options_re \s*) .*? (\s*) $head_end_re } {$1$options$2}xms;
499  
500 # Usage message
501 50 $usage = " $SCRIPT_NAME $arg_summary\n";
502 50 $usage .= " $SCRIPT_NAME --help\n";
503 50 $usage .= " $SCRIPT_NAME --man\n";
504 50 $usage .= " $SCRIPT_NAME --usage\n";
505 50 $usage .= " $SCRIPT_NAME --version\n";
506  
507 # Help message
508 50 $help = "=head1 \L\uUsage:\E\n\n$usage\n";
509 50 ▶ $help .= "=head1 \L\u$req_name:\E\n\n$required\n\n"
Branch: 1 branch
BranchTrueFalseTotal
if ($req_name || "") =~ /\S/ 40 10 50
Condition100%2/2
$req_name || ''
l!l
4010
MC/DC100%1/1
$req_name || ''
$req_name
Truth table100%2/2
A
A= $req_name
Aresult
11
00
510 if ( $req_name || q{} ) =~ /\S/;
511 50 ▶ $help .= "=head1 \L\u$opt_name:\E\n\n$options\n\n"
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_name || "") =~ /\S/ 41 9 50
Condition100%2/2
$opt_name || ''
l!l
419
MC/DC100%1/1
$opt_name || ''
$opt_name
Truth table100%2/2
A
A= $opt_name
Aresult
11
00
512 if ( $opt_name || q{} ) =~ /\S/;
513  
514 50 $usage = "Usage:\n".$usage;
515  
516 # Version message
517 50 $version = "This is $SCRIPT_NAME version $SCRIPT_VERSION\n";
518 50 ▶ $version .= "\n$licence\n" if $licence;
Branch: 1 branch
BranchTrueFalseTotal
if $licence 35 15 50
519  
520 # Convert arg specifications to regexes...
521 50 _convert_to_regex( $all_specs );
522  
523 # Build matcher...
524 50 my @arg_list = ( values(%requireds), values(%options) );
525 427 $matcher = join '|', map { $_->{matcher} }
526 983 sort( { $b->{name} cmp $a->{name} } grep { $_->{name} =~ /^[^<]/ } @arg_list ),
527 50 sort( { $a->{seq} <=> $b->{seq} } grep { $_->{name} =~ /^[<]/ } @arg_list );
528 50 $matcher .= '|(?> (.+)) (?{ push @errors, $^N }) (?!)';
529 50 $matcher = '(?:' . $matcher . ')';
530  
531 50 return 1;
532 }
533  
534  
535 sub _register_specs {
536 530 ▶ my ($name_re, $spec, $seq, $storage, $longnames, $seen) = @_;
Subroutine _register_specs: called CC=3 SCAR=11.0
537 530 my @variants = _get_variants($name_re);
538 530 $storage->{$name_re} = {
539 seq => $seq,
540 src => $spec,
541 name => $name_re,
542 variants => \@variants,
543 };
544 530 ▶ if ($minimal_keys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($minimal_keys) 41 489 530
545 41 my $minimal = _minimize_name($name_re);
546 croak "Internal error: minimalist mode caused arguments ".
547 "'$name_re' and '".$seen->{$minimal}."' to clash"
548 41 ▶ if $seen->{$minimal};
Branch: 1 branch
BranchTrueFalseTotal
if $seen->{$minimal} 1 40 41
549 40 $seen->{$minimal} = $name_re;
550 }
551 529 $longnames->{ _longestname(@variants) } = $name_re;
552 529 return $seen;
553 }
554  
555  
556 sub _process_euclid_specs {
557 62 ▶ my ($args) = @_;
Subroutine _process_euclid_specs: called CC=42 SCAR=37.4
558 62 my %all_var_list;
559 my %excluded_by_def;
560  
561 ARG:
562 62 ▶ while ( (undef, my $arg) = each %$args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(undef, $arg) = each %$args) 487 52 539
563  
564 # Validate and record variable names seen here...
565 487 my $var_list = _validate_name( $arg->{name} );
566 485 ▶ while (my ($var_name, undef) = each %$var_list) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($var_name, undef) = each %$var_list) 374 485 859
567 374 $all_var_list{$var_name} = undef;
568 }
569  
570 # Process arguments with a Euclid specification further
571 485 ▶ $arg->{src} =~ s{^ =for \s+ Euclid\b [^\n]* \s* (.*) \z}{}ixms
Branch: 1 branch
BranchTrueFalseTotal
$arg->{"src"} =~ s/^ =for \s+ Euclid\b [^\n]* \s* (.*) \z//imsx or next ARG 246 239 485
572 or next ARG;
573 239 my $info = $1;
574  
575 239 $arg->{is_repeatable} = $info =~ s{^ \s* repeatable \s*? $}{}xms;
576  
577 239 my @false_vals;
578 239 ▶ while ( $info =~ s{^ \s* false \s*[:=] \s* ([^\n]*)}{}xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info =~ s/^ \s* false \s*[:=] \s* ([^\n]*)//msx) 10 239 249
579 10 my $regex = $1;
580 10 ▶ 1 while $regex =~ s/ \[ ([^]]*) \] /(?:$1)?/gxms;
Branch: 1 branch
BranchTrueFalseTotal
$regex =~ s/ \[ ([^]]*) \] /(?:$1)?/gmsx and do { '???' } 3 10 13
581 10 $regex =~ s/ (\s+) /$1.'[\\s\\0\\1]*'/egxms;
582 10 push @false_vals, $regex;
583 }
584 239 ▶ if (@false_vals) {
Branch: 1 branch
BranchTrueFalseTotal
if (@false_vals) 8 231 239
585 8 $arg->{false_vals} = '(?:' . join( '|', @false_vals ) . ')';
586 }
587  
588 239 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($info =~ /\G \s* (([^.]+)\.([^:=\s]+) \s*[:=]\s* ([^\n]*)) /cgmsx) 405 232 637
589 $info =~ m{\G \s* (([^.]+)\.([^:=\s]+) \s*[:=]\s* ([^\n]*)) }gcxms )
590 {
591 405 my ( $spec, $var, $field, $val ) = ( $1, $2, $3, $4 );
592  
593 # Check for misplaced fields...
594 405 ▶ if ( $arg->{name} !~ m{\Q<$var>}xms ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg->{"name"} =~ /\Q<$var>\E/msx) 1 404 405
595 1 _fail( "Invalid constraint: $spec\n(No <$var> placeholder in ".
596 "argument: $arg->{name})" );
597 }
598  
599 # Decode...
600 404 ▶ if ( $field eq 'type.error' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($field eq 'type.error') { } 2 402 404
elsif ($field eq 'type') { } 238 164 402
elsif ($field eq 'default' or $field eq 'opt_default') { } 156 8 164
elsif ($field eq 'excludes.error') { } 1 7 8
elsif ($field eq 'excludes') { } 6 1 7
601 2 $arg->{var}{$var}{type_error} = $val;
602 } elsif ( $field eq 'type' ) {
603 238 $val = _qualify_variables_fully( $val );
604 238 my ( $matchtype, $comma, $constraint ) =
605 $val =~ m{(/(?:\.|.)+/ | [^,\s]+)\s*(?:(,))?\s*(.*)}xms;
606 238 $arg->{var}{$var}{type} = $matchtype;
607 238 ▶ if ( $comma && length $constraint ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($comma and length $constraint) { } 18 220 238
elsif (length $constraint) { } 39 181 220
Condition66%2/3
$comma and length $constraint
!ll&&!rl&&r
220018
MC/DC50%1/2
$comma and length $constraint
$comma length $constraint
Truth table66%2/3
A and B
A= $commaB= length $constraint
ABresult
0X0
100
111
608 18 ( $arg->{var}{$var}{constraint_desc} = $constraint ) =~
609 s/\s*\b\Q$var\E\b\s*//g;
610 18 $constraint =~ s/\b\Q$var\E\b/\$_[0]/g;
611 18 ▶ $arg->{var}{$var}{constraint} = eval "sub{ $constraint }"
Branch: 1 branch
BranchTrueFalseTotal
$arg->{"var"}{$var}{"constraint"} = eval "sub{ $constraint }" or _fail("Invalid .type constraint: $spec\n($@)") 0 18 18
612 or _fail("Invalid .type constraint: $spec\n($@)");
613 } elsif ( length $constraint ) {
614 39 $arg->{var}{$var}{constraint_desc} = $constraint;
615 $arg->{var}{$var}{constraint} =
616 39 ▶ eval "sub{ \$_[0] $constraint }"
Branch: 1 branch
BranchTrueFalseTotal
$arg->{"var"}{$var}{"constraint"} = eval "sub{ \$_[0] $constraint }" or _fail("Invalid .type constraint: $spec\n($@)") 0 39 39
617 or _fail("Invalid .type constraint: $spec\n($@)");
618 } else {
619 181 $arg->{var}{$var}{constraint_desc} = $matchtype;
620 $arg->{var}{$var}{constraint} =
621 $matchtype =~ m{\A\s*/.*/\s*\z}xms
622 4 ▶ ? sub { 1 }
Subroutine __ANON__: called CC=1 SCAR=0.0
623 181 ▶ : $std_constraint_for{$matchtype}
Branch: 2 branches
BranchTrueFalseTotal
$arg->{"var"}{$var}{"constraint"} = $matchtype =~ m[\A\s*/.*/\s*\z]msx ? sub { 1; } : $std_constraint_for{$matchtype} or _fail("Unknown .type constraint: $spec") 1 180 181
$matchtype =~ m[\A\s*/.*/\s*\z]msx ? : 4 177 181
624 or _fail("Unknown .type constraint: $spec");
625 }
626  
627 ▶ } elsif ( ($field eq 'default') || ($field eq 'opt_default') ) {
Condition100%3/3
$field eq "default" or $field eq "opt_default"
l!l&&r!l&&!r
14978
MC/DC100%2/2
$field eq "default" or $field eq "opt_default"
$field eq "default" $field eq "opt_default"
Truth table100%3/3
A or B
A= $field eq "default"B= $field eq "opt_default"
ABresult
1X1
011
000
628 156 $val = _qualify_variables_fully( $val );
629 156 ▶ eval "\$val = $val; 1"
Branch: 1 branch
BranchTrueFalseTotal
eval "\$val = $val; 1" or _fail("Invalid .$field value: $spec\n($@)") 1 155 156
630 or _fail("Invalid .$field value: $spec\n($@)");
631 155 $arg->{var}{$var}{$field} = $val;
632 155 my $has_field = 'has_'.$field;
633 $arg->{$has_field} = exists $arg->{$has_field} ?
634 155 ▶ $arg->{$has_field}++ :
Branch: 1 branch
BranchTrueFalseTotal
exists $arg->{$has_field} ? : 2 153 155
635 1;
636  
637 155 ▶ if ($field eq 'opt_default') {
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq "opt_default") 7 148 155
638 # Check that placeholders with optional defaults have a flagged argument
639 7 ▶ if ( $arg->{name} =~ m{^<}xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{"name"} =~ /^</msx) 1 6 7
640 1 _fail( "Invalid .$field constraint: $spec\nParameter ".
641 "$arg->{name} must have a flag" );
642 }
643 # Check that placeholders with optional defaults is optional
644 6 ▶ if ( $arg->{name} !~ m{\Q[<$var>]}xms ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg->{"name"} =~ /\Q[<$var>]\E/msx) 1 5 6
645 1 _fail( "Invalid .$field constraint: $spec\nPlaceholder".
646 " <$var> must be optional, i.e. [<$var>], to have ".
647 "an optional default in argument: $arg->{name}" );
648 }
649 }
650  
651 } elsif ( $field eq 'excludes.error' ) {
652 1 $arg->{var}{$var}{excludes_error} = $val;
653 } elsif ( $field eq 'excludes' ) {
654 6 $arg->{var}{$var}{excludes} = [ split '\s*,\s*', $val ];
655 6 for my $excl_var (@{$arg->{var}{$var}{excludes}}) {
656 8 ▶ if ($var eq $excl_var) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var eq $excl_var) 1 7 8
657 1 _fail( "Invalid .excludes value for variable <$var>: ".
658 "<$excl_var> cannot exclude itself." );
659 }
660 }
661 } else {
662 1 _fail("Unknown specification: $spec");
663 }
664 }
665 # Record variables excluded by another that has a default
666 232 ▶ while (my ($var_name, $var_data) = each %{$arg->{var}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$arg{"var"};}) 256 232 488
667 256 for my $excl_var (@{$arg->{var}{$var_name}{excludes}}) {
668 7 ▶ $excluded_by_def{$excl_var}{default}{$var_name} = 1 if $arg->{has_default};
Branch: 1 branch
BranchTrueFalseTotal
if $arg->{"has_default"} 6 1 7
669 7 ▶ $excluded_by_def{$excl_var}{opt_default}{$var_name} = 1 if $arg->{has_opt_default};
Branch: 1 branch
BranchTrueFalseTotal
if $arg->{"has_opt_default"} 0 7 7
670 }
671 }
672 232 ▶ if ( $info =~ m{\G \s* ([^\s\0\1] [^\n]*) }gcxms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info =~ /\G \s* ([^\s\0\1] [^\n]*) /cgmsx) 1 231 232
673 1 _fail("Unknown specification: $1");
674 }
675 }
676  
677 # Validate and complete .excludes specs
678  
679 52 ▶ while ( (undef, my $arg) = each %$args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(undef, $arg) = each %$args) 440 51 491
680 440 ▶ while ( my ($var, $var_specs) = each %{$arg->{var}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$arg{"var"};}) 240 439 679
681 # Check for invalid placeholder name in .excludes specifications
682 240 for my $excl_var (@{$var_specs->{excludes}}) {
683 7 ▶ if (not exists $all_var_list{$excl_var}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $all_var_list{$excl_var}) 1 6 7
684 1 _fail( "Invalid .excludes value for variable <$var>: ".
685 "<$excl_var> does not exist\n" );
686 }
687 }
688 # Remove default for placeholders excluded by others that have a default
689 239 for my $type ( 'default', 'opt_default' ) {
690 478 ▶ if ( (exists $arg->{var}->{$var}->{$type}) && (exists $excluded_by_def{$var}{$type}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg->{"var"}{$var}{$type} and exists $excluded_by_def{$var}{$type}) 3 475 478
Condition100%3/3
exists $arg->{"var"}{$var}{$type} and exists $excluded_by_def{$var}{$type}
!ll&&!rl&&r
3401353
MC/DC100%2/2
exists $arg->{"var"}{$var}{$type} and exists $excluded_by_def{$var}{$type}
exists $arg->{"var"}{$var}{$type} exists $excluded_by_def{$var}{$type}
Truth table100%3/3
A and B
A= exists $arg->{"var"}{$var}{$type}B= exists $excluded_by_def{$var}{$type}
ABresult
0X0
100
111
691 3 delete $arg->{var}->{$var}->{$type};
692 3 $arg->{"has_$type"}--;
693 3 ▶ if ($arg->{"has_$type"} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$arg{"has_$type"} == 0) 2 1 3
694 2 delete $arg->{"has_$type"};
695 }
696 }
697 }
698 }
699 }
700  
701 51 return 1;
702 }
703  
704  
705 sub _qualify_variables_fully {
706 # Restore fully-qualified name to variables:
707 # $x becomes $main::x
708 # $::x becomes $main::x
709 # $Package::x stays as $Package::x
710 # /^asdf$/ stays as /^asdf$/
711 # '$10' stays as '$10'
712 # Note: perlvar indicates that ' can also be used instead of ::
713 394 ▶ my ($val) = @_;
Subroutine _qualify_variables_fully: called CC=7 SCAR=19.5
714 394 ▶ if ($val =~ m/[\$\@\%]/) { # Avoid expensive Text::Balanced operations when there are no variables
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /[\$\@\%]/) { } 9 385 394
715 9 my $new_val;
716 9 ▶ for my $s (extract_multiple($val,[{Quoted=>sub{extract_delimited($_[0])}}],undef,0)) {
Subroutine __ANON__: called CC=1 SCAR=0.0
717 10 ▶ if (not ref $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $s) { } 9 1 10
718 # A non-quoted section... may contain variables to fix
719 9 for my $var_name ( @{_get_variable_names($s)} ) {
720 # Skip fully qualified names, such as '$Package::x'
721 11 ▶ next if $var_name =~ m/main(?:'|::)/;
Branch: 1 branch
BranchTrueFalseTotal
if $var_name =~ /main(?:'|::)/ 1 10 11
722 # Remove sigils from beginning of variable name: $ @ % {
723 10 $var_name =~ s/^[\$\@\%\{]+//;
724 # Substitute non-fully qualified vars, e.g. '$x' or '$::x', by '$main::x'
725 10 my $new_name = Symbol::qualify($var_name, 'main');
726 10 ▶ next if $new_name eq $var_name;
Branch: 1 branch
BranchTrueFalseTotal
if $new_name eq $var_name 1 9 10
727 9 $var_name = quotemeta( $var_name );
728 9 $s =~ s/$var_name/$new_name/;
729 }
730 9 $new_val .= $s;
731 } else {
732 # A quoted section, to keep as-is
733 1 $new_val .= $$s;
734 }
735 }
736 9 return $new_val;
737 } else {
738 385 return $val;
739 }
740 }
741  
742  
743 sub _get_variable_names {
744 # Get an arrayref of the variables names found in the provided string.
745 # This function is a hack, needed only because of Text::Balanced ticket #78855:
746 # https://rt.cpan.org/Public/Bug/Display.html?id=78855
747 9 ▶ my ($str) = @_;
Subroutine _get_variable_names: called CC=3 SCAR=11.0
748 9 my $vars = [];
749 9 ▶ for my $var (extract_multiple($str,[sub{extract_variable($_[0],'')}],undef,1)) {
Subroutine __ANON__: called CC=1 SCAR=0.0
750 # Name must start with underscore or a letter, e.g. $t $$h{a} ${$h}{a} $h->{a} @_
751 # Skip special or invalid names, e.g. $/ $1
752 13 my $tmp = $var;
753 13 $tmp =~ s/(?:{|})//g;
754 13 ▶ next if not $tmp =~ m/^[\$\@\%]+[_a-z]/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $tmp =~ /^[\$\@\%]+[_a-z]/i 2 11 13
755 11 push @$vars, $var;
756 }
757 9 return $vars;
758 }
759  
760  
761 sub _minimize_name {
762 693 ▶ my ($name_re) = @_;
Subroutine _minimize_name: called CC=1 SCAR=0.0
763 693 $name_re =~ s{[][]}{}gxms; # remove all square brackets
764 693 $name_re =~ s{\A \W+ ([\w-]*) .* \z}{$1}gxms;
765 693 $name_re =~ s{-}{_}gxms;
766 693 return $name_re;
767 }
768  
769  
770 sub _minimize_entries_of {
771 96 ▶ my ($arg_ref) = @_;
Subroutine _minimize_entries_of: called CC=3 SCAR=11.0
772 96 ▶ return if ref $arg_ref ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $arg_ref ne "HASH" 0 96 96
773  
774 96 for my $old_key (keys %$arg_ref) {
775 652 my $new_key = _minimize_name($old_key);
776 652 $arg_ref->{$new_key} = delete $arg_ref->{$old_key};
777 }
778  
779 96 return 1;
780 }
781  
782  
783 # Do match, recursively trying to expand cuddles...
784 sub _doesnt_match {
785 60 ▶ my ( $matcher, $argv, $arg_specs_ref ) = @_;
Subroutine _doesnt_match: called CC=7 SCAR=19.5
786  
787 60 our @errors; # 'our' instead of 'my' because it is needed for the re pragma
788 60 local @errors = ();
789 60 %ARGV = ();
790  
791 # Match arguments, populate %ARGV and @errors
792 # Note that the matcher needs the pragma: use re 'eval';
793 60 $argv =~ m{\A (?: \s* $matcher )* \s* \z}xms;
794  
795 # Report errors in passed arguments
796 60 for my $error (@errors) {
797 12 ▶ if ( $error =~ m/\A ((\W) (\w) (\w+))/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ /\A ((\W) (\w) (\w+))/msx) 5 7 12
798 5 my ( $bundle, $marker, $firstchar, $chars ) = ( $1, $2, $3, $4 );
799 5 $argv =~ s{\Q$bundle\E}{$marker$firstchar $marker$chars}xms;
800 5 ▶ return if !_doesnt_match( $matcher, $argv, $arg_specs_ref );
Branch: 1 branch
BranchTrueFalseTotal
unless _doesnt_match($matcher, $argv, $arg_specs_ref) 2 3 5
801 }
802 ARG:
803 10 for my $arg_spec_ref ( values %{$arg_specs_ref} ) {
804 48 our $bad_type;
805 48 local $bad_type;
806 next ARG
807 48 ▶ if $error !~ m/\A [\s\0\1]* ($arg_spec_ref->{generic_matcher})/xms
Branch: 1 branch
BranchTrueFalseTotal
unless $error =~ /\A [\s\0\1]* ($arg_spec_ref->{"generic_matcher"})/msx and $Getopt::Euclid::bad_type 44 4 48
Condition100%3/3
$error =~ /\A [\s\0\1]* ($arg_spec_ref->{"generic_matcher"})/msx and $Getopt::Euclid::bad_type
!ll&&!rl&&r
4314
MC/DC100%2/2
$error =~ /\A [\s\0\1]* ($arg_spec_ref->{"generic_matcher"})/msx and $Getopt::Euclid::bad_type
$error =~ /\A [\s\0\1]* ($arg_spec_ref->{"generic_matcher"})/msx $Getopt::Euclid::bad_type
Truth table100%3/3
A and B
A= $error =~ /\A [\s\0\1]* ($arg_spec_ref->{"generic_matcher"})/msxB= $Getopt::Euclid::bad_type
ABresult
0X0
100
111
808 || !$bad_type;
809
810 my $msg = _type_error( $bad_type->{arg}, $bad_type->{var},
811 4 $bad_type->{val}, $bad_type->{type}, $bad_type->{type_error} );
812 4 return $msg;
813 }
814 6 return "Unknown argument: $error";
815 }
816  
817 48 return 0; # No error
818 }
819  
820  
821 sub _escape_arg {
822 615 ▶ my $arg = shift;
Subroutine _escape_arg: called CC=1 SCAR=0.0
823 615 my ($num_replaced) = ($arg =~ tr/ \t/\0\1/);
824 615 return $arg;
825 }
826  
827  
828 sub _rectify_arg {
829 418 ▶ my $arg = shift;
Subroutine _rectify_arg: called CC=1 SCAR=0.0
830 418 my ($num_replaced) = ($arg =~ tr/\0\1/ \t/);
831 418 return $arg;
832 }
833  
834  
835 sub _rectify_all_args {
836 47 ▶ while ( my (undef, $arg_list) = each %ARGV ) {
Subroutine _rectify_all_args: called CC=7 SCAR=21.5
Branch: 1 branch
BranchTrueFalseTotal
if (my(undef, $arg_list) = each %ARGV) 267 47 314
837 267 for my $arg ( @{$arg_list} ) {
838 278 ▶ if ( ref $arg eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'HASH') { } 278 0 278
839 278 for my $var ( values %{$arg} ) {
840 302 ▶ if ( ref $var eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $var eq 'ARRAY') { } 35 267 302
841 35 $var = [ map { _rectify_arg($_) } @{$var} ];
842 } else {
843 267 $var = _rectify_arg($var);
844 }
845 }
846 } else {
847 0 ▶ if ( ref $arg eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'ARRAY') { } 0 0 0
848 0 $arg = [ map { _rectify_arg($_) } @{$arg} ];
849 } else {
850 0 $arg = _rectify_arg($arg);
851 }
852 }
853 }
854 }
855 47 return 1;
856 }
857  
858  
859 sub _verify_args {
860 47 ▶ my ($arg_specs_ref) = @_;
Subroutine _verify_args: called CC=39 SCAR=38.2
861 # Check exclusive variables, variable constraints and fill in defaults...
862 # Handle mutually exclusive arguments
863 47 my %seen_vars;
864 47 ▶ while ( my ($arg_name, $arg_elems) = each %ARGV ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %ARGV) 267 47 314
865 267 for my $elem (@{$arg_elems}) {
866 278 ▶ while ( my ($var_name) = each (%{$elem}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($var_name) = each %{$elem;}) 302 278 580
867 302 ▶ $seen_vars{$var_name} = $arg_name if $var_name;
Branch: 1 branch
BranchTrueFalseTotal
if $var_name 258 44 302
868 }
869 }
870 }
871  
872 47 ▶ while ( my ($arg_name, $arg) = each %{$arg_specs_ref} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$arg_specs_ref;}) 425 44 469
873 425 ▶ while ( my ($var_name, $var) = each %{$arg->{var}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$arg{"var"};}) 327 422 749
874 # Enforce placeholders that cannot be specified with others
875 327 for my $excluded_var ( @{$var->{excludes}} ) {
876 12 ▶ if (exists $seen_vars{$var_name} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $seen_vars{$var_name} and exists $seen_vars{$excluded_var}) 3 9 12
Condition66%2/3
exists $seen_vars{$var_name} and exists $seen_vars{$excluded_var}
!ll&&!rl&&r
903
MC/DC50%1/2
exists $seen_vars{$var_name} and exists $seen_vars{$excluded_var}
exists $seen_vars{$var_name} exists $seen_vars{$excluded_var}
Truth table66%2/3
A and B
A= exists $seen_vars{$var_name}B= exists $seen_vars{$excluded_var}
ABresult
0X0
100
111
877 exists $seen_vars{$excluded_var}) {
878 3 my $excl_arg = $seen_vars{$excluded_var};
879 3 my $msg;
880 3 ▶ if (exists $var->{excludes_error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $var->{'excludes_error'}) { } 1 2 3
881 1 $msg = $var->{excludes_error};
882 } else {
883 2 $msg =
884 qq{Invalid "$excl_arg" argument.\n<$excluded_var> }.
885 qq{cannot be specified with <$var_name> because }.
886 qq{argument "$arg_name" excludes <$excluded_var>};
887 }
888 3 _bad_arglist($msg);
889 }
890 }
891 }
892 }
893  
894 # Enforce constraints and fill in defaults...
895 ARG:
896 44 ▶ while (my ($arg_name, $arg_specs) = each %{$arg_specs_ref} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$arg_specs_ref;}) 383 39 422
897  
898 # Skip non-existent/non-defaulting/non-optional-defaulting arguments
899 next ARG
900 if !exists $ARGV{$arg_name}
901 && !( $arg_specs->{has_default}
902 383 ▶ || $arg_specs->{has_opt_default} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ARGV{$arg_name} or ($arg_specs->{"has_default"} or $arg_specs->{"has_opt_default"}) 113 270 383
Condition100%6/6
exists $ARGV{$arg_name} or ($arg_specs->{"has_default"} or $arg_specs->{"has_opt_default"})
l!l&&r!l&&!r
2351147
$arg_specs->{"has_default"} or $arg_specs->{"has_opt_default"}
l!l&&r!l&&!r
341113
MC/DC66%2/3
exists $ARGV{$arg_name} or ($arg_specs->{"has_default"} or $arg_specs->{"has_opt_default"})
exists $ARGV{$arg_name} $arg_specs->{"has_default"} $arg_specs->{"has_opt_default"}
Truth table75%3/4
A or B or C
A= exists $ARGV{$arg_name}B= $arg_specs->{"has_default"}C= $arg_specs->{"has_opt_default"}
ABCresult
1XX1
01X1
0011
0000
903  
904 # Ensure all vars exist within arg...
905 270 my @vars = keys %{$arg_specs->{placeholders}};
906 270 for my $index ( 0 .. $#{ $ARGV{$arg_name} } ) {
907 246 my $entry = $ARGV{$arg_name}[$index];
908 246 @{$entry}{@vars} = @{$entry}{@vars};
909  
910 # Get arg specs...
911 VAR:
912 246 for my $var (@vars) {
913  
914 251 my $arg_vars = $arg_specs->{var}->{$var};
915  
916 # Check constraints on vars...
917 251 ▶ if ( exists $ARGV{$arg_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ARGV{$arg_name}) 251 0 251
918  
919 251 ▶ if ( ref $entry eq 'HASH' && defined $entry->{$var} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $entry eq 'HASH' and defined $entry->{$var}) { } 225 26 251
elsif (ref $entry ne 'HASH' and defined $entry) { } 0 52 52
Condition66%2/3
ref $entry eq "HASH" and defined $entry->{$var}
!ll&&!rl&&r
026225
MC/DC50%1/2
ref $entry eq "HASH" and defined $entry->{$var}
ref $entry eq "HASH" defined $entry->{$var}
Truth table66%2/3
A and B
A= ref $entry eq "HASH"B= defined $entry->{$var}
ABresult
0X0
100
111
920 # Named vars...
921 225 ▶ for my $val (
Branch: 1 branch
BranchTrueFalseTotal
ref $entry->{$var} eq 'ARRAY' ? : 35 190 225
922 ref $entry->{$var} eq 'ARRAY'
923 35 ? @{ $entry->{$var} }
924 : $entry->{$var}
925 )
926 {
927 325 ▶ if ( $arg_vars->{constraint} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_vars->{"constraint"} and not $arg_vars->{"constraint"}->($val)) 5 320 325
Condition100%3/3
$arg_vars->{"constraint"} and not $arg_vars->{"constraint"}->($val)
!ll&&!rl&&r
772435
MC/DC100%2/2
$arg_vars->{"constraint"} and not $arg_vars->{"constraint"}->($val)
$arg_vars->{"constraint"} not $arg_vars->{"constraint"}->($val)
Truth table100%3/3
A and not(B)
A= $arg_vars->{"constraint"}B= not $arg_vars->{"constraint"}->($val)
ABresult
0X0
100
111
928 !$arg_vars->{constraint}->($val) ) {
929 _bad_arglist( _type_error($arg_name, $var, $val,
930 $arg_vars->{constraint_desc},
931 5 $arg_vars->{type_error}) );
932 }
933 }
934 220 next VAR;
935 ▶ } elsif ( ref $entry ne 'HASH' && defined $entry ) {
Condition33%1/3
ref $entry ne "HASH" and defined $entry
!ll&&!rl&&r
2600
MC/DC0%0/2
ref $entry ne "HASH" and defined $entry
ref $entry ne "HASH" defined $entry
Truth table33%1/3
A and B
A= ref $entry ne "HASH"B= defined $entry
ABresult
0X0
100
111
936 # Unnamed vars...
937 0 ▶ for my $val (
Branch: 1 branch
BranchTrueFalseTotal
ref $entry eq 'ARRAY' ? : 0 0 0
938 ref $entry eq 'ARRAY'
939 0 ? @{$entry}
940 : $entry
941 )
942 {
943 0 ▶ if ( $arg_vars->{constraint} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_vars->{"constraint"} and not $arg_vars->{"constraint"}->($val)) 0 0 0
Condition0%0/3
$arg_vars->{"constraint"} and not $arg_vars->{"constraint"}->($val)
!ll&&!rl&&r
000
MC/DC0%0/2
$arg_vars->{"constraint"} and not $arg_vars->{"constraint"}->($val)
$arg_vars->{"constraint"} not $arg_vars->{"constraint"}->($val)
Truth table0%0/3
A and not(B)
A= $arg_vars->{"constraint"}B= not $arg_vars->{"constraint"}->($val)
ABresult
0X0
100
111
944 !$arg_vars->{constraint}->($val) ) {
945 _bad_arglist( _type_error( $arg_name, $var, $val,
946 $arg_vars->{constraint_desc},
947 0 $arg_vars->{type_error}) );
948 }
949 $entry->{$var} = ''
950 0 ▶ unless defined( $ARGV{$arg_name} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ARGV{$arg_name} 0 0 0
951 }
952 0 next VAR;
953 }
954 }
955  
956 # Assign placeholder defaults (if necessary)...
957 next ARG
958 if !exists $arg_vars->{default}
959 26 ▶ && !exists $arg_vars->{opt_default};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $arg_vars->{"default"} or exists $arg_vars->{"opt_default"} 9 17 26
Condition100%3/3
exists $arg_vars->{"default"} or exists $arg_vars->{"opt_default"}
l!l&&r!l&&!r
1619
MC/DC100%2/2
exists $arg_vars->{"default"} or exists $arg_vars->{"opt_default"}
exists $arg_vars->{"default"} exists $arg_vars->{"opt_default"}
Truth table100%3/3
A or B
A= exists $arg_vars->{"default"}B= exists $arg_vars->{"opt_default"}
ABresult
1X1
011
000
960  
961 $entry->{$var} = exists $arg_vars->{opt_default} ?
962 $arg_vars->{opt_default} :
963 17 ▶ $arg_vars->{default};
Branch: 1 branch
BranchTrueFalseTotal
exists $arg_vars->{'opt_default'} ? : 2 15 17
964 }
965 }
966  
967 # Handle defaults for missing args...
968 256 ▶ if ( !@{ $ARGV{$arg_name} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$ARGV{$arg_name};}) 35 221 256
969 35 for my $var (@vars) {
970 # Assign defaults (if necessary)...
971 37 my $arg_vars = $arg_specs->{var}->{$var};
972 next ARG
973 37 ▶ if !exists $arg_vars->{default}; # no default specified
Branch: 1 branch
BranchTrueFalseTotal
unless exists $arg_vars->{"default"} 5 32 37
974  
975 # Omit default if it conflicts with a specified parameter
976 32 for my $excl_var ( @{$arg_specs->{var}->{$var}->{excludes}} ) {
977 5 ▶ if (exists $seen_vars{$excl_var}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $seen_vars{$excl_var}) 3 2 5
978 3 next ARG;
979 }
980 }
981  
982 29 $ARGV{$arg_name}[0]{$var} = $arg_vars->{default};
983 }
984 }
985 }
986 39 return 1;
987 }
988  
989  
990 sub _type_error {
991 9 ▶ my ($arg_name, $var_name, $var_val, $var_constraint, $var_error) = @_;
Subroutine _type_error: called CC=2 SCAR=6.9
992 9 my $msg = qq{Invalid "$arg_name" argument.\n};
993 9 $var_name =~ s{\W+}{}gxms;
994 9 ▶ if ( $var_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_error) { } 3 6 9
995 3 $msg = $var_error;
996 3 $msg =~ s{(?<!<)\b$var_name\b|\b$var_name\b(?!>)}{$var_val}gxms;
997 } else {
998 6 $msg = qq{<$var_name> must be $var_constraint but the supplied value }.
999 qq{("$var_val") is not.};
1000 }
1001 9 return $msg;
1002 }
1003  
1004  
1005 sub _convert_to_regex {
1006 50 ▶ my ($args_ref) = @_;
Subroutine _convert_to_regex: called CC=14 SCAR=26.4
1007  
1008 # Regexp to capture the start of a new argument
1009 50 my $no_esc_ws = '(?!\0)'; # no escaped whitespaces
1010  
1011 50 my @arg_variants;
1012 50 ▶ while ( my ($arg_name, $arg_specs) = each %{$args_ref} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$args_ref;}) 427 50 477
1013 427 push @arg_variants, @{$arg_specs->{variants}};
1014 }
1015  
1016 50 my $no_match = join('|',@arg_variants);
1017 50 $no_match = _escape_specials($no_match);
1018 50 $no_match = '(?!(?:'.$no_match.')'.$no_esc_ws.')';
1019  
1020 50 ▶ while ( my ($arg_name, $arg) = each %{$args_ref} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$args_ref;}) 427 50 477
1021 427 my $regex = $arg_name;
1022  
1023 # Quotemeta specials...
1024 427 $regex = _escape_specials($regex);
1025 427 $regex = "(?:$regex)";
1026  
1027 # Convert optionals...
1028 427 ▶ 1 while $regex =~ s/ \[ ([^]]*) \] /(?:$1)?/gxms;
Branch: 1 branch
BranchTrueFalseTotal
$regex =~ s/ \[ ([^]]*) \] /(?:$1)?/gmsx and do { '???' } 195 427 622
1029 427 $regex =~ s/ (\s+) /$1.'\s*'.$no_esc_ws/egxms;
1030 427 my $generic = $regex;
1031  
1032 # Set the matcher
1033 $regex =~
1034 s{ < (.*?) >(\.\.\.|) }
1035 342 { my ($var_name, $var_rep) = ($1, $2);
1036 342 $var_name =~ s/(\s+)\[\\s\\0\\1]\*/$1/gxms;
1037 342 ▶ my $type = $arg->{var}{$var_name}{type} || q{};
Condition100%2/2
$arg->{'var'}{$var_name}{'type'} || ''
l!l
211131
MC/DC100%1/1
$arg->{'var'}{$var_name}{'type'} || ''
$arg->{'var'}{$var_name}{'type'}
Truth table100%2/2
A
A= $arg->{'var'}{$var_name}{'type'}
Aresult
11
00
1038 342 $arg->{placeholders}->{$var_name} = undef;
1039 my $matcher =
1040 $type =~ m{\A\s*/.*/\s*\z}xms
1041 ? eval "qr$type"
1042 342 ▶ : $std_matcher_for{ $type }
Branch: 2 branches
BranchTrueFalseTotal
my $matcher = $type =~ m[\A\s*/.*/\s*\z]msx ? eval "qr$type" : $std_matcher_for{$type} or _fail("Unknown type ($type) in specification: $arg_name") 0 342 342
$type =~ m[\A\s*/.*/\s*\z]msx ? : 4 338 342
1043 or _fail("Unknown type ($type) in specification: $arg_name");
1044 342 ▶ $var_rep ?
Branch: 1 branch
BranchTrueFalseTotal
$var_rep ? : 38 304 342
1045 "(?:[\\s\\0\\1]*$no_match($matcher)(?{push \@{(\$ARGV{q{$arg_name}}||=[{}])->[-1]{q{$var_name}}}, \$^N}))+"
1046 :
1047 "(?:$no_match($matcher)(?{(\$ARGV{q{$arg_name}}||=[{}])->[-1]{q{$var_name}} = \$^N}))";
1048 }gexms
1049 427 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
$regex =~ s[ < (.*?) >(\.\.\.|) ](() = ($1, $2); $var_name =~ s/(\s+)\[\\s\\0\\1]\*/$1/gmsx; my $type = $arg->{"var"}{$var_name}{"type"} || ""; $arg->{"placeholders"}{$var_name} = undef; my $matcher = $type =~ m[\A\s*/.*/\s*\z]msx ? eval "qr$type" : $std_matcher_for{$type} or _fail("Unknown type ($type) in specification: $arg_name"); $var_rep ? "(?:[\\s\\0\\1]*$no_match($matcher)(?{push \@{(\$ARGV{q{$arg_name}}||=[{}])->[-1]{q{$var_name}}}, \$^N}))+" : "(?:$no_match($matcher)(?{(\$ARGV{q{$arg_name}}||=[{}])->[-1]{q{$var_name}} = \$^N}))";)egmsx or do { $regex .= "(?{(\$ARGV{q{$arg_name}}||=[{}])->[-1]{q{}} = 1})" } 162 265 427
1050 162 $regex .= "(?{(\$ARGV{q{$arg_name}}||=[{}])->[-1]{q{}} = 1})";
1051 };
1052  
1053 427 ▶ if ( $arg->{is_repeatable} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{'is_repeatable'}) { } 6 421 427
1054 6 $arg->{matcher} = "$regex (?:(?<!\\w)|(?!\\w)) (?{push \@{\$ARGV{q{$arg_name}}}, {} })";
1055 } else {
1056 $arg->{matcher} = "(??{exists\$ARGV{q{$arg_name}}?'(?!)':''}) "
1057 . (
1058 $arg->{false_vals}
1059 421 ▶ ? "(?:$arg->{false_vals} (?:(?<!\\w)|(?!\\w)) (?{\$ARGV{q{$arg_name}} ||= [{ q{} => 0 }] }) | $regex (?:(?<!\\w)|(?!\\w)) (?{\$ARGV{q{$arg_name}} ||= [{ q{} => 1}] }))"
Branch: 1 branch
BranchTrueFalseTotal
$arg->{'false_vals'} ? : 8 413 421
1060 : "$regex (?:(?<!\\w)|(?!\\w)) (?{\$ARGV{q{$arg_name}} ||= [{}] })"
1061 );
1062 }
1063  
1064 # Set the generic matcher
1065 427 $generic =~
1066 s{ < (.*?) > }
1067 342 { my $var_name = $1;
1068 342 $var_name =~ s/(\s+)\[\\s\\0\\1]\*/$1/gxms;
1069 342 ▶ my $type = $arg->{var}{$var_name}{type} || q{};
Condition100%2/2
$arg->{'var'}{$var_name}{'type'} || ''
l!l
211131
MC/DC100%1/1
$arg->{'var'}{$var_name}{'type'} || ''
$arg->{'var'}{$var_name}{'type'}
Truth table100%2/2
A
A= $arg->{'var'}{$var_name}{'type'}
Aresult
11
00
1070 342 ▶ my $type_error = $arg->{var}{$var_name}{type_error} || q{};
Condition100%2/2
$arg->{'var'}{$var_name}{'type_error'} || ''
l!l
2340
MC/DC100%1/1
$arg->{'var'}{$var_name}{'type_error'} || ''
$arg->{'var'}{$var_name}{'type_error'}
Truth table100%2/2
A
A= $arg->{'var'}{$var_name}{'type_error'}
Aresult
11
00
1071 my $matcher = $type =~ m{\A\s*/.*/\s*\z}xms
1072 ? eval "qr$type"
1073 342 ▶ : $std_matcher_for{ $type };
Branch: 1 branch
BranchTrueFalseTotal
$type =~ m[\A\s*/.*/\s*\z]msx ? : 4 338 342
1074 342 "(?:($matcher|([^\\s\\0\\1]+)"
1075 . "(?{\$bad_type ||= "
1076 . "{arg=>q{$arg_name},type=>q{$type},type_error=>q{$type_error}, var=>q{<$var_name>},val=>\$^N};})))"
1077 }gexms;
1078 427 $arg->{generic_matcher} = $generic;
1079 }
1080 50 return 1;
1081 }
1082  
1083  
1084 sub _escape_specials {
1085 # Escape quotemeta special characters
1086 477 ▶ my $arg = shift;
Subroutine _escape_specials: called CC=1 SCAR=0.0
1087 477 $arg =~ s{([@#\$^*()+{}?])}{\\$1}gxms;
1088 477 return $arg;
1089 }
1090  
1091  
1092 sub _print_pod {
1093 0 ▶ my ( $pod, $paged ) = @_;
Subroutine _print_pod: not called CC=4 SCAR=30.0
1094  
1095 0 ▶ if ($paged) {
Branch: 1 branch
BranchTrueFalseTotal
if ($paged) 0 0 0
1096 # Page output
1097 0 ▶ eval { require IO::Pager::Page } or eval { require IO::Page };
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require IO::Pager::Page } } or eval { do { require IO::Page } } 0 0 0
1098 }
1099
1100 # Convert POD to plaintext, wrapping the lines at 76 chars and print to STDOUT
1101 0 ▶ open my $parser_in, '<', \$pod or croak "Could not read from variable because $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $parser_in, "<", \$pod or croak("Could not read from variable because $!") 0 0 0
1102 0 Pod::PlainText->new()->parse_from_filehandle($parser_in);
1103 0 close $parser_in;
1104  
1105 0 return 1;
1106 }
1107  
1108  
1109 sub _validate_name {
1110 # Check that the argument name only has pairs of < > brackets (ticket 34199)
1111 # Return the name of the variables that this argument specifies
1112 487 ▶ my ($name) = @_;
Subroutine _validate_name: called CC=6 SCAR=17.9
1113 487 ▶ if ($name =~ m/[<>]/) { # skip expensive Text::Balance functions if possible
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /[<>]/) { } 302 185 487
1114 302 my %var_names;
1115 302 my $pos = 0;
1116 302 ▶ for my $s (extract_multiple($name,[sub{extract_bracketed($_[0],'<>')}],undef,0)) {
Subroutine __ANON__: called CC=1 SCAR=0.0
1117 832 ▶ next if not $s =~ m/[<>]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /[<>]/ 443 389 832
1118 389 $s =~ s/^<(.*)>$/$1/;
1119 389 ▶ if ( $s =~ m/[<>]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /[<>]/) 2 387 389
1120 2 _fail( 'Invalid argument specification: '.$name );
1121 }
1122 387 $pos++;
1123 387 ▶ $var_names{$s} = $pos if not exists $var_names{$s};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $var_names{$s} 374 13 387
1124 }
1125 300 return \%var_names;
1126 } else {
1127 185 return {};
1128 }
1129 }
1130  
1131  
1132 sub _get_variants {
1133 783 ▶ my @arg_desc = shift =~ m{ [^[|]+ (?: $optional_re [^[|]* )* }gmxs;
Subroutine _get_variants: called CC=7 SCAR=19.5
1134  
1135 783 for (@arg_desc) {
1136 808 s{^ \s+ | \s+ $}{}gxms;
1137 }
1138  
1139 # Only consider first "word"...
1140 783 ▶ return $1 if $arg_desc[0] =~ m/\A (< [^>]+ >)/xms;
Branch: 1 branch
BranchTrueFalseTotal
if $arg_desc[0] =~ /\A (< [^>]+ >)/msx 37 746 783
1141  
1142 746 $arg_desc[0] =~ s/\A ([^\s<]+) \s* (?: < .*)? \z/$1/xms;
1143  
1144 # Variants are all those with and without each optional component...
1145 746 my %variants;
1146 746 ▶ while (@arg_desc) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arg_desc) 2975 746 3721
1147 2975 my $arg_desc_with = shift @arg_desc;
1148 2975 my $arg_desc_without = $arg_desc_with;
1149  
1150 2975 ▶ if ( $arg_desc_without =~ s/ \[ [^][]* \] //xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_desc_without =~ s/ \[ [^][]* \] //msx) 1134 1841 2975
1151 1134 push @arg_desc, $arg_desc_without;
1152 }
1153 2975 ▶ if ( $arg_desc_with =~ m/ [[(] ([^][()]*) [])] /xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_desc_with =~ / [[(] ([^][()]*) [])] /msx) 1134 1841 2975
1154 1134 my $option = $1;
1155 1134 for my $alternative ( split /\|/, $option ) {
1156 1070 my $arg_desc = $arg_desc_with;
1157 1070 $arg_desc =~ s{[[(] [^][()]* [])]}{$alternative}xms;
1158 1070 push @arg_desc, $arg_desc;
1159 }
1160 }
1161  
1162 2975 $arg_desc_with =~ s/[][]//gxms;
1163 2975 $arg_desc_with =~ s/\b[^-\w] .* \z//xms;
1164 2975 $variants{$arg_desc_with} = 1;
1165 }
1166  
1167 746 return keys %variants;
1168 }
1169  
1170  
1171 sub _longestname {
1172 557 ▶ return ( sort { length $a <=> length $b || $a cmp $b } @_ )[-1];
Subroutine _longestname: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
length $a <=> length $b or $a cmp $b 1 525 526
1173 }
1174  
1175  
1176 sub _export_var {
1177 45 ▶ my ( $prefix, $key, $value ) = @_;
Subroutine _export_var: called CC=3 SCAR=11.0
1178 45 my $export_as = $prefix . $key;
1179 45 $export_as =~ s{\W}{_}gxms; # mainly for '-'
1180 45 ▶ my $callpkg = caller( $export_lvl + ($Exporter::ExportLevel || 0) );
Condition50%1/2
$Exporter::ExportLevel || 0
l!l
045
MC/DC0%0/1
$Exporter::ExportLevel || 0
$Exporter::ExportLevel
Truth table50%1/2
A
A= $Exporter::ExportLevel
Aresult
11
00
1181 65 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1182 45 ▶ *{"$callpkg\::$export_as"} = ( ref $value ) ? $value : \$value;
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 13 32 45
1183 45 return 1;
1184 }
1185  
1186  
1187 # Utility sub to factor out hash key aliasing...
1188 sub _make_equivalent {
1189 130 ▶ my ( $hash_ref, %alias_hash ) = @_;
Subroutine _make_equivalent: called CC=3 SCAR=11.0
1190  
1191 130 ▶ while ( my ( $name_re, $aliases ) = each %alias_hash ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %alias_hash) 910 130 1040
1192 910 for my $alias (@$aliases) {
1193 2730 $hash_ref->{$alias} = $hash_ref->{$name_re};
1194 }
1195 }
1196  
1197 130 return 1;
1198 }
1199  
1200  
1201 # Report problems in specification and die
1202 sub _fail {
1203 12 ▶ my (@msg) = @_;
Subroutine _fail: called CC=1 SCAR=0.0
1204 12 croak "Getopt::Euclid: @msg";
1205 }
1206  
1207  
1208 sub _get_pod_names {
1209 # Parse the POD of the caller program and its modules.
1210 66 ▶ my @caller = caller(1);
Subroutine _get_pod_names: called CC=5 SCAR=16.3
1211  
1212 # Sanity check
1213 66 ▶ if ($has_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_run) 0 66 66
1214 0 carp 'Getopt::Euclid loaded a second time';
1215 0 warn "Second attempt to parse command-line was ignored\n";
1216 0 return 0;
1217 }
1218  
1219 # Handle calls from .pm files
1220 66 ▶ if ( $caller[1] =~ m/[.]pm \z/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($caller[1] =~ /[.]pm \z/msx) 4 62 66
1221 4 my @caller = caller(1); # at import()'s level
1222 4 push @pod_names, $caller[1];
1223 # Install this import() sub as module's import sub...
1224 65 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1225 croak '.pm file cannot define an explicit import() when using Getopt::Euclid'
1226 4 ▶ if *{"$caller[0]::import"}{CODE};
Branch: 1 branch
BranchTrueFalseTotal
if *{"$caller[0]::import";}{"CODE"} 0 4 4
1227 4 my $lambda; # Needed so the anon sub is generated at run-time
1228 4 *{"$caller[0]::import"}
1229 4 ▶ = bless sub { $lambda = 1; goto &Getopt::Euclid::import },
Subroutine __ANON__: called CC=1 SCAR=0.0
1230 4 'Getopt::Euclid::Importer';
1231  
1232 4 return 0;
1233 }
1234  
1235 # Add name of caller program
1236 62 ▶ push @pod_names, $0 if (-e $0); # When calling perl -e '...', $0 is '-e', i.e. not a actual file
Branch: 1 branch
BranchTrueFalseTotal
if -e $0 61 1 62
1237  
1238 62 return 1;
1239 }
1240  
1241  
1242 sub _insert_default_values {
1243 101 ▶ my ($args) = @_;
Subroutine _insert_default_values: called CC=8 SCAR=20.8
1244 101 my $pod_string = '';
1245 # Retrieve item names in sequential order
1246 101 for my $item_name ( sort { $args->{$a}->{'seq'} <=> $args->{$b}->{'seq'} } (keys %$args) ) {
1247 428 my $item_spec = $args->{$item_name}->{'src'};
1248 428 $item_spec =~ s/=for(.*)//ms;
1249 428 $pod_string .= "=item $item_name\n\n";
1250 # Get list of variable for this argument
1251 428 ▶ while ( my ($var_name, $var) = each %{$args->{$item_name}->{var}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$args{$item_name}{"var"};}) 233 428 661
1252 # Get default for this variable
1253 233 for my $default_type ( 'default', 'opt_default' ) {
1254 466 my $var_default;
1255 466 ▶ if (exists $var->{$default_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $var->{$default_type}) { } 131 335 466
1256 131 ▶ if (ref($var->{$default_type}) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $var->{$default_type} eq 'ARRAY') { } 1 130 131
elsif (ref $var->{$default_type} eq '') { } 130 0 130
1257 1 $var_default = join(' ', @{$var->{$default_type}});
1258 } elsif (ref($var->{$default_type}) eq '') {
1259 130 $var_default = $var->{$default_type};
1260 } else {
1261 0 carp 'Getopt::Euclid found an unexpected default value type';
1262 }
1263 } else {
1264 335 $var_default = 'none';
1265 }
1266 466 $item_spec =~ s/$var_name\.$default_type/$var_default/g;
1267 }
1268 }
1269 428 ▶ if ($item_spec =~ m/(\S+(\.(?:opt_)?default))/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item_spec =~ /(\S+(\.(?:opt_)?default))/) 1 427 428
1270 1 my ($reference, $default_type) = ($1, $2);
1271 1 _fail( "Invalid reference to field $reference in argument ".
1272 "description:\n$item_spec" );
1273 }
1274 427 $pod_string .= $item_spec;
1275 }
1276 100 $pod_string = "=over\n\n".$pod_string."=back\n\n";
1277 100 return $pod_string;
1278 }
1279  
1280  
1281 65 1; # Magic true value required at end of module
1282  
1283  
1284 =head1 NAME
1285  
1286 Getopt::Euclid - Executable Uniform Command-Line Interface Descriptions
1287  
1288 =head1 VERSION
1289  
1290 This document describes Getopt::Euclid version 0.4.5
1291  
1292 =head1 SYNOPSIS
1293  
1294 use Getopt::Euclid;
1295  
1296 if ($ARGV{-i}) {
1297 print "Interactive mode...\n";
1298 }
1299  
1300 for my $x (0..$ARGV{-size}{h}-1) {
1301 for my $y (0..$ARGV{-size}{w}-1) {
1302 do_something_with($x, $y);
1303 }
1304 }
1305  
1306 __END__
1307  
1308 =head1 NAME
1309  
1310 yourprog - Your program here
1311  
1312 =head1 VERSION
1313  
1314 This documentation refers to yourprog version 1.9.4
1315  
1316 =head1 USAGE
1317  
1318 yourprog [options] -s[ize]=<h>x<w> -o[ut][file] <file>
1319  
1320 =head1 REQUIRED ARGUMENTS
1321  
1322 =over
1323  
1324 =item -s[ize]=<h>x<w>
1325  
1326 Specify size of simulation
1327  
1328 =for Euclid:
1329 h.type: int > 0
1330 h.default: 24
1331 w.type: int >= 10
1332 w.default: 80
1333  
1334 =item -o[ut][file] <file>
1335  
1336 Specify output file
1337  
1338 =for Euclid:
1339 file.type: writable
1340 file.default: '-'
1341  
1342 =back
1343  
1344 =head1 OPTIONS
1345  
1346 =over
1347  
1348 =item -i
1349  
1350 Specify interactive simulation
1351  
1352 =item -l[[en][gth]] <l>
1353  
1354 Length of simulation. The default is l.default
1355  
1356 =for Euclid:
1357 l.type: int > 0
1358 l.default: 99
1359  
1360 =item --debug [<log_level>]
1361  
1362 Set the log level. Default is log_level.default but if you provide --debug,
1363 then it is log_level.opt_default.
1364  
1365 =for Euclid:
1366 log_level.type: int
1367 log_level.default: 0
1368 log_level.opt_default: 1
1369  
1370 =item --version
1371  
1372 =item --usage
1373  
1374 =item --help
1375  
1376 =item --man
1377  
1378 Print the usual program information
1379  
1380 =back
1381  
1382 Remainder of documentation starts here...
1383  
1384 =head1 AUTHOR
1385  
1386 Damian Conway (DCONWAY@CPAN.org)
1387  
1388 =head1 BUGS
1389  
1390 There are undoubtedly serious bugs lurking somewhere in this code.
1391 Bug reports and other feedback are most welcome.
1392  
1393 =head1 COPYRIGHT
1394  
1395 Copyright (c) 2005, Damian Conway. All Rights Reserved.
1396 This module is free software. It may be used, redistributed
1397 and/or modified under the terms of the Perl Artistic License
1398 (see http://www.perl.com/perl/misc/Artistic.html)
1399  
1400  
1401 =head1 DESCRIPTION
1402  
1403 Getopt::Euclid uses your program's own POD documentation to create a powerful
1404 command-line argument parser. This ensures that your program's documented interface
1405 and its actual interface always agree.
1406  
1407 The created command-line argument parser includes many features such as argument
1408 type checking, required arguments, exclusive arguments, optional arguments with
1409 default values, automatic usage message, ...
1410  
1411 To use the module, simply write the following at the top of your program:
1412  
1413 use Getopt::Euclid;
1414  
1415 This will cause Getopt::Euclid to be require'd and its import method will be
1416 called. It is important that the import method be allowed to run, so do not
1417 invoke Getopt::Euclid in the following manner:
1418  
1419 # Will not work
1420 use Getopt::Euclid ();
1421  
1422 When the module is loaded within a regular Perl program, it will:
1423  
1424 =over
1425  
1426 =item 1.
1427  
1428 locate any POD in the same *.pl file or its associated *.pod file.
1429  
1430 =item 2.
1431  
1432 extract information from that POD, most especially from
1433 the C<=head1 REQUIRED ARGUMENTS> and C<=head1 OPTIONS> sections,
1434  
1435 =item 3.
1436  
1437 build a parser that parses the arguments and options the POD specifies,
1438  
1439 =item 4.
1440  
1441 remove the command-line arguments from C<@ARGV> and parse them, and
1442  
1443 =item 5.
1444  
1445 put the results in the global C<%ARGV> variable (or into specifically named
1446 optional variables, if you request that -- see L<Exporting option variables>).
1447  
1448 =back
1449  
1450 As a special case, if the module is loaded within some other module
1451 (i.e. from within a C<.pm> file), it still locates and extracts POD
1452 information, but instead of parsing C<@ARGV> immediately, it caches that
1453 information and installs an C<import()> subroutine in the caller module.
1454 This new C<import()> acts just like Getopt::Euclid's own import, except
1455 that it adds the POD from the caller module to the POD of the callee.
1456  
1457 All of which just means you can put some or all of your CLI specification
1458 in a module, rather than in the application's source file.
1459 See L<Module interface> for more details.
1460  
1461 =head1 INTERFACE
1462  
1463 =head2 Program interface
1464  
1465 You write:
1466  
1467 use Getopt::Euclid;
1468  
1469 and your command-line is parsed automagically.
1470  
1471 =head2 Module interface
1472  
1473 =over
1474  
1475 =item import()
1476  
1477 You write:
1478  
1479 use Getopt::Euclid;
1480  
1481 and your module will then act just like Getopt::Euclid (i.e. you can use
1482 your module I<instead> of Getopt::Euclid>, except that your module's POD
1483 will also be prepended to the POD of any module that loads yours. In
1484 other words, you can use Getopt::Euclid in a module to create a standard
1485 set of CLI arguments, which can then be added to any application simply
1486 by loading your module.
1487  
1488 To accomplish this trick Getopt::Euclid installs an C<import()>
1489 subroutine in your module. If your module already has an C<import()>
1490 subroutine defined, terrible things happen. So do not do that.
1491  
1492 You may also short-circuit the import method within your calling program to
1493 have the POD from several modules included for argument parsing.
1494  
1495 use Module1::Getopt (); # No argument parsing
1496 use Module2::Getopt (); # No argument parsing
1497 use Getopt::Euclid; # Arguments parsed
1498  
1499 =item process_args()
1500  
1501 Alternatively, to parse arguments from a source different from C<@ARGV>, use the
1502 C<process_args()> subroutine.
1503  
1504 use Getopt::Euclid qw(:defer);
1505 my @args = ( '-in', 'file.txt', '-out', 'results.txt' );
1506 Getopt::Euclid->process_args(\@args);
1507  
1508 If you want to use the :minimal or :vars mode in this type of scenario, you can
1509 pass extra options to C<process_args()>:
1510  
1511 use Getopt::Euclid qw(:defer);
1512 my @args = ( '-in', 'file.txt', '-out', 'results.txt' );
1513 Getopt::Euclid->process_args(\@args, {-minimal => 1, -vars => 'prefix_'});
1514  
1515 This is particularly when you plan on processing POD manually.
1516  
1517 =item process_pods()
1518  
1519 Similarly, to parse argument specifications from a source different than the
1520 current script (and its dependencies), use the C<process_pods()> subroutine.
1521  
1522 use Getopt::Euclid ();
1523 my @pods = ( 'script.pl', 'Module.pm' );
1524 $Getopt::Euclid::MAN = Getopt::Euclid->process_pods(\@pods, {-strict => 1});
1525 my @args = ( '-in', 'file.txt', '-out', 'results.txt' );
1526 Getopt::Euclid->process_args(\@args);
1527  
1528 By default, this method will look for .pod files associated with the given .pl
1529 and .pm files and use these .pod files preferentially when available. Set
1530 -strict to 1 to only use the given files.
1531  
1532 =back
1533  
1534 =head2 POD interface
1535  
1536 This is where all the action is. POD markup can be placed in a .pod file that
1537 has the same prefix as the corresponding Perl file. Alternatively, POD can be
1538 inserted anywhere in the Perl code, but is typically added either after an
1539 __END__ statement (like in the L<SYNOPSIS>), or interspersed in the code:
↑ Summary