File Coverage

blib/lib/App/Asciio/Options.pm
Criterion Covered Total %
statement 12 41 29.2
branch 0 6 0.0
condition 0 7 0.0
subroutine 4 8 50.0
pod 0 3 0.0
total 16 65 24.6


line stmt bran cond sub pod time code
1              
2             package App::Asciio ;
3              
4             $|++ ;
5              
6 4     4   29 use strict;
  4         9  
  4         171  
7 4     4   21 use warnings;
  4         9  
  4         232  
8              
9 4     4   25 use Data::TreeDumper ;
  4         7  
  4         424  
10 4     4   3359 use Getopt::Long ;
  4         65163  
  4         70  
11              
12             #-----------------------------------------------------------------------------
13              
14             sub ParseSwitches
15             {
16 0     0 0   my ($self, $switches_to_parse, $ignore_error) = @_ ;
17              
18 0           my $asciio_config = {} ;
19              
20 0           Getopt::Long::Configure('no_auto_abbrev', 'no_ignore_case', 'require_order') ;
21              
22 0           my @flags = Get_GetoptLong_Data($asciio_config) ;
23              
24 0           @ARGV = @{$switches_to_parse} ;
  0            
25              
26             # tweek option parsing so we can mix switches with targets
27 0           my $contains_switch ;
28             my @targets ;
29              
30             do
31 0           {
32 0   0       while(@ARGV && $ARGV[0] !~ /^-/)
33             {
34             #~ print "target => $ARGV[0] \n" ;
35 0           push @targets, shift @ARGV ;
36             }
37            
38 0           $contains_switch = @ARGV ;
39            
40 0 0   0     local $SIG{__WARN__} = sub {print STDERR $_[0] unless $ignore_error ;} ;
  0            
41            
42 0 0         unless(GetOptions(@flags))
43             {
44 0 0         return(0, "Try perl asciio -h.", $asciio_config, @ARGV) unless $ignore_error;
45             }
46             }
47             while($contains_switch) ;
48              
49 0           $asciio_config->{TARGETS} = \@targets ;
50              
51 0           return(1, '', $asciio_config) ;
52             }
53              
54             #-------------------------------------------------------------------------------
55              
56             sub Get_GetoptLong_Data
57             {
58 0   0 0 0   my $asciio_config = shift || die 'Missing argument.' ;
59              
60 0           my @flags_and_help = GetSwitches($asciio_config) ;
61              
62 0           my $flag_element_counter = 0 ;
63 0           my @getoptlong_data ;
64              
65 0           for (my $i = 0 ; $i < @flags_and_help; $i += 4)
66             {
67 0           my ($flag, $variable) = ($flags_and_help[$i], $flags_and_help[$i + 1]) ;
68 0           push @getoptlong_data, ($flag, $variable) ;
69             }
70              
71 0           return(@getoptlong_data) ;
72             }
73              
74             #-------------------------------------------------------------------------------
75              
76             sub GetSwitches
77             {
78 0   0 0 0   my $asciio_config = shift || {} ;
79              
80 0           $asciio_config->{SETUP_PATHS} = [] ;
81              
82             my @flags_and_help =
83             (
84             'setup_path=s' => $asciio_config->{SETUP_PATHS},
85             'Sets the root of the setup directory.',
86             '',
87            
88             's|script=s' => \$asciio_config->{SCRIPT},
89             'script to be run at AsciiO start.',
90             '',
91            
92             'h|help' => \$asciio_config->{HELP},
93 0           'Displays some help.',
94             '',
95             ) ;
96            
97 0           return(@flags_and_help) ;
98             }
99              
100             #-----------------------------------------------------------------------------
101              
102             1 ;
103