TPath/Attributes/Extended.pm

filter: Statementstmt 60.8% 104 / 171 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 51.5% 34 / 66 Podpod 0.0% 0 / 31 totaltotal 46.9% 138 / 294 CC 13 SCAR 11.5
CC
13
Cov
53%
extended_matches
12.0
extended_replace
12.0
extended_looking_at
6.0
CRAP 3.2
« TPath/Selector/Parent.pm ↑ Summary TPath/Selector/Test/AnywhereMatch.pm »
1 package TPath::Attributes::Extended;
2 1 $TPath::Attributes::Extended::VERSION = '1.007';
3 # ABSTRACT: a collection of attributes beyond the standard set
4  
5  
6 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MooseX::MethodAttributes::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use List::Util qw(max min sum reduce);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 0 ▶sub extended_abs : Attr(m:abs) {
Subroutine extended_abs: not called CC=1 SCAR=6.9
Pod undocumented
12 0 abs $_[2];
13 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 0 ▶sub extended_ceil : Attr(m:ceil) {
Subroutine extended_ceil: not called CC=1 SCAR=6.9
Pod undocumented
17 0 require POSIX;
18 0 POSIX::ceil( $_[2] );
19 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 0 ▶sub extended_floor : Attr(m:floor) {
Subroutine extended_floor: not called CC=1 SCAR=6.9
Pod undocumented
23 0 require POSIX;
24 0 POSIX::floor( $_[2] );
25 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27  
28 0 ▶sub extended_int : Attr(m:int) {
Subroutine extended_int: not called CC=1 SCAR=6.9
Pod undocumented
29 0 int $_[2];
30 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32  
33 0 ▶sub extended_round : Attr(m:round) {
Subroutine extended_round: not called CC=1 SCAR=6.9
Pod undocumented
34 0 sprintf '%.0f', $_[2];
35 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37  
38 0 ▶sub extended_max : Attr(m:max) {
Subroutine extended_max: not called CC=1 SCAR=6.9
Pod undocumented
39 0 max @_[ 2 .. $#_ ];
40 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42  
43 0 ▶sub extended_min : Attr(m:min) {
Subroutine extended_min: not called CC=1 SCAR=6.9
Pod undocumented
44 0 min @_[ 2 .. $#_ ];
45 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47  
48 0 ▶sub extended_sum : Attr(m:sum) {
Subroutine extended_sum: not called CC=1 SCAR=6.9
Pod undocumented
49 0 sum @_[ 2 .. $#_ ];
50 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52  
53 0 ▶sub extended_prod : Attr(m:prod) {
Subroutine extended_prod: not called CC=1 SCAR=6.9
Pod undocumented
54 0 ▶ 0 + reduce { $a * $b } @_[ 2 .. $#_ ];
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57  
58 0 ▶sub extended_matches : Attr(s:matches) {
Subroutine extended_matches: not called CC=3 SCAR=24.8
Pod undocumented
59 0 my ( $str, $re ) = @_[ 2, 3 ];
60 0 ▶ ( $str // '' ) =~ /^$re$/ ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
($str // '') =~ /^$re$/ ? : 0 0 0
Condition0%0/2
$str // ""
l!l
00
MC/DC0%0/1
$str // ""
$str
Truth table0%0/2
A
A= $str
Aresult
11
00
61 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63  
64 0 ▶sub extended_looking_at : Attr(s:looking-at) {
Subroutine extended_looking_at: not called CC=2 SCAR=17.9
Pod undocumented
65 0 my ( $str, $re ) = @_[ 2, 3 ];
66 0 ▶ $str =~ /^$re/ ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /^$re/ ? : 0 0 0
67 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69  
70 0 ▶sub extended_find : Attr(s:find) {
Subroutine extended_find: not called CC=2 SCAR=17.9
Pod undocumented
71 0 my ( $str, $re ) = @_[ 2, 3 ];
72 0 ▶ $str =~ /$re/ ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /$re/ ? : 0 0 0
73 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
74  
75  
76 0 ▶sub extended_starts_with : Attr(s:starts-with) {
Subroutine extended_starts_with: not called CC=2 SCAR=17.9
Pod undocumented
77 0 my ( $str, $prefix ) = @_[ 2, 3 ];
78 0 ▶ 0 == index $str, $prefix ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 0 0 0
79 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
80  
81  
82 0 ▶sub extended_ends_with : Attr(s:ends-with) {
Subroutine extended_ends_with: not called CC=2 SCAR=17.9
Pod undocumented
83 0 my ( $str, $suffix ) = @_[ 2, 3 ];
84 0 ▶ -1 < index( $str, $suffix, length($str) - length($suffix) ) ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
index($str, $suffix, length($str) - length($suffix)) != -1 ? : 0 0 0
85 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87  
88 0 ▶sub extended_contains : Attr(s:contains) {
Subroutine extended_contains: not called CC=2 SCAR=17.9
Pod undocumented
89 0 my ( $str, $infix ) = @_[ 2, 3 ];
90 0 ▶ -1 < index( $str, $infix ) ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
index($str, $infix) != -1 ? : 0 0 0
91 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
92  
93  
94 0 ▶sub extended_index : Attr(s:index) {
Subroutine extended_index: not called CC=1 SCAR=6.9
Pod undocumented
95 0 my ( $str, $infix ) = @_[ 2, 3 ];
96 0 index $str, $infix;
97 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
98  
99  
100 0 ▶sub extended_concat : Attr(s:concat) {
Subroutine extended_concat: not called CC=1 SCAR=6.9
Pod undocumented
101 0 join '', @_[ 2 .. $#_ ];
102 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
103  
104  
105 0 ▶sub extended_replace_first : Attr(s:replace-first) {
Subroutine extended_replace_first: not called CC=1 SCAR=6.9
Pod undocumented
106 0 my ( $str, $rx, $rep ) = @_[ 2 .. 4 ];
107 0 $str =~ s/$rx/$rep/;
108 0 $str;
109 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
110  
111  
112 0 ▶sub extended_replace_all : Attr(s:replace-all) {
Subroutine extended_replace_all: not called CC=1 SCAR=6.9
Pod undocumented
113 0 my ( $str, $rx, $rep ) = @_[ 2 .. 4 ];
114 0 $str =~ s/$rx/$rep/g;
115 0 $str;
116 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
117  
118  
119 0 ▶sub extended_replace : Attr(s:replace) {
Subroutine extended_replace: not called CC=3 SCAR=24.8
Pod undocumented
120 0 my ( $str, $ss, $rep ) = @_[ 2 .. 4 ];
121 0 my $l = length $ss;
122 0 my $start = 0;
123 0 my $ns = '';
124 0 ▶ while ( ( my $i = index $str, $ss, $start ) > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $i = index($str, $ss, $start)) > -1) 0 0 0
125 0 $ns .= substr $str, $start, $i - $start;
126 0 $ns .= $rep;
127 0 $start = $i + $l;
128 }
129 0 $l = length $str;
130 0 ▶ $ns .= substr $str, $start, $l - $start if $start < $l;
Branch: 1 branch
BranchTrueFalseTotal
if $start < $l 0 0 0
131 0 $ns;
132 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
133  
134  
135 0 ▶sub extended_compare : Attr(s:cmp) {
Subroutine extended_compare: not called CC=1 SCAR=6.9
Pod undocumented
136 0 my ( $s1, $s2 ) = @_[ 2, 3 ];
137 0 $s1 cmp $s2;
138 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
139  
140  
141 0 ▶sub extended_substr : Attr(s:substr) {
Subroutine extended_substr: not called CC=2 SCAR=17.9
Pod undocumented
142 0 my ( $s, $i1, $i2 ) = @_[ 2 .. 4 ];
143 0 ▶ if ( defined $i2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i2) { } 0 0 0
144 0 substr $s, $i1, $i2 - $i1;
145 }
146 else {
147 0 substr $s, $i1;
148 }
149 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
150  
151  
152 0 ▶sub extended_len : Attr(s:len) {
Subroutine extended_len: not called CC=1 SCAR=6.9
Pod undocumented
153 0 length $_[2];
154 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
155  
156  
157 0 ▶sub extended_uc : Attr(s:uc) {
Subroutine extended_uc: not called CC=1 SCAR=6.9
Pod undocumented
158 0 uc $_[2];
159 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
160  
161  
162 0 ▶sub extended_lc : Attr(s:lc) {
Subroutine extended_lc: not called CC=1 SCAR=6.9
Pod undocumented
163 0 lc $_[2];
164 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
165  
166  
167 0 ▶sub extended_uc_first : Attr(s:ucfirst) {
Subroutine extended_uc_first: not called CC=1 SCAR=6.9
Pod undocumented
168 0 ucfirst $_[2];
169 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
170  
171  
172 0 ▶sub extended_trim : Attr(s:trim) {
Subroutine extended_trim: not called CC=1 SCAR=6.9
Pod undocumented
173 0 ( my $s = $_[2] ) =~ s/^\s++|\s++$//g;
174 0 $s;
175 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
176  
177  
178 0 ▶sub extended_nspace : Attr(s:nspace) {
Subroutine extended_nspace: not called CC=1 SCAR=6.9
Pod undocumented
179 0 my $s = extended_trim(@_);
180 0 $s =~ s/\s++/ /g;
181 0 $s;
182 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
183  
184  
185 0 ▶sub extended_join : Attr(s:join) {
Subroutine extended_join: not called CC=2 SCAR=17.9
Pod undocumented
186 0 my ( $sep, @strings ) = @_[ 2 .. $#_ ];
187 0 ▶ $sep //= 'null';
Condition0%0/2
$sep //= "null"
l!l
00
MC/DC0%0/1
$sep //= "null"
$sep
Truth table0%0/2
A
A= $sep
Aresult
11
00
188 0 join "$sep", @strings;
189 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
190  
191  
192 0 ▶sub extended_millis : Attr(u:millis) {
Subroutine extended_millis: not called CC=1 SCAR=6.9
Pod undocumented
193 0 require Time::HiRes;
194 0 my ( $s, $m ) = Time::HiRes::gettimeofday();
195 0 $m = int( $m / 1000 );
196 0 $s * 1000 + $m;
197 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
198  
199  
200 0 ▶sub extended_udef : Attr(u:def) {
Subroutine extended_udef: not called CC=2 SCAR=17.9
Pod undocumented
201 0 ▶ defined $_[2] ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[2] ? : 0 0 0
202 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
203  
204 1 1;
205  
206 __END__
« TPath/Selector/Parent.pm ↑ Summary TPath/Selector/Test/AnywhereMatch.pm »