Util/Interface/Classic.pm

filter: Statementstmt 66.0% 33 / 50 Branchbran 40.0% 8 / 20 Conditioncond 36.3% 4 / 11 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 90.0% 9 / 10 Podpod n/a totaltotal 57.2% 55 / 96 CC 14 SCAR 32.9
CC
14
Cov
56%
_remove_opts
72.0
_myargs
5.1
_names_values
3.0
CRAP 26.9
« Util/Exception.pm ↑ Summary Util/Definitions.pm »
1 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package File::Util::Interface::Classic;
5 24 $File::Util::Interface::Classic::VERSION = '4.201720';
6 # ABSTRACT: Legacy call interface to File::Util
7  
8 24 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 24 ▶use File::Util::Definitions qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 24 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 @ISA $AUTHORITY
14 @EXPORT_OK %EXPORT_TAGS
15 24 );
16  
17 24 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 24 $AUTHORITY = 'cpan:TOMMY';
20 24 @ISA = qw( Exporter );
21 24 @EXPORT_OK = qw(
22 _myargs
23 _remove_opts
24 _names_values
25 );
26  
27 24 %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
28  
29  
30 # --------------------------------------------------------
31 # File::Util::Interface::Classic::_myargs()
32 # --------------------------------------------------------
33 786 ▶sub _myargs {
Subroutine _myargs: called CC=5 SCAR=16.3
34  
35 786 ▶ shift @_ if ( blessed $_[0] || ( $_[0] && $_[0] =~ /^File::Util/ ) );
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) or $_[0] and $_[0] =~ /^File::Util/ 473 313 786
Condition66%4/6
builtin::blessed($_[0]) or $_[0] and $_[0] =~ /^File::Util/
l!l&&r!l&&!r
4730313
$_[0] and $_[0] =~ /^File::Util/
!ll&&!rl&&r
23110
MC/DC33%1/3
builtin::blessed($_[0]) or $_[0] and $_[0] =~ /^File::Util/
builtin::blessed($_[0]) $_[0] $_[0] =~ /^File::Util/
Truth table75%3/4
A or B and C
A= builtin::blessed($_[0])B= $_[0]C= $_[0] =~ /^File::Util/
ABCresult
1XX1
0111
00X0
0100
36  
37 786 ▶ return wantarray ? @_ : $_[0]
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 9 777 786
38 }
39  
40  
41 # --------------------------------------------------------
42 # File::Util::Interface::Classic::_remove_opts()
43 # --------------------------------------------------------
44 0 ▶sub _remove_opts {
Subroutine _remove_opts: not called CC=8 SCAR=42.8
45  
46 0 shift; # we don't need "$this" here
47  
48 0 my $args = shift @_;
49  
50 0 ▶ return unless ref $args eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args eq "ARRAY" 0 0 0
51  
52 0 my @triage = @$args; @$args = ();
53 0 my $opts = { };
54  
55 0 ▶ while ( @triage ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@triage) 0 0 0
56  
57 0 my $arg = shift @triage;
58  
59 # if an argument is '', 0, or undef, it's obviously not an --option ...
60 0 ▶ push @$args, $arg and next unless $arg; # ...so give it back to the @$args
Branch: 1 branch
BranchTrueFalseTotal
unless $arg 0 0 0
Condition0%0/5
$arg || push(@$args, $arg) && (next)
l!l&&r!l&&!r
000
push @$args, $arg and next
!ll
00
MC/DC0%0/2
$arg || push(@$args, $arg) && (next)
$arg push @$args, $arg
Truth table0%0/3
A || B
A= $argB= push @$args, $arg
ABresult
1X1
011
000
61  
62 # hmmm. looks like an "--option" argument, if:
63 0 ▶ if ( $arg =~ /^--/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^--/) { } 0 0 0
64  
65 # it's either a bare "--option", or it's an "--option=value" pair
66 0 my ( $opt, $value ) = split /=/, $arg;
67  
68 # bare version
69 0 ▶ $opts->{ $opt } = defined $value ? $value : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
70 # ^^^^^^^ if $value is undef, it was a --flag (true)
71  
72 # sanitized version, remove leading "--" ...
73 0 my $clean_name = substr $opt, 2;
74  
75 # ...and replace non-alnum chars with "_" so the names can be
76 # referenced as hash keys without superfluous quoting and escaping
77 0 $clean_name =~ s/[^[:alnum:]]/_/g;
78  
79 0 ▶ $opts->{ $clean_name } = defined $value ? $value : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
80 }
81 else {
82  
83 # but if it's not an "--option" type arg, give it back to the @$args
84 0 push @$args, $arg;
85 }
86 }
87  
88 0 return $opts;
89 }
90  
91  
92 # --------------------------------------------------------
93 # File::Util::Interface::Classic::_names_values()
94 # --------------------------------------------------------
95 171 ▶sub _names_values {
Subroutine _names_values: called CC=3 SCAR=11.0
96  
97 171 shift; # we don't need "$this" here
98  
99 171 my @in_pairs = @_;
100 171 my $out_pairs = { };
101  
102 # this code no longer tries to catch foolishness such as names that are
103 # undef other than skipping over them, for lack of sane options to deal
104 # with such insane input ;-)
105 171 ▶ while ( my ( $name, $val ) = splice @in_pairs, 0, 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@in_pairs, 0, 2)) 144 171 315
106  
107 144 ▶ next unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 2 142 144
108  
109 142 $out_pairs->{ $name } = $val;
110 }
111  
112 171 return $out_pairs;
113 }
114  
115  
116 # --------------------------------------------------------
117 # File::Util::Interface::Classic::DESTROY()
118 # --------------------------------------------------------
119 2 ▶sub DESTROY { }
Subroutine DESTROY: called CC=1 SCAR=0.0
120  
121 24 1;
122  
123  
124 __END__
« Util/Exception.pm ↑ Summary Util/Definitions.pm »