line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
20
|
|
|
20
|
|
63
|
use strict; |
|
20
|
|
|
|
|
20
|
|
|
20
|
|
|
|
|
441
|
|
2
|
20
|
|
|
20
|
|
214
|
use warnings; |
|
20
|
|
|
|
|
22
|
|
|
20
|
|
|
|
|
774
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package File::Util::Interface::Modern; |
5
|
|
|
|
|
|
|
$File::Util::Interface::Modern::VERSION = '4.161200'; |
6
|
|
|
|
|
|
|
# ABSTRACT: Modern call interface to File::Util |
7
|
|
|
|
|
|
|
|
8
|
20
|
|
|
20
|
|
61
|
use lib 'lib'; |
|
20
|
|
|
|
|
23
|
|
|
20
|
|
|
|
|
98
|
|
9
|
|
|
|
|
|
|
|
10
|
20
|
|
|
20
|
|
6620
|
use File::Util::Interface::Classic qw( _myargs ); |
|
20
|
|
|
|
|
618
|
|
|
20
|
|
|
|
|
853
|
|
11
|
20
|
|
|
20
|
|
80
|
use File::Util::Definitions qw( :all ); |
|
20
|
|
|
|
|
14
|
|
|
20
|
|
|
|
|
3489
|
|
12
|
|
|
|
|
|
|
|
13
|
20
|
|
|
|
|
903
|
use vars qw( |
14
|
|
|
|
|
|
|
@ISA $AUTHORITY |
15
|
|
|
|
|
|
|
@EXPORT_OK %EXPORT_TAGS |
16
|
20
|
|
|
20
|
|
75
|
); |
|
20
|
|
|
|
|
16
|
|
17
|
|
|
|
|
|
|
|
18
|
20
|
|
|
20
|
|
66
|
use Exporter; |
|
20
|
|
|
|
|
18
|
|
|
20
|
|
|
|
|
6462
|
|
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
|
172
|
100
|
|
172
|
|
299
|
if ( ref $_[1] eq 'HASH' ) { |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# method was called like $f->method( { name => val } ) |
44
|
2
|
|
|
|
|
8
|
return $_[1] |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# ...method called like $f->methd( name => val ); |
48
|
|
|
|
|
|
|
|
49
|
170
|
|
|
|
|
444
|
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
|
254
|
|
|
254
|
|
198
|
shift; # we don't need "$this" here |
59
|
|
|
|
|
|
|
|
60
|
254
|
|
|
|
|
218
|
my $args = shift @_; |
61
|
|
|
|
|
|
|
|
62
|
254
|
100
|
|
|
|
506
|
return unless ref $args eq 'ARRAY'; |
63
|
|
|
|
|
|
|
|
64
|
247
|
|
|
|
|
338
|
my @triage = @$args; @$args = (); |
|
247
|
|
|
|
|
297
|
|
65
|
247
|
|
|
|
|
229
|
my $opts = { }; |
66
|
|
|
|
|
|
|
|
67
|
247
|
|
|
|
|
461
|
while ( @triage ) { |
68
|
|
|
|
|
|
|
|
69
|
363
|
|
|
|
|
286
|
my $arg = shift @triage; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# if an argument is '', 0, or undef, it's obviously not an --option ... |
72
|
363
|
100
|
50
|
|
|
553
|
push @$args, $arg and next unless $arg; # ...so give it back to the @$args |
73
|
|
|
|
|
|
|
|
74
|
325
|
100
|
|
|
|
1085
|
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
|
|
|
|
|
491
|
@$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
|
|
|
|
|
46
|
my ( $opt, $value ) = split /=/, $arg; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# bare version |
93
|
24
|
100
|
|
|
|
57
|
$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
|
|
|
|
|
28
|
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
|
|
|
|
|
40
|
$clean_name =~ s/[^[:alnum:]]/_/g; |
102
|
|
|
|
|
|
|
|
103
|
24
|
100
|
|
|
|
72
|
$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
|
177
|
|
|
|
|
326
|
push @$args, $arg; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
247
|
|
|
|
|
380
|
return $opts; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# -------------------------------------------------------- |
118
|
|
|
|
|
|
|
# File::Util::Interface::Modern::_parse_in() |
119
|
|
|
|
|
|
|
# -------------------------------------------------------- |
120
|
|
|
|
|
|
|
sub _parse_in { |
121
|
163
|
|
|
163
|
|
285
|
my ( $this, @in ) = @_; |
122
|
|
|
|
|
|
|
|
123
|
163
|
|
|
|
|
311
|
my $opts = $this->_remove_opts( \@in ); # always returns a hashref, given a listref |
124
|
163
|
|
|
|
|
305
|
my $in = $this->_names_values( @in ); # always returns a hashref, given anything |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# merge two hashrefs |
127
|
163
|
|
|
|
|
350
|
@$in{ keys %$opts } = values %$opts; |
128
|
|
|
|
|
|
|
|
129
|
163
|
|
|
|
|
362
|
return $in; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# -------------------------------------------------------- |
134
|
|
|
|
|
|
|
# File::Util::Interface::Modern::DESTROY() |
135
|
|
|
|
|
|
|
# -------------------------------------------------------- |
136
|
|
|
|
2
|
|
|
sub DESTROY { } |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
__END__ |