line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
21
|
|
|
21
|
|
68
|
use strict; |
|
21
|
|
|
|
|
22
|
|
|
21
|
|
|
|
|
472
|
|
2
|
21
|
|
|
21
|
|
229
|
use warnings; |
|
21
|
|
|
|
|
25
|
|
|
21
|
|
|
|
|
816
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package File::Util::Interface::Modern; |
5
|
|
|
|
|
|
|
$File::Util::Interface::Modern::VERSION = '4.161950'; |
6
|
|
|
|
|
|
|
# ABSTRACT: Modern call interface to File::Util |
7
|
|
|
|
|
|
|
|
8
|
21
|
|
|
21
|
|
66
|
use lib 'lib'; |
|
21
|
|
|
|
|
50
|
|
|
21
|
|
|
|
|
101
|
|
9
|
|
|
|
|
|
|
|
10
|
21
|
|
|
21
|
|
7029
|
use File::Util::Interface::Classic qw( _myargs ); |
|
21
|
|
|
|
|
660
|
|
|
21
|
|
|
|
|
902
|
|
11
|
21
|
|
|
21
|
|
85
|
use File::Util::Definitions qw( :all ); |
|
21
|
|
|
|
|
22
|
|
|
21
|
|
|
|
|
3602
|
|
12
|
|
|
|
|
|
|
|
13
|
21
|
|
|
|
|
922
|
use vars qw( |
14
|
|
|
|
|
|
|
@ISA $AUTHORITY |
15
|
|
|
|
|
|
|
@EXPORT_OK %EXPORT_TAGS |
16
|
21
|
|
|
21
|
|
75
|
); |
|
21
|
|
|
|
|
21
|
|
17
|
|
|
|
|
|
|
|
18
|
21
|
|
|
21
|
|
65
|
use Exporter; |
|
21
|
|
|
|
|
17
|
|
|
21
|
|
|
|
|
7085
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$AUTHORITY = 'cpan:TOMMY'; |
21
|
|
|
|
|
|
|
@ISA = qw( Exporter File::Util::Interface::Classic ); |
22
|
|
|
|
|
|
|
@EXPORT_OK = qw( |
23
|
|
|
|
|
|
|
_remove_opts |
24
|
|
|
|
|
|
|
_myargs |
25
|
|
|
|
|
|
|
_names_values |
26
|
|
|
|
|
|
|
_parse_in |
27
|
|
|
|
|
|
|
); # some of the symbols above come from File::Util::Interface::Classic but |
28
|
|
|
|
|
|
|
# the _remove_opts/_names_values methods are specifically overriden in |
29
|
|
|
|
|
|
|
# this package |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
%EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# -------------------------------------------------------- |
35
|
|
|
|
|
|
|
# File::Util::Interface::Modern::_names_values() |
36
|
|
|
|
|
|
|
# -------------------------------------------------------- |
37
|
|
|
|
|
|
|
sub _names_values { |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# ignore $_[0] File::Util object reference |
40
|
|
|
|
|
|
|
|
41
|
173
|
100
|
|
173
|
|
331
|
if ( ref $_[1] eq 'HASH' ) { |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# method was called like $f->method( { name => val } ) |
44
|
2
|
|
|
|
|
7
|
return $_[1] |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# ...method called like $f->methd( name => val ); |
48
|
|
|
|
|
|
|
|
49
|
171
|
|
|
|
|
459
|
goto \&File::Util::Interface::Classic::_names_values; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# -------------------------------------------------------- |
54
|
|
|
|
|
|
|
# File::Util::Interface::Modern::_remove_opts() |
55
|
|
|
|
|
|
|
# -------------------------------------------------------- |
56
|
|
|
|
|
|
|
sub _remove_opts { |
57
|
|
|
|
|
|
|
|
58
|
260
|
|
|
260
|
|
216
|
shift; # we don't need "$this" here |
59
|
|
|
|
|
|
|
|
60
|
260
|
|
|
|
|
280
|
my $args = shift @_; |
61
|
|
|
|
|
|
|
|
62
|
260
|
100
|
|
|
|
555
|
return unless ref $args eq 'ARRAY'; |
63
|
|
|
|
|
|
|
|
64
|
253
|
|
|
|
|
372
|
my @triage = @$args; @$args = (); |
|
253
|
|
|
|
|
273
|
|
65
|
253
|
|
|
|
|
539
|
my $opts = { }; |
66
|
|
|
|
|
|
|
|
67
|
253
|
|
|
|
|
443
|
while ( @triage ) { |
68
|
|
|
|
|
|
|
|
69
|
367
|
|
|
|
|
324
|
my $arg = shift @triage; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# if an argument is '', 0, or undef, it's obviously not an --option ... |
72
|
367
|
100
|
50
|
|
|
572
|
push @$args, $arg and next unless $arg; # ...so give it back to the @$args |
73
|
|
|
|
|
|
|
|
74
|
329
|
100
|
|
|
|
1132
|
if ( UNIVERSAL::isa( $arg, 'HASH' ) ) { |
|
|
100
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# if we got hashref, then we were called with the new & improved syntax: |
77
|
|
|
|
|
|
|
# e.g.- $ftl->method( arg => { opt => foo, opt2 => bar } ); |
78
|
|
|
|
|
|
|
# |
79
|
|
|
|
|
|
|
# ...as oppsed to the classic syntax: |
80
|
|
|
|
|
|
|
# e.g.- $ftl->method( arg => value, --opt1=value, --flag ) |
81
|
|
|
|
|
|
|
# |
82
|
|
|
|
|
|
|
# the bit of code below makes it possible to support both call syntaxes |
83
|
|
|
|
|
|
|
|
84
|
124
|
|
|
|
|
534
|
@$opts{ keys %$arg } = values %$arg; # crane lower that rover (ahhhhh) |
85
|
|
|
|
|
|
|
# err, Perl flatcopy that hashref |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
elsif ( $arg =~ /^--/ ) { # got old school "--option" argument? |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# it's either a bare "--option", or it's an "--option=value" pair |
90
|
24
|
|
|
|
|
49
|
my ( $opt, $value ) = split /=/, $arg; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# bare version |
93
|
24
|
100
|
|
|
|
56
|
$opts->{ $opt } = defined $value ? $value : 1; |
94
|
|
|
|
|
|
|
# ^^^^^^^ if $value is undef it's a --flag, and value=1 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# sanitized version, remove leading "--" ... |
97
|
24
|
|
|
|
|
30
|
my $clean_name = substr $opt, 2; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# ...and replace non-alnum chars with "_" so the names can be |
100
|
|
|
|
|
|
|
# referenced as hash keys without superfluous quoting and escaping |
101
|
24
|
|
|
|
|
41
|
$clean_name =~ s/[^[:alnum:]]/_/g; |
102
|
|
|
|
|
|
|
|
103
|
24
|
100
|
|
|
|
69
|
$opts->{ $clean_name } = defined $value ? $value : 1; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
else { |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# but if it's not an "--option" type arg, or a hashref of options, |
108
|
|
|
|
|
|
|
# then give it back to the caller's @$args arrayref |
109
|
181
|
|
|
|
|
356
|
push @$args, $arg; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
253
|
|
|
|
|
389
|
return $opts; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# -------------------------------------------------------- |
118
|
|
|
|
|
|
|
# File::Util::Interface::Modern::_parse_in() |
119
|
|
|
|
|
|
|
# -------------------------------------------------------- |
120
|
|
|
|
|
|
|
sub _parse_in { |
121
|
164
|
|
|
164
|
|
250
|
my ( $this, @in ) = @_; |
122
|
|
|
|
|
|
|
|
123
|
164
|
|
|
|
|
349
|
my $opts = $this->_remove_opts( \@in ); # always returns a hashref, given a listref |
124
|
164
|
|
|
|
|
308
|
my $in = $this->_names_values( @in ); # always returns a hashref, given anything |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# merge two hashrefs |
127
|
164
|
|
|
|
|
359
|
@$in{ keys %$opts } = values %$opts; |
128
|
|
|
|
|
|
|
|
129
|
164
|
|
|
|
|
356
|
return $in; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# -------------------------------------------------------- |
134
|
|
|
|
|
|
|
# File::Util::Interface::Modern::DESTROY() |
135
|
|
|
|
|
|
|
# -------------------------------------------------------- |
136
|
|
|
|
2
|
|
|
sub DESTROY { } |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
__END__ |