Util/Underscore/Scalars.pm

filter: Statementstmt 85.7% 36 / 42 Branchbran 80.7% 21 / 26 Conditioncond 90.9% 10 / 11 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 14 / 14 Podpod n/a totaltotal 85.8% 85 / 99 CC 17 SCAR 13.0
CC
17
Cov
85%
chomp
7.4
index
5.3
is_string
3.0
CRAP 3.7
« Util/Underscore/References.pm ↑ Summary Util/Underscore/Numbers.pm »
1 package Util::Underscore::Scalars;
2  
3 #ABSTRACT: Functions for introspecting and manipulating scalars
4  
5 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 ## no critic (ProhibitMultiplePackages)
10 package # hide from PAUSE
11 _;
12  
13 ## no critic (RequireArgUnpacking, RequireFinalReturn, ProhibitSubroutinePrototypes)
14  
15 ## no critic (ProtectPrivateVars)
16 12 $Util::Underscore::_ASSIGN_ALIASES->('Scalar::Util', new_dual => 'dualvar');
17  
18 sub is_dual(_) {
19 4 ▶ goto &Scalar::Util::isdual;
Subroutine is_dual: called CC=1 SCAR=0.0
20 }
21  
22 sub is_vstring(_) {
23 7 ▶ goto &Scalar::Util::isvstring;
Subroutine is_vstring: called CC=1 SCAR=0.0
24 }
25  
26 sub is_readonly(_) {
27 8 ▶ goto &Scalar::Util::readonly;
Subroutine is_readonly: called CC=1 SCAR=0.0
28 }
29  
30 ## no critic (ProtectPrivateVars)
31 12 $Util::Underscore::_ASSIGN_ALIASES->('Const::Fast', const => 'const');
32  
33 sub is_tainted (_) {
34 4 ▶ goto &Scalar::Util::tainted;
Subroutine is_tainted: called CC=1 SCAR=0.0
35 }
36  
37 12 ▶if (eval q{use Data::Alias 1.18 (); 1}) { ## no critic (ProhibitStringyEval)
Subroutine BEGIN: called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
if (eval "use Data::Alias 1.18 (); 1") 0 12 12
38 ## no critic (ProtectPrivateVars)
39 0 $Util::Underscore::_ASSIGN_ALIASES->('Data::Alias', alias => 'alias');
40 }
41  
42 sub is_plain(_) {
43 7 ▶ defined $_[0]
Subroutine is_plain: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and not defined &ref_type($_[0]) 5 2 7
44 && !defined ref_type $_[0];
45 }
46  
47 sub is_string(_) {
48 27 ▶ defined $_[0]
Subroutine is_string: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and !defined(&ref_type($_[0])) || overload::Method($_[0], "\"\"") 25 2 27
Condition100%6/6
defined $_[0] && (!defined(&ref_type($_[0])) || overload::Method($_[0], '""'))
!ll&&!rl&&r
2520
not defined &ref_type($_[0]) or overload::Method($_[0], "\"\"")
l!l&&r!l&&!r
1915
MC/DC100%3/3
defined $_[0] && (!defined(&ref_type($_[0])) || overload::Method($_[0], '""'))
defined $_[0] not defined &ref_type($_[0]) overload::Method($_[0], "\"\"")
Truth table100%4/4
A && not(B) or C
A= defined $_[0]B= not defined &ref_type($_[0])C= overload::Method($_[0], "\"\"")
ABCresult
0XX0
1000
11X1
1011
49 && (!defined ref_type $_[0]
50 || overload::Method($_[0], q[""]));
51 }
52  
53 sub is_bool(_) {
54 10 ▶ !defined ref_type $_[0]
Subroutine is_bool: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
not defined &ref_type($_[0]) or overload::Method($_[0], "bool") 5 5 10
55 || overload::Method($_[0], q[bool]);
56 }
57  
58 sub is_identifier(_) {
59 11 ▶ defined $_[0]
Subroutine is_identifier: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and scalar $_[0] =~ /\A [^\W\d]\w* \z/msx 9 2 11
60 && scalar($_[0] =~ /\A [^\W\d]\w* \z/xsm);
61 }
62  
63 sub is_package(_) {
64 25 ▶ defined $_[0]
Subroutine is_package: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and scalar $_[0] =~ /\A [^\W\d]\w* (?: [:][:]\w+ )* \z/msx 23 2 25
65 && scalar($_[0] =~ /\A [^\W\d]\w* (?: [:][:]\w+ )* \z/xsm);
66 }
67  
68 sub chomp(_;$) {
69  
70 # localizedly set the input record separator
71 8 ▶ local $/ = $/;
Subroutine chomp: called CC=7 SCAR=20.0
72 8 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 4 4 8
73 4 ▶ if (_::is_string $_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (&is_string($_[1])) { } 4 0 4
74 4 $/ = "$_[1]";
75 }
76 else {
77 0 Carp::croak q(_::chomp: second argument must be a string);
78 }
79 }
80  
81 # handle a single string
82 # ATTENTION: this depends on _::is_string
83 8 ▶ if (_::is_string $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (&is_string($_[0])) { } 4 4 8
elsif (&is_array_ref($_[0])) { } 4 0 4
84 4 CORE::chomp(my $copy = $_[0]);
85 4 return $copy;
86 }
87  
88 # handle an arrayref of strings (effectively auto-mapping)
89 # ATTENTION: _::is_array_ref will be defined later
90 elsif (_::is_array_ref($_[0])) {
91 4 my @result = @{ $_[0] };
92 4 for (@result) {
93 8 ▶ goto ERROR if not _::is_string;
Branch: 1 branch
BranchTrueFalseTotal
unless &is_string($_) 0 8 8
94 8 CORE::chomp;
95 }
96 4 return \@result;
97 }
98  
99 ERROR:
100 0 Carp::croak
101 q(_::chomp: first argument must be string or arrayref of strings);
102 }
103  
104 sub index($$;$) {
105 7 ▶ if (@_ >= 3 and $_[2] < 0) {
Subroutine index: called CC=5 SCAR=16.7
Branch: 1 branch
BranchTrueFalseTotal
if (@_ >= 3 and $_[2] < 0) 0 7 7
Condition66%2/3
@_ >= 3 and $_[2] < 0
!ll&&!rl&&r
340
MC/DC0%0/2
@_ >= 3 and $_[2] < 0
@_ >= 3 $_[2] < 0
Truth table66%2/3
A and B
A= @_ >= 3B= $_[2] < 0
ABresult
0X0
100
111
106 0 Carp::croak q(_::index: starting position must be non-negative.)
107 }
108 7 ▶ my $result = CORE::index($_[0], $_[1], $_[2] // 0);
Condition100%2/2
$_[2] // 0
l!l
43
MC/DC100%1/1
$_[2] // 0
$_[2]
Truth table100%2/2
A
A= $_[2]
Aresult
11
00
109 7 ▶ return ($result >= 0) ? $result : undef;
Branch: 1 branch
BranchTrueFalseTotal
$result >= 0 ? : 5 2 7
110 }
111  
112 12 1;
113  
114 __END__
« Util/Underscore/References.pm ↑ Summary Util/Underscore/Numbers.pm »