Framework/Feature/Args.pm

filter: Statementstmt 93.3% 324 / 347 Branchbran 80.3% 106 / 132 Conditioncond 80.3% 49 / 61 MC/DCmcdc 62.1% 23 / 37 Subroutinesub 100% 21 / 21 Podpod 100% 13 / 13 totaltotal 87.7% 536 / 611 CC 104 SCAR 30.8
CC
104
Cov
89%
check_args
46.6
_process_argv
15.3
_process_arg_spec
13.7
CRAP 21.8
« Framework/Base.pm ↑ Summary Framework/Feature/Run.pm »
1 package App::Framework::Feature::Args ;
2  
3 =head1 NAME
4  
5 App::Framework::Feature::Args - Handle application command line arguments
6  
7 =head1 SYNOPSIS
8  
9 # Args are loaded by default as if the script contained:
10 use App::Framework '+Args' ;
11
12 # Alternatives...
13
14 # Open no file handles
15 use App::Framework '+Args(open=none)' ;
16
17 # Open only input file handles
18 use App::Framework '+Args(open=in)' ;
19
20 # Open only output file handles
21 use App::Framework '+Args(open=out)' ;
22
23 # Open all file handles (the default)
24 use App::Framework '+Args(open=all)' ;
25  
26  
27 =head1 DESCRIPTION
28  
29 Args feature that provides command line arguments handling.
30  
31 Arguments are defined once in a text format and this text format generates
32 both the command line arguments data, but also the man pages, help text etc.
33  
34 =head2 Argument Definition
35  
36 Arguments are specified in the application __DATA__ section in the format:
37  
38 * <name>=<specification> <Summary> <optional default setting>
39
40 <Description>
41  
42 The parts of the specification are defined below.
43  
44 =head3 name
45  
46 The name defines the name of the key to use to access the argument value in the arguments hash. The application framework
47 passes a reference to the argument hash as the third parameter to the application subroutine B<app> (see L</Script Usage>)
48  
49 =head3 specification
50  
51 The specification is in the format:
52  
53 [ <direction> ] [ <binary> ] <type> [ <multiple> ]
54  
55 The optional I<direction> is only valid for file or directory types. For a file or directory types, if no direction is specified then
56 it is assumed to be input. Direction can be one of:
57  
58 =over 4
59  
60 =item <
61  
62 An input file or directory
63  
64 =item >
65  
66 An output file or directory
67  
68 =item >>
69  
70 An output appended file
71  
72 =back
73  
74 An optional 'b' after the direction specifies that the file is binary mode (only used when the type is file).
75  
76 The B<type> must be specified and may be one of:
77  
78 =over 4
79  
80 =item f
81  
82 A file
83  
84 =item d
85  
86 A directory
87  
88 =item s
89  
90 Any string
91  
92 =back
93  
94 Additionally, an optional multiple can be specified. If used, this can only be specified on the last argument. When it is used, this tells the
95 application framework to use the last argument as an ARRAY, pushing all subsequent specified arguments onto this. Accessing the argument
96 in the script returns the ARRAY ref containing all of the command line argument values.
97  
98 Multiple can be:
99  
100 =over 4
101  
102 =item '@'
103  
104 One or more items
105  
106 =item '*'
107  
108 Zero or more items. There is also a special case (the real reason for *) where the argument specification is of the form '<f*' (input file multiple). Here, if the script user does not
109 specify any arguments on the command line for this argument then the framework opens STDIN and provides it as a file handle.
110  
111 =back
112  
113  
114 =head3 summary
115  
116 The summary is a simple line of text used to summarise the argument. It is used in the man pages in 'usage' mode.
117  
118 =head3 default
119  
120 Defaults values are optional. If they are defined, they are in the format:
121  
122 [default=<value>]
123  
124 When a default is defined, if the user does not specify a value for an argument then that argument takes on the defualt value.
125  
126 Also, all subsequent arguments must also be defined as optional.
127  
128 =head3 description
129  
130 The summary is multiple lines of text used to fully describe the option. It is used in the man pages in 'man' mode.
131  
132 =head2 Feature Options
133  
134 The Args feature allows control over how it opens files. By default, any input or output file definitions also create equivalent file handles
135 (the files being opened for read/write automatically). These file handles are made available only in the arguments HASH. The key name for the handle
136 being the name of the argument with the suffix '_fh'.
137  
138 For example, the following definition:
139  
140 [ARGS]
141
142 * file=f Input file
143
144 A simple input directory name (directory must exist)
145
146 * out=>f Output file (file will be created)
147
148 An output filename
149  
150 And the command line arguments:
151  
152 infile.txt outfile.txt
153  
154 Results in the arguments HASH:
155  
156 'file' => 'infile.txt'
157 'out' => 'outfile.txt'
158 'file_fh' => <file handle of 'infile.txt'>
159 'out_fh' => <file handle of 'outfile.txt'>
160  
161 If this behaviour is not required, then you can get the framework to open just input files, output files, or none by using the 'open' option.
162  
163 Specify this in the App::Framework 'use' line as an argument to the Args feature:
164  
165 # Open no file handles
166 use App::Framework '+Args(open=none)' ;
167
168 # Open only input file handles
169 use App::Framework '+Args(open=in)' ;
170
171 # Open only output file handles
172 use App::Framework '+Args(open=out)' ;
173
174 # Open all file handles (the default)
175 use App::Framework '+Args(open=all)' ;
176  
177 =head2 Variable Expansion
178  
179 Argument values can contain variables, defined using the standard Perl format:
180  
181 $<name>
182 ${<name>}
183  
184 When the argument is used, the variable is expanded and replaced with a suitable value. The value will be looked up from a variety of possible sources:
185 object fields (where the variable name matches the field name) or environment variables.
186  
187 The variable name is looked up in the following order, the first value found with a matching name is used:
188  
189 =over 4
190  
191 =item *
192  
193 Argument names - the values of any other arguments may be used as variables in arguments
194  
195 =item *
196  
197 Option names - the values of any command line options may be used as variables in arguments
198  
199 =item *
200  
201 Application fields - any fields of the $app object may be used as variables
202  
203 =item *
204  
205 Environment variables - if no application fields match the variable name, then the environment variables are used
206  
207 =back
208  
209  
210  
211 =head2 Script Usage
212  
213 The application framework passes a reference to the argument HASH as the third parameter to the application subroutine B<app>. Alternatively,
214 the script can call the app object's alias to the args accessor, i.e. the B<args> method which returns the arguments value list. Yet another
215 alternative is to call the args accessor method directly. These alternatives are shown below:
216  
217  
218 sub app
219 {
220 my ($app, $opts_href, $args_href) = @_ ;
221
222 # use parameter
223 my $infile = $args_href->{infile}
224
225 # access alias
226 my @args = $app->args() ;
227 $infile = $args[0] ;
228
229 # access alias
230 @args = $app->Args() ;
231 $infile = $args[0] ;
232  
233 ($infile) = $app->args('infile') ;
234
235 # feature object
236 @args = $app->feature('Args')->args() ;
237 $infile = $args[0] ;
238 }
239  
240  
241  
242 =head2 Examples
243  
244 With the following script definition:
245  
246 [ARGS]
247
248 * file=f Input file
249
250 A simple input file name (file must exist)
251
252 * dir=d Input directory
253
254 A simple input directory name (directory must exist)
255
256 * out=>f Output file (file will be created)
257
258 An output filename
259
260 * outdir=>d Output directory
261
262 An output directory name (path will be created)
263
264 * append=>>f Output file append
265
266 An output filename (an existing file will be appended; otherwise file will be created)
267
268 * array=<f* All other args are input files
269
270 Any other command line arguments will be pushced on to this array.
271  
272 The following command line arguments:
273  
274 infile.txt indir outfile.txt odir append.txt file1.txt file2.txt file3.txt
275  
276 Give the arguments HASH values:
277  
278 'file' => 'infile.txt'
279 'file_fh' => <infile.txt file handle>
280 'dir' => 'indir'
281 'out' => 'outfile.txt'
282 'out_fh' => <outfile.txt file handle>
283 'outdir' => 'odir'
284 'append' => 'append.txt'
285 'append_fh'=> <append.txt file handle>
286 'array' => [
287 'file1.txt'
288 'file2.txt'
289 'file3.txt'
290 ]
291 'array_fh' => [
292 <file1.txt file handle>
293 <file2.txt file handle>
294 <file3.txt file handle>
295 ]
296  
297  
298 An example script that uses the I<multiple> arguments, along with the default 'open' behaviour is:
299  
300 sub app
301 {
302 my ($app, $opts_href, $args_href) = @_ ;
303
304 foreach my $fh (@{$args_href->{array_fh}})
305 {
306 while (my $data = <$fh>)
307 {
308 # do something ...
309 }
310 }
311 }
312
313 __DATA__
314 [ARGS]
315 * array=f@ Input file
316
317  
318 This script can then be called with one or more filenames and each file will be processed. Or it can be called with no
319 filenames and STDIN will then be used.
320  
321  
322  
323 =cut
324  
325 31 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
326 31 ▶use Carp ;
Subroutine BEGIN: called CC=1 SCAR=0.0
327  
328 31 our $VERSION = "1.007" ;
329  
330 #============================================================================================
331 # USES
332 #============================================================================================
333 31 ▶use App::Framework::Feature ;
Subroutine BEGIN: called CC=1 SCAR=0.0
334  
335 #============================================================================================
336 # OBJECT HIERARCHY
337 #============================================================================================
338 31 our @ISA = qw(App::Framework::Feature) ;
339  
340 #============================================================================================
341 # GLOBALS
342 #============================================================================================
343  
344  
345 =head2 FIELDS
346  
347 The following fields should be defined either in the call to 'new()', as part of a 'set()' call, or called by their accessor method
348 (which is the same name as the field):
349  
350  
351 =over 4
352  
353 =item B<user_args> - list of argument definitions
354  
355 Created by the object. Once all of the arguments have been created, this field contains an ARRAY ref to the list
356 of all of the specified option specifications (see method L</append_args>).
357  
358 =item B<arg_names> - list of argument names
359  
360 Created by the object. Once all of the arguments have been created, this field contains an ARRAY ref to the list
361 of all of the argument names.
362  
363 =item B<argv> - list of command line arguments
364  
365 Reference to @ARGV array.
366  
367 =back
368  
369 =cut
370  
371 31 my %FIELDS = (
372 ## User specified
373 'user_args' => [], # User-specified args
374 'argv' => [], # ref to @ARGV
375 'arg_names' => [], # List of arg names
376  
377 ## Created
378 '_arg_list' => [], # Final ARRAY ref of args - EXCLUDING any opened files
379 '_args' => {}, # Final args HASH - key = arg name; value = arg value
380 '_arg_names_hash' => {}, # List of HASHes, each hash contains details of an arg
381 '_fh_list' => [], # List of any opened file handles
382 ) ;
383  
384 #============================================================================================
385  
386 =head2 CONSTRUCTOR
387  
388 =over 4
389  
390 =cut
391  
392 #============================================================================================
393  
394  
395 =item B< new([%args]) >
396  
397 Create a new Args.
398  
399 The %args are specified as they would be in the B<set> method (see L</Fields>).
400  
401 =cut
402  
403 sub new
404 35 ▶{
Subroutine new: called CC=2 SCAR=7.1
Pod documented
405 35 my ($obj, %args) = @_ ;
406  
407 35 ▶ my $class = ref($obj) || $obj ;
Condition33%1/3
ref $obj || $obj
l!l&&r!l&&!r
0350
MC/DC0%0/2
ref $obj || $obj
ref $obj $obj
Truth table33%1/3
A || B
A= ref $objB= $obj
ABresult
1X1
011
000
408  
409 # Create object
410 35 my $this = $class->SUPER::new(%args,
411 ) ;
412  
413  
414 35 my $args = $this->feature_args() ;
415 35 $this->_dbg_prt(["NEW: feature args=", $args]) ;
416 35 $this->_dbg_prt(["OBJ=", $this]) ;
417
418 35 return($this) ;
419 }
420  
421  
422  
423 #============================================================================================
424  
425 =back
426  
427 =head2 CLASS METHODS
428  
429 =over 4
430  
431 =cut
432  
433 #============================================================================================
434  
435  
436 #-----------------------------------------------------------------------------
437  
438 =item B< init_class([%args]) >
439  
440 Initialises the Args object class variables.
441  
442 =cut
443  
444 sub init_class
445 35 ▶{
Subroutine init_class: called CC=1 SCAR=0.0
Pod documented
446 35 my $class = shift ;
447 35 my (%args) = @_ ;
448  
449 # Add extra fields
450 35 $class->add_fields(\%FIELDS, \%args) ;
451  
452 # init class
453 35 $class->SUPER::init_class(%args) ;
454  
455 }
456  
457 #============================================================================================
458  
459 =back
460  
461 =head2 OBJECT METHODS
462  
463 =over 4
464  
465 =cut
466  
467 #============================================================================================
468  
469 #----------------------------------------------------------------------------
470  
471 =item B< args([$name]) >
472  
473 When called with no arguments, returns the full arguments list (same as call to method L</arg_list>).
474  
475 When a name (or list of names) is specified: if the named arguments hash is available, returns the
476 argument values as a list; otherwise just returns the complete args list.
477  
478 =cut
479  
480 sub args
481 5 ▶{
Subroutine args: called CC=5 SCAR=19.6
Pod documented
482 5 my $this = shift ;
483 5 my (@names) = @_ ;
484
485 5 my $args_href = $this->_args() ;
486 5 my @args = $this->arg_list ;
487  
488 5 ▶ if (keys %$args_href)
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$args_href) 5 0 5
489 {
490 # do named args
491 5 ▶ if (@names)
Branch: 1 branch
BranchTrueFalseTotal
if (@names) 0 5 5
492 {
493 0 @args = () ;
494 0 foreach my $name (@names)
495 {
496 0 ▶ push @args, $args_href->{$name} if exists($args_href->{$name}) ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $args_href->{$name} 0 0 0
497 }
498 }
499 }
500
501 5 return @args ;
502 }
503  
504 #----------------------------------------------------------------------------
505  
506 =item B< Args([$name]) >
507  
508 Alias to L</args>
509  
510 =cut
511  
512 31 *Args = \&args ;
513  
514  
515 #----------------------------------------------------------------------------
516  
517 =item B< arg_list() >
518  
519 Returns the full arguments list. This is the list of arguments, as specified
520 at the command line by the user.
521  
522 =cut
523  
524 sub arg_list
525 49 ▶{
Subroutine arg_list: called CC=1 SCAR=0.0
Pod documented
526 49 my $this = shift ;
527  
528 49 my $args_aref = $this->_arg_list() ;
529  
530 49 return @$args_aref ;
531 }
532  
533 #----------------------------------------------------------------------------
534  
535 =item B< arg_hash() >
536  
537 Returns the full arguments hash.
538  
539 =cut
540  
541 sub arg_hash
542 118 ▶{
Subroutine arg_hash: called CC=1 SCAR=0.0
Pod documented
543 118 my $this = shift ;
544  
545 118 my $args_href = $this->_args() ;
546 118 return %$args_href ;
547 }
548  
549  
550 #----------------------------------------------------------------------------
551  
552 =item B<append_args($args_aref)>
553  
554 Append the options listed in the ARRAY ref I<$args_aref> to the current args list
555  
556 =cut
557  
558 sub append_args
559 17 ▶{
Subroutine append_args: called CC=1 SCAR=0.0
Pod documented
560 17 my $this = shift ;
561 17 my ($args_aref) = @_ ;
562  
563 17 $this->_dbg_prt(["Args: append_args()\n"]) ;
564  
565 17 my @combined_args = (@{$this->user_args}, @$args_aref) ;
566 17 $this->user_args(\@combined_args) ;
567  
568 17 $this->_dbg_prt(["Options: append_args() new=", $args_aref], 2) ;
569 17 $this->_dbg_prt(["combined=", \@combined_args], 2) ;
570  
571 ## Build new set of args
572 17 $this->update() ;
573
574 17 return @combined_args ;
575 }
576  
577 #----------------------------------------------------------------------------
578  
579 =item B< update() >
580  
581 Take the list of args (created by calls to L</append_args>) and process the list into the
582 final args list.
583  
584 Each entry in the ARRAY is an ARRAY ref containing:
585  
586 [ <arg spec>, <arg summary>, <arg description>, <arg default> ]
587  
588 Returns the hash of args/values
589  
590 =cut
591  
592 sub update
593 17 ▶{
Subroutine update: called CC=9 SCAR=22.1
Pod documented
594 17 my $this = shift ;
595  
596 17 $this->_dbg_prt(["Args: update()\n"]) ;
597  
598 ## get user settings
599 17 my $args_aref = $this->user_args ;
600  
601 ## set up internals
602
603 # rebuild these
604 17 my $args_href = {} ;
605  
606 # keep full details
607 17 my $args_names_href = {} ;
608  
609 ## fill args_href, get_args_aref
610 17 my $args_list = [] ;
611
612 # Cycle through
613 17 my $optional = 0 ;
614 17 my $last_dest_type ;
615 17 foreach my $arg_entry_aref (@$args_aref)
616 {
617 36 $this->_dbg_prt(["Arg entry=", $arg_entry_aref], 2) ;
618  
619 36 my ($arg_spec, $summary, $description, $default_val) = @$arg_entry_aref ;
620
621 ## Process the arg spec
622 36 my ($name, $pod_spec, $dest_type, $arg_type, $arg_direction, $arg_optional, $arg_append, $arg_mode) ;
623 36 ($name, $arg_spec, $pod_spec, $dest_type, $arg_type, $arg_direction, $arg_optional, $arg_append, $arg_mode) =
624 $this->_process_arg_spec($arg_spec) ;
625  
626 36 ▶ if ($last_dest_type)
Branch: 1 branch
BranchTrueFalseTotal
if ($last_dest_type) 0 36 36
627 {
628 0 $this->throw_fatal("Application definition error: arg $name defined after $last_dest_type defined as array") ;
629 }
630 36 ▶ $last_dest_type = $name if $dest_type ;
Branch: 1 branch
BranchTrueFalseTotal
if $dest_type 11 25 36
631
632 # Set default if required
633 36 ▶ $args_href->{$name} = $default_val if (defined($default_val)) ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $default_val 11 25 36
634  
635 # See if optional
636 36 ▶ $arg_optional++ if defined($default_val) ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $default_val 11 25 36
637 36 ▶ if ($optional && !$arg_optional)
Branch: 1 branch
BranchTrueFalseTotal
if ($optional and not $arg_optional) 0 36 36
Condition66%2/3
$optional and not $arg_optional
!ll&&!rl&&r
2970
MC/DC0%0/2
$optional and not $arg_optional
$optional not $arg_optional
Truth table66%2/3
A and not(B)
A= $optionalB= not $arg_optional
ABresult
0X0
100
111
638 {
639 0 $this->throw_fatal("Application definition error: arg $name should be optional since previous arg is") ;
640 }
641 36 ▶ $optional ||= $arg_optional ;
Condition100%3/3
$optional ||= $arg_optional
l!l&&r!l&&!r
7425
MC/DC100%2/2
$optional ||= $arg_optional
$optional $arg_optional
Truth table100%3/3
A ||= B
A= $optionalB= $arg_optional
ABresult
1X1
011
000
642  
643 36 $this->_dbg_prt(["Args: update() - arg_optional=$arg_optional optional=$optional\n"]) ;
644
645 # Create full entry
646 36 my $href = $this->_new_arg_entry($name, $arg_spec, $summary, $description, $default_val, $pod_spec, $arg_type, $arg_direction, $dest_type, $optional, $arg_append, $arg_mode) ;
647 36 $args_names_href->{$name} = $href ;
648  
649 36 $this->_dbg_prt(["Arg $name HASH=", $href], 2) ;
650  
651 # save arg in specified order
652 36 push @$args_list, $name ;
653 }
654  
655 17 $this->_dbg_prt(["update() - END\n"], 2) ;
656  
657 ## Save
658 17 $this->arg_names($args_list) ;
659 17 $this->_args($args_href) ;
660 17 $this->_arg_names_hash($args_names_href) ;
661  
662 17 return %$args_href ;
663 }
664  
665  
666  
667 #-----------------------------------------------------------------------------
668  
669 =item B< check_args() >
670  
671 At start of application, check the arguments for valid files etc.
672  
673 =cut
674  
675 sub check_args
676 39 ▶{
Subroutine check_args: called CC=43 SCAR=38.4
Pod documented
677 39 my $this = shift ;
678  
679 # specified args
680 39 my $argv_aref = $this->argv ;
681 # values
682 39 my $args_href = $this->_args() ;
683 # details
684 39 my $arg_names_href = $this->_arg_names_hash() ;
685  
686 # File handles
687 39 my $fh_aref = $this->_fh_list() ;
688  
689 39 $this->_dbg_prt(["check_args() Names=", $arg_names_href, "Values=", $args_href, "Name list=", $this->arg_names()], 2) ;
690
691
692 ## Check feature settings
693 39 my ($open_out, $open_in) = (1, 1) ;
694 39 my $feature_args = $this->feature_args ;
695 39 ▶ if ($feature_args =~ m/open\s*=\s*(out|in|no)/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($feature_args =~ /open\s*=\s*(out|in|no)/i) 9 30 39
696 {
697 9 ▶ if ($1 =~ /out/i)
Branch: 2 branches
BranchTrueFalseTotal
if ($1 =~ /out/i) { } 0 9 9
elsif ($1 =~ /in/i) { } 0 9 9
698 {
699 0 ++$open_out ;
700 }
701 elsif ($1 =~ /in/i)
702 {
703 0 ++$open_in ;
704 }
705 else
706 {
707 # none
708 9 $open_in = 0;
709 9 $open_out = 0;
710 }
711 }
712 # elsif ($feature_args =~ m/open/i)
713 # {
714 # ## open both
715 # ++$open_out ;
716 # ++$open_in ;
717 # }
718
719 ## Process each arg checking that it's been specified (where required)
720 39 my $idx = -1 ;
721 39 my $arg_list = $this->arg_names() ;
722 39 foreach my $name (@$arg_list)
723 {
724 # # skip if optional
725 # next if $arg_names_href->{$name}{'optional'} ;
726  
727 # create file handle name
728 50 my $fh_name = "${name}_fh";
729  
730 50 my $type = "" ;
731 50 ▶ if ($arg_names_href->{$name}{'type'} eq 'f')
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_names_href->{$name}{"type"} eq "f") 36 14 50
732 {
733 36 $type = "file " ;
734 }
735 50 ▶ if ($arg_names_href->{$name}{'type'} eq 'd')
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_names_href->{$name}{"type"} eq "d") 9 41 50
736 {
737 9 $type = "directory " ;
738 }
739  
740 50 my $value = $args_href->{$name} ;
741 50 my @values = ($value) ;
742  
743 ## Special handling for @* spec
744 50 ▶ if ($arg_names_href->{$name}{'dest_type'})
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_names_href->{$name}{"dest_type"}) 17 33 50
745 {
746 17 $this->_dbg_prt([" + + special dest type\n"], 2) ;
747 17 ▶ if (defined($value))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 17 0 17
748 {
749 17 @values = @$value ;
750 }
751
752 17 ▶ push @values, '' unless @values ;
Branch: 1 branch
BranchTrueFalseTotal
unless @values 8 9 17
753  
754 17 ▶ if ($open_in && ($arg_names_href->{$name}{'type'} eq 'f'))
Branch: 1 branch
BranchTrueFalseTotal
if ($open_in and $arg_names_href->{$name}{"type"} eq "f") 12 5 17
Condition66%2/3
$open_in and $arg_names_href->{$name}{"type"} eq "f"
!ll&&!rl&&r
5012
MC/DC50%1/2
$open_in and $arg_names_href->{$name}{"type"} eq "f"
$open_in $arg_names_href->{$name}{"type"} eq "f"
Truth table66%2/3
A and B
A= $open_inB= $arg_names_href->{$name}{"type"} eq "f"
ABresult
0X0
100
111
755 {
756 12 $args_href->{$fh_name} = [] ;
757 }
758 }
759  
760 50 $this->_dbg_prt([" + values (@values) [".scalar(@values)."]\n"], 2) ;
761  
762 ## Very special case of * spec with no args - set fh to STDIN if required
763 50 ▶ if ($arg_names_href->{$name}{'dest_type'} eq '*')
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_names_href->{$name}{"dest_type"} eq "*") 13 37 50
764 {
765 13 ▶ if (!defined($value) || scalar(@$value)==0)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value or scalar @$value == 0) 7 6 13
Condition66%2/3
not defined $value or scalar @$value == 0
l!l&&r!l&&!r
076
MC/DC50%1/2
not defined $value or scalar @$value == 0
not defined $value scalar @$value == 0
Truth table66%2/3
not(A) or B
A= not defined $valueB= scalar @$value == 0
ABresult
1X1
011
000
766 {
767 7 ▶ if ($open_in && ($arg_names_href->{$name}{'type'} eq 'f'))
Branch: 1 branch
BranchTrueFalseTotal
if ($open_in and $arg_names_href->{$name}{"type"} eq "f") 6 1 7
Condition66%2/3
$open_in and $arg_names_href->{$name}{"type"} eq "f"
!ll&&!rl&&r
106
MC/DC50%1/2
$open_in and $arg_names_href->{$name}{"type"} eq "f"
$open_in $arg_names_href->{$name}{"type"} eq "f"
Truth table66%2/3
A and B
A= $open_inB= $arg_names_href->{$name}{"type"} eq "f"
ABresult
0X0
100
111
768 {
769 # Create new entry
770 6 my $href = $this->_new_arg_entry($fh_name) ;
771 6 $arg_names_href->{$fh_name} = $href ;
772
773 # set value
774 6 $args_href->{$fh_name} = [\*STDIN] ;
775  
776 6 ▶ $args_href->{$name} ||= [] ;
Condition50%1/2
$args_href->{$name} ||= []
l!l
60
MC/DC0%0/1
$args_href->{$name} ||= []
$args_href->{$name}
Truth table50%1/2
A
A= $args_href->{$name}
Aresult
11
00
777 6 push @{$args_href->{$name}}, 'STDIN' ;
778
779 6 next ;
780 }
781 }
782 }
783
784
785 ## Check all of the values
786 44 foreach my $val (@values)
787 {
788
789 54 ++$idx ;
790 54 my $arg_optional = $arg_names_href->{$name}{'optional'} ;
791
792 54 $this->_dbg_prt([" + checking $name value=$val, type=$type, optional=$arg_optional ..\n"], 2) ;
793
794 # First check that an arg has been specified
795 54 ▶ if ($idx >= scalar(@$argv_aref))
Branch: 1 branch
BranchTrueFalseTotal
if ($idx >= scalar @$argv_aref) 13 41 54
796 {
797 # Ignore if * type -OR- optional
798 13 ▶ if ( ($arg_names_href->{$name}{'dest_type'} ne '*') && (! $arg_optional) )
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_names_href->{$name}{"dest_type"} ne "*" and not $arg_optional) 2 11 13
Condition100%3/3
$arg_names_href->{$name}{"dest_type"} ne "*" and not $arg_optional
!ll&&!rl&&r
1102
MC/DC100%2/2
$arg_names_href->{$name}{"dest_type"} ne "*" and not $arg_optional
$arg_names_href->{$name}{"dest_type"} ne "*" not $arg_optional
Truth table100%3/3
A and not(B)
A= $arg_names_href->{$name}{"dest_type"} ne "*"B= not $arg_optional
ABresult
0X0
100
111
799 {
800 2 $this->_complain_usage_exit("Must specify input $type\"$name\"") ;
801 }
802 }
803
804 52 ▶ next unless $val ;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 1 51 52
805
806 ## Input
807 51 ▶ if ($arg_names_href->{$name}{'direction'} eq 'i')
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_names_href->{$name}{"direction"} eq "i") 42 9 51
808 {
809 42 $this->_dbg_prt([" + Check $val for existence\n"], 2) ;
810
811 ## skip checks if optional and no value specified (i.e. do the check if a default is specified)
812 42 ▶ if (!$arg_optional && $val)
Branch: 1 branch
BranchTrueFalseTotal
if (not $arg_optional and $val) { } 34 8 42
Condition66%2/3
not $arg_optional and $val
!ll&&!rl&&r
8034
MC/DC50%1/2
not $arg_optional and $val
not $arg_optional $val
Truth table66%2/3
not(A) and B
A= not $arg_optionalB= $val
ABresult
0X0
100
111
813 {
814 # File check
815 34 ▶ if ( ($arg_names_href->{$name}{'type'} eq 'f') && (! -f $val) )
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_names_href->{$name}{"type"} eq "f" and not -f $val) 3 31 34
Condition100%3/3
$arg_names_href->{$name}{"type"} eq "f" and not -f $val
!ll&&!rl&&r
5263
MC/DC100%2/2
$arg_names_href->{$name}{"type"} eq "f" and not -f $val
$arg_names_href->{$name}{"type"} eq "f" not -f $val
Truth table100%3/3
A and not(B)
A= $arg_names_href->{$name}{"type"} eq "f"B= not -f $val
ABresult
0X0
100
111
816 {
817 3 $this->_complain_usage_exit("Must specify a valid input filename for \"$name\"") ;
818 }
819 # Directory check
820 31 ▶ if ( ($arg_names_href->{$name}{'type'} eq 'd') && (! -d $val) )
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_names_href->{$name}{"type"} eq "d" and not -d $val) 1 30 31
Condition100%3/3
$arg_names_href->{$name}{"type"} eq "d" and not -d $val
!ll&&!rl&&r
2641
MC/DC100%2/2
$arg_names_href->{$name}{"type"} eq "d" and not -d $val
$arg_names_href->{$name}{"type"} eq "d" not -d $val
Truth table100%3/3
A and not(B)
A= $arg_names_href->{$name}{"type"} eq "d"B= not -d $val
ABresult
0X0
100
111
821 {
822 1 $this->_complain_usage_exit("Must specify a valid input directory for \"$name\"") ;
823 }
824 }
825 else
826 {
827 8 $this->_dbg_prt([" + Skipped checks opt=$arg_optional val=$val bool=".."...\n"], 2) ;
828
829 }
830
831
832 ## File open
833 38 ▶ if ($open_in && ($arg_names_href->{$name}{'type'} eq 'f'))
Branch: 1 branch
BranchTrueFalseTotal
if ($open_in and $arg_names_href->{$name}{"type"} eq "f") 10 28 38
Condition100%3/3
$open_in and $arg_names_href->{$name}{"type"} eq "f"
!ll&&!rl&&r
21710
MC/DC100%2/2
$open_in and $arg_names_href->{$name}{"type"} eq "f"
$open_in $arg_names_href->{$name}{"type"} eq "f"
Truth table100%3/3
A and B
A= $open_inB= $arg_names_href->{$name}{"type"} eq "f"
ABresult
0X0
100
111
834 {
835 10 open my $fh, "<$val" ;
836 10 ▶ if ($fh)
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) { } 10 0 10
837 {
838 10 push @$fh_aref, $fh ;
839
840 10 ▶ if ($arg_names_href->{$name}{'mode'} eq 'b')
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_names_href->{$name}{"mode"} eq "b") 0 10 10
841 {
842 0 binmode $fh ;
843 }
844
845 # Create new entry
846 10 my $href = $this->_new_arg_entry($fh_name) ;
847 10 $arg_names_href->{$fh_name} = $href ;
848
849 # set value
850 10 ▶ if ($arg_names_href->{$name}{'dest_type'})
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_names_href->{$name}{'dest_type'}) { } 6 4 10
851 {
852 6 ▶ $args_href->{$fh_name} ||= [] ;
Condition50%1/2
$args_href->{$fh_name} ||= []
l!l
60
MC/DC0%0/1
$args_href->{$fh_name} ||= []
$args_href->{$fh_name}
Truth table50%1/2
A
A= $args_href->{$fh_name}
Aresult
11
00
853 6 push @{$args_href->{$fh_name}}, $fh ;
854 }
855 else
856 {
857 4 $args_href->{$fh_name} = $fh ;
858 }
859 }
860 else
861 {
862 0 $this->_complain_usage_exit("Unable to read file \"$val\" : $!") ;
863 }
864 }
865 }
866
867 ## Output
868 47 ▶ if ($open_out)
Branch: 1 branch
BranchTrueFalseTotal
if ($open_out) 23 24 47
869 {
870 23 ▶ if (($arg_names_href->{$name}{'direction'} eq 'o') && ($arg_names_href->{$name}{'type'} eq 'f'))
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_names_href->{$name}{"direction"} eq "o" and $arg_names_href->{$name}{"type"} eq "f") 4 19 23
Condition100%3/3
$arg_names_href->{$name}{"direction"} eq "o" and $arg_names_href->{$name}{"type"} eq "f"
!ll&&!rl&&r
1724
MC/DC100%2/2
$arg_names_href->{$name}{"direction"} eq "o" and $arg_names_href->{$name}{"type"} eq "f"
$arg_names_href->{$name}{"direction"} eq "o" $arg_names_href->{$name}{"type"} eq "f"
Truth table100%3/3
A and B
A= $arg_names_href->{$name}{"direction"} eq "o"B= $arg_names_href->{$name}{"type"} eq "f"
ABresult
0X0
100
111
871 {
872 4 my $mode = '>' ;
873 4 ▶ if ($arg_names_href->{$name}{'append'})
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_names_href->{$name}{"append"}) 2 2 4
874 {
875 2 $mode .= '>' ;
876 }
877
878 4 open my $fh, "$mode$val" ;
879 4 ▶ if ($fh)
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) { } 4 0 4
880 {
881 4 push @$fh_aref, $fh ;
882
883 4 ▶ if ($arg_names_href->{$name}{'mode'} eq 'b')
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_names_href->{$name}{"mode"} eq "b") 0 4 4
884 {
885 0 binmode $fh ;
886 }
887
888 # Create new entry
889 4 my $href = $this->_new_arg_entry($fh_name) ;
890 4 $arg_names_href->{$fh_name} = $href ;
891
892 # set value
893 4 $args_href->{$fh_name} = $fh ;
894 }
895 else
896 {
897 0 ▶ my $md = $arg_names_href->{$name}{'append'} ? 'append' : 'write' ;
Branch: 1 branch
BranchTrueFalseTotal
$arg_names_href->{$name}{'append'} ? : 0 0 0
898
899 0 $this->_complain_usage_exit("Unable to $md file \"$val\" : $!") ;
900 }
901 }
902 }
903 }
904 }
905
906 }
907  
908 #-----------------------------------------------------------------------------
909  
910 =item B< close_args() >
911  
912 If any arguements cause files/devices to be opened, this shuts them down
913  
914 =cut
915  
916 sub close_args
917 33 ▶{
Subroutine close_args: called CC=2 SCAR=6.9
Pod documented
918 33 my $this = shift ;
919  
920 # File handles
921 33 my $fh_aref = $this->_fh_list() ;
922
923 33 foreach my $fh (@$fh_aref)
924 {
925 29 close $fh ;
926 }
927  
928 }
929  
930  
931  
932 #----------------------------------------------------------------------------
933  
934 =item B<get_args()>
935  
936 Finish any args processing and return the arguments list
937  
938 =cut
939  
940 sub get_args
941 41 ▶{
Subroutine get_args: called CC=2 SCAR=6.9
Pod documented
942 41 my $this = shift ;
943  
944 # save @ARGV
945 41 $this->argv(\@ARGV) ;
946 41 my @args = @ARGV ;
947  
948 # Copy values over
949 41 $this->_process_argv() ;
950  
951 41 my %args ;
952
953 41 %args = $this->arg_hash() ;
954 41 $this->_dbg_prt(["Args before expand : hash=", \%args]) ;
955  
956 # Expand the args variables
957 41 $this->_expand_args() ;
958  
959 # Set arg list
960 41 my @arg_array ;
961 41 %args = $this->arg_hash() ;
962 41 my $arg_list = $this->arg_names() ;
963 41 foreach my $name (@$arg_list)
964 {
965 70 push @arg_array, $args{$name} ;
966 }
967 41 $this->_arg_list(\@arg_array) ;
968  
969  
970 # return arglist
971 41 return $this->arg_list ;
972 }
973  
974 #----------------------------------------------------------------------------
975  
976 =item B<arg_entry($arg_name)>
977  
978 Returns the HASH ref of arg if name is found; undef otherwise
979  
980 =cut
981  
982 sub arg_entry
983 109 ▶{
Subroutine arg_entry: called CC=2 SCAR=7.0
Pod documented
984 109 my $this = shift ;
985 109 my ($arg_name) = @_ ;
986  
987 109 my $arg_names_href = $this->_arg_names_hash() ;
988 109 my $arg_href ;
989 109 ▶ if (exists($arg_names_href->{$arg_name}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg_names_href->{$arg_name}) 109 0 109
990 {
991 109 $arg_href = $arg_names_href->{$arg_name} ;
992 }
993 109 return $arg_href ;
994 }
995  
996  
997 #----------------------------------------------------------------------------
998  
999 =item B<args_values_hash()>
1000  
1001 Returns the args values HASH reference.
1002  
1003 =cut
1004  
1005 sub args_values_hash
1006 82 ▶{
Subroutine args_values_hash: called CC=3 SCAR=11.0
Pod documented
1007 82 my $this = shift ;
1008  
1009 82 my $args_href = $this->_args() ;
1010 82 my $args_names_href = $this->_arg_names_hash() ;
1011  
1012 # get args
1013 82 my %values ;
1014 82 foreach my $arg (keys %$args_names_href)
1015 {
1016 150 ▶ $values{$arg} = $args_href->{$arg} if defined($args_href->{$arg}) ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $args_href->{$arg} 146 4 150
1017 }
1018  
1019 82 return \%values ;
1020 }
1021  
1022 #----------------------------------------------------------------------------
1023  
1024 =item B<args_values_set($values_href)>
1025  
1026 Sets the args values based on the values in the HASH reference B<$values_href>.
1027  
1028 =cut
1029  
1030 sub args_values_set
1031 41 ▶{
Subroutine args_values_set: called CC=3 SCAR=11.0
Pod documented
1032 41 my $this = shift ;
1033 41 my ($values_href) = @_ ;
1034  
1035 41 my $args_href = $this->_args() ;
1036 41 my $args_names_href = $this->_arg_names_hash() ;
1037  
1038 ## Update
1039 # foreach my $arg (keys %$args_names_href)
1040 # {
1041 # $args_href->{$arg} = $values_href->{$arg} if defined($args_href->{$arg}) ;
1042 # }
1043  
1044 # Cycle through
1045 41 my $names_aref = $this->arg_names() ;
1046 41 foreach my $arg (@$names_aref)
1047 {
1048 70 ▶ if ( defined($args_href->{$arg}) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args_href->{$arg}) 68 2 70
1049 {
1050 68 my $arg_entry_href = $this->arg_entry($arg) ;
1051
1052 68 $args_href->{$arg} = $values_href->{$arg} ;
1053 68 $arg_entry_href->{'default'} = $values_href->{$arg} ;
1054 }
1055 }
1056 }
1057  
1058 # ============================================================================================
1059 # PRIVATE METHODS
1060 # ============================================================================================
1061  
1062 #----------------------------------------------------------------------------
1063 #
1064 #=item B<_expand_args()>
1065 #
1066 #Expand any variables in the args
1067 #
1068 #=cut
1069 #
1070 sub _expand_args
1071 41 ▶{
Subroutine _expand_args: called CC=6 SCAR=17.9
1072 41 my $this = shift ;
1073  
1074 41 my $args_href = $this->_args() ;
1075 41 my $args_names_href = $this->_arg_names_hash() ;
1076  
1077 # get args
1078 41 my %values ;
1079 41 foreach my $arg (keys %$args_names_href)
1080 {
1081 75 ▶ $values{$arg} = $args_href->{$arg} if defined($args_href->{$arg}) ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $args_href->{$arg} 73 2 75
1082 }
1083  
1084 # get replacement vars
1085 41 my @vars ;
1086 41 my $app = $this->app ;
1087 41 ▶ if ($app)
Branch: 1 branch
BranchTrueFalseTotal
if ($app) 41 0 41
1088 {
1089 41 my %app_vars = $app->vars ;
1090 41 push @vars, \%app_vars ;
1091 41 my %opt_vars = $app->options() ;
1092 41 push @vars, \%opt_vars ;
1093 }
1094 41 push @vars, \%ENV ;
1095
1096 # ## expand
1097 # $this->expand_keys(\%values, \@vars) ;
1098
1099 ## Update
1100 41 foreach my $arg (keys %$args_names_href)
1101 {
1102 75 ▶ $args_href->{$arg} = $values{$arg} if defined($args_href->{$arg}) ;
Branch: 1 branch
BranchTrueFalseTotal
if defined $args_href->{$arg} 73 2 75
1103 }
1104
1105 }
1106  
1107 #----------------------------------------------------------------------------
1108 #
1109 #=item B<_process_argv()>
1110 #
1111 #Processes the @ARGV array
1112 #
1113 #=cut
1114 #
1115 sub _process_argv
1116 41 ▶{
Subroutine _process_argv: called CC=15 SCAR=27.3
1117 41 my $this = shift ;
1118  
1119 41 my $argv_aref = $this->argv() ;
1120 41 my @args = @$argv_aref ;
1121 41 $argv_aref = [] ; # clear our args, rebuild the list as we process them
1122 41 my $idx = 0 ;
1123  
1124 41 $this->_dbg_prt(["_process_argv() : args=", \@args]) ;
1125
1126 # values
1127 41 my $args_href = $this->_args() ;
1128 # details
1129 41 my $args_names_href = $this->_arg_names_hash() ;
1130
1131 41 my $dest_type ;
1132 41 my $arg_list = $this->arg_names() ;
1133 41 foreach my $name (@$arg_list)
1134 {
1135 70 ▶ if ($args_names_href->{$name}{'dest_type'})
Branch: 1 branch
BranchTrueFalseTotal
if ($args_names_href->{$name}{"dest_type"}) 21 49 70
1136 {
1137 # set value
1138 21 $args_href->{$name} = [] ;
1139 }
1140 }
1141
1142 41 foreach my $name (@$arg_list)
1143 {
1144 63 ▶ last unless @args ;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 13 50 63
1145 50 my $arg = shift @args ;
1146
1147 # set value
1148 50 $args_href->{$name} = $arg ;
1149 50 push @$argv_aref, $arg ;
1150
1151 # get this dest type
1152 50 ▶ $dest_type = $name if $args_names_href->{$name}{'dest_type'} ;
Branch: 1 branch
BranchTrueFalseTotal
if $args_names_href->{$name}{"dest_type"} 13 37 50
1153  
1154 50 ++$idx ;
1155 }
1156  
1157 # If last arg specified as ARRAY, then convert value to ARRAY ref
1158 41 ▶ if ($dest_type)
Branch: 1 branch
BranchTrueFalseTotal
if ($dest_type) 13 28 41
1159 {
1160 13 my $arg = $args_href->{$dest_type} ;
1161 13 $args_href->{$dest_type} = [] ;
1162 13 pop @$argv_aref ;
1163  
1164 ## Handle wildcards (mainly to cope with Windoze)
1165 13 ▶ if ($arg =~ m/[\*\?]/)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /[\*\?]/) 1 12 13
1166 {
1167 1 my @files = glob("$arg") ;
1168 1 ▶ if (@files)
Branch: 1 branch
BranchTrueFalseTotal
if (@files) 1 0 1
1169 {
1170 1 push @{$args_href->{$dest_type}}, @files ;
1171 1 push @$argv_aref, @files ;
1172 1 $arg = undef ;
1173 }
1174 }
1175  
1176 13 ▶ if ($arg)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) 12 1 13
1177 {
1178 12 push @{$args_href->{$dest_type}}, $arg ;
1179 12 push @$argv_aref, $arg ;
1180 }
1181
1182 }
1183  
1184 41 $this->_dbg_prt(["_process_argv() : args hash (so far)=", $args_href, "args now=", \@args]) ;
1185
1186 # If there are any args left over, handle them
1187 41 foreach my $arg (@args)
1188 {
1189 # If last arg specified as ARRAY, then just add all ARGS
1190 20 ▶ if ($dest_type)
Branch: 1 branch
BranchTrueFalseTotal
if ($dest_type) { } 20 0 20
1191 {
1192 ## Handle wildcards (mainly to cope with Windoze)
1193 20 ▶ if ($arg =~ m/[\*\?]/)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /[\*\?]/) 1 19 20
1194 {
1195 1 my @files = glob("$arg") ;
1196 1 ▶ if (@files)
Branch: 1 branch
BranchTrueFalseTotal
if (@files) 1 0 1
1197 {
1198 1 push @{$args_href->{$dest_type}}, @files ;
1199 1 push @$argv_aref, @files ;
1200 1 $arg = undef ;
1201 }
1202 }
1203
1204 20 ▶ if ($arg)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) 19 1 20
1205 {
1206 19 push @{$args_href->{$dest_type}}, $arg ;
1207 19 push @$argv_aref, $arg ;
1208 }
1209 }
1210 else
1211 {
1212 0 push @$argv_aref, $arg ;
1213  
1214 # create name
1215 0 my $name = sprintf "arg%d", $idx++ ;
1216
1217 # Create new entry
1218 0 my $href = $this->_new_arg_entry($name) ;
1219 0 $args_names_href->{$name} = $href ;
1220
1221 # save arg in specified order
1222 0 push @$arg_list, $name ;
1223
1224 # set value
1225 0 $args_href->{$name} = $arg ;
1226
1227 }
1228  
1229 }
1230  
1231 41 $this->argv($argv_aref) ;
1232 }
1233  
1234 #----------------------------------------------------------------------------
1235 #
1236 #=item B<_process_arg_spec($arg_spec)>
1237 #
1238 #Processes the arg specification string, returning:
1239 #
1240 # ($name, $arg_spec, $spec, $dest_type, $arg_type, $arg_direction, $arg_optional, $arg_append, $arg_mode)
1241 #
1242 #=cut
1243 #
1244 sub _process_arg_spec
1245 36 ▶{
Subroutine _process_arg_spec: called CC=13 SCAR=26.2
1246 36 my $this = shift ;
1247 36 my ($arg_spec) = @_ ;
1248  
1249 36 $this->_dbg_prt(["arg: _process_arg_spec($arg_spec)"], 2) ;
1250  
1251 36 my $developer_only = 0 ;
1252  
1253 # If arg starts with start char then remove it
1254 36 $arg_spec =~ s/^[\-\+\*]// ;
1255
1256 # Get arg name
1257 36 my $name = $arg_spec ;
1258 36 ▶ if ($arg_spec =~ /[\'\"](\w+)[\'\"]/)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg_spec =~ /[\'\"](\w+)[\'\"]/) 0 36 36
1259 {
1260 0 $name = $1 ;
1261 0 $arg_spec =~ s/[\'\"]//g ;
1262 }
1263 36 $name =~ s/\=.*$// ;
1264  
1265 36 my $spec = $arg_spec ;
1266 36 my $arg = "";
1267 36 ▶ if ($spec =~ s/\=(.*)$//)
Branch: 1 branch
BranchTrueFalseTotal
if ($spec =~ s/\=(.*)$//) 36 0 36
1268 {
1269 36 $arg = $1 ;
1270 }
1271 36 $this->_dbg_prt(["_process_arg_spec() set: pod spec=$spec arg=$arg\n"], 2) ;
1272
1273 36 my $dest_type = "" ;
1274 36 ▶ if ($arg =~ /([\@\*])/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /([\@\*])/i) 11 25 36
1275 {
1276 11 $dest_type = $1 ;
1277 }
1278
1279 36 my $arg_type = "" ;
1280 36 ▶ if ($arg =~ /([sfd])/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /([sfd])/i) 36 0 36
1281 {
1282 36 $arg_type = $1 ;
1283 36 ▶ if ($arg_type eq 's')
Branch: 3 branches
BranchTrueFalseTotal
if ($arg_type eq 's') { } 5 31 36
elsif ($arg_type eq 'f') { } 25 6 31
elsif ($arg_type eq 'd') { } 6 0 6
1284 {
1285 5 $spec .= " <string>" ;
1286 }
1287 elsif ($arg_type eq 'f')
1288 {
1289 25 $spec .= " <file>" ;
1290 }
1291 elsif ($arg_type eq 'd')
1292 {
1293 6 $spec .= " <dir>" ;
1294 }
1295 }
1296  
1297 36 my $arg_direction = "i" ;
1298 36 my $arg_append = "" ;
1299 36 ▶ if ($arg =~ /(i|<)/i)
Branch: 3 branches
BranchTrueFalseTotal
if ($arg =~ /(i|<)/i) { } 8 28 36
elsif ($arg =~ /a|>>/i) { } 3 25 28
elsif ($arg =~ /(o|>)/i) { } 6 19 25
1300 {
1301 8 $arg_direction = 'i' ;
1302 8 $spec .= " <input>" ;
1303 }
1304 elsif ($arg =~ /a|>>/i)
1305 {
1306 3 $arg_direction = 'o' ;
1307 3 $arg_append = "a" ;
1308 3 $spec .= " <output>" ;
1309 }
1310 elsif ($arg =~ /(o|>)/i)
1311 {
1312 6 $arg_direction = 'o' ;
1313 6 $spec .= " <output>" ;
1314 }
1315
1316 36 my $arg_optional = 0 ;
1317 36 ▶ if ($arg =~ /\?/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /\?/i) 0 36 36
1318 {
1319 0 $this->_dbg_prt(["_process_arg_spec() set: optional\n"], 2) ;
1320 0 $arg_optional = 1 ;
1321 }
1322  
1323 36 my $arg_mode = "" ;
1324 36 ▶ if ($arg =~ /b/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /b/i) 0 36 36
1325 {
1326 0 $arg_mode = 'b' ;
1327 }
1328
1329 36 $this->_dbg_prt(["_process_arg_spec() set: final pod spec=$spec arg=$arg\n"], 2) ;
1330
1331 36 return ($name, $arg_spec, $spec, $dest_type, $arg_type, $arg_direction, $arg_optional, $arg_append, $arg_mode) ;
1332 }
1333  
1334  
1335 #----------------------------------------------------------------------------
1336 #
1337 #=item B<_new_arg_entry($name, $arg_spec, $summary, $description, $default_val, $pod_spec, $arg_type, $arg_direction, $dest_type, $optional, $arg_append, $arg_mode)>
1338 #
1339 #Create a new HASH with the specified values. Sets the values to defaults if not specified
1340 #
1341 #=cut
1342 #
1343 sub _new_arg_entry
1344 56 ▶{
Subroutine _new_arg_entry: called CC=10 SCAR=23.1
1345 56 my $this = shift ;
1346 56 my ($name, $arg_spec, $summary, $description, $default_val, $pod_spec, $arg_type, $arg_direction, $dest_type, $optional, $arg_append, $arg_mode) = @_ ;
1347
1348 56 ▶ $summary ||= "Arg" ;
Condition100%2/2
$summary ||= "Arg"
l!l
3620
MC/DC100%1/1
$summary ||= "Arg"
$summary
Truth table100%2/2
A
A= $summary
Aresult
11
00
1349 56 ▶ $description ||= "" ;
Condition100%2/2
$description ||= ""
l!l
650
MC/DC100%1/1
$description ||= ""
$description
Truth table100%2/2
A
A= $description
Aresult
11
00
1350 56 ▶ $arg_type ||= "s" ;
Condition100%2/2
$arg_type ||= "s"
l!l
3620
MC/DC100%1/1
$arg_type ||= "s"
$arg_type
Truth table100%2/2
A
A= $arg_type
Aresult
11
00
1351 56 ▶ $arg_direction ||= "i" ;
Condition100%2/2
$arg_direction ||= "i"
l!l
3620
MC/DC100%1/1
$arg_direction ||= "i"
$arg_direction
Truth table100%2/2
A
A= $arg_direction
Aresult
11
00
1352 56 ▶ $dest_type ||= "" ;
Condition100%2/2
$dest_type ||= ""
l!l
1145
MC/DC100%1/1
$dest_type ||= ""
$dest_type
Truth table100%2/2
A
A= $dest_type
Aresult
11
00
1353 56 ▶ $optional ||= 0 ;
Condition100%2/2
$optional ||= 0
l!l
1145
MC/DC100%1/1
$optional ||= 0
$optional
Truth table100%2/2
A
A= $optional
Aresult
11
00
1354 56 ▶ $arg_spec ||= "$arg_type" ;
Condition66%2/3
$arg_spec ||= "$arg_type"
l!l&&r!l&&!r
36200
MC/DC0%0/2
$arg_spec ||= "$arg_type"
$arg_spec "$arg_type"
Truth table66%2/3
A ||= B
A= $arg_specB= "$arg_type"
ABresult
1X1
011
000
1355 56 ▶ $arg_append ||= "" ;
Condition100%2/2
$arg_append ||= ""
l!l
353
MC/DC100%1/1
$arg_append ||= ""
$arg_append
Truth table100%2/2
A
A= $arg_append
Aresult
11
00
1356 56 ▶ $arg_mode ||= "" ;
Condition50%1/2
$arg_mode ||= ""
l!l
056
MC/DC0%0/1
$arg_mode ||= ""
$arg_mode
Truth table50%1/2
A
A= $arg_mode
Aresult
11
00
1357 56 my $entry_href =
1358 {
1359 'name'=>$name,
1360 'spec'=>$arg_spec,
1361 'summary'=>$summary,
1362 'description'=>$description,
1363 'default'=>$default_val,
1364 'pod_spec'=>$pod_spec,
1365 'type' => $arg_type,
1366 'direction' => $arg_direction,
1367 'dest_type' => $dest_type,
1368 'optional' => $optional,
1369 'append' => $arg_append,
1370 'mode' => $arg_mode,
1371 } ;
1372  
1373 56 return $entry_href ;
1374 }
1375  
1376 #----------------------------------------------------------------------------
1377 # Output message, usage info, then exit
1378 sub _complain_usage_exit
1379 6 ▶{
Subroutine _complain_usage_exit: called CC=2 SCAR=7.0
1380 6 my $this = shift ;
1381 6 my ($complain, $exit_code) = @_ ;
1382  
1383 6 print "Error: $complain\n" ;
1384 6 $this->app->usage() ;
1385 6 ▶ $this->app->exit( $exit_code || 1 ) ;
Condition50%1/2
$exit_code || 1
l!l
06
MC/DC0%0/1
$exit_code || 1
$exit_code
Truth table50%1/2
A
A= $exit_code
Aresult
11
00
1386 }
1387  
1388  
1389 # ============================================================================================
1390 # END OF PACKAGE
1391  
1392 =back
1393  
1394 =head1 DIAGNOSTICS
1395  
1396 Setting the debug flag to level 1 prints out (to STDOUT) some debug messages, setting it to level 2 prints out more verbose messages.
1397  
1398 =head1 AUTHOR
1399  
1400 Steve Price C<< <sdprice at cpan.org> >>
1401  
1402 =head1 BUGS
1403  
1404 None that I know of!
1405  
1406 =cut
1407  
1408 31 1;
1409  
1410 __END__
« Framework/Base.pm ↑ Summary Framework/Feature/Run.pm »