Medley/String.pm

filter: Statementstmt 52.6% 399 / 758 Branchbran 15.6% 69 / 442 Conditioncond 3.0% 1 / 33 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 87.9% 95 / 108 Podpod n/a totaltotal 41.3% 564 / 1363 CC 245 SCAR 39.8
CC
245
Cov
38%
undefToString
148.1
isUpper
122.1
camelize
101.6
CRAP 53.3
« Medley/File/Zip.pm ↑ Summary Medley/Spawn.pm »
1 package Util::Medley::String;
2 8 $Util::Medley::String::VERSION = '0.049';
3 8 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use Kavorka '-all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Data::Printer alias => 'pdump';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use String::Util 'nocontent';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Scalar::Util::Numeric; # qw(isint);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Util::Medley::String - utility methods for working with strings
14  
15 =head1 VERSION
16  
17 version 0.049
18  
19 =head1 SYNOPSIS
20  
21 ...
22
23 =head1 DESCRIPTION
24  
25 ...
26  
27 =cut
28  
29 #########################################################################################
30  
31 =head1 METHODS
32  
33 =head2 camelize
34  
35 Converts a string to camelcase.
36  
37 =over
38  
39 =item usage:
40  
41 $camelCase = $util->camelize($str);
42  
43 $camelCase = $util->camelize(str => $str);
44  
45 =item args:
46  
47 =over
48  
49 =item str [Str]
50  
51 The string you wish to camelize.
52  
53 =back
54  
55 =back
56
57 =cut
58  
59 8 ▶multi method camelize (Str $str) {
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine camelize: called CC=9 SCAR=25.2
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 1 0 1
@_ ? : 1 0 1
unless ($____nobble_checks) 0 1 1
if @_ != 1 0 1 1
$#_ >= 0 ? : 1 0 1
unless ($____nobble_checks) 0 1 1
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
60  
61 1 my @a = split( /[:_-]+/, $str );
62 1 my @b = lc shift @a;
63 1 push @b, map { ucfirst lc $_ } @a;
64  
65 1 return join '', @b;
66 }
67  
68 8 ▶multi method camelize (Str :$str!) {
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine camelize: not called CC=14 SCAR=46.2
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'str'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"str"}) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
69
70 0 return $self->camelize($str);
71 }
72  
73  
74 =head2 isBlank
75  
76 Checks whether a string is strictly whitespace or empty.
77  
78 =over
79  
80 =item usage:
81  
82 $bool = $util->isBlank($str);
83  
84 $bool = $util->isBlank(str => $str);
85  
86 =item args:
87  
88 =over
89  
90 =item str [Str]
91  
92 The string to check.
93  
94 =back
95
96 =back
97
98 =cut
99  
100 8 ▶multi method isBlank (Str $str) {
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine isBlank: called CC=10 SCAR=26.6
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 3 0 3
@_ ? : 3 0 3
unless ($____nobble_checks) 0 3 3
if @_ != 1 0 3 3
$#_ >= 0 ? : 3 0 3
unless ($____nobble_checks) 0 3 3
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
101  
102 3 ▶ if ( nocontent($str) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (nocontent($str)) 2 1 3
103 2 return 1;
104 }
105  
106 1 return 0;
107 }
108  
109 8 ▶multi method isBlank (Str :$str!) {
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine isBlank: not called CC=14 SCAR=46.2
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'str'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"str"}) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
110  
111 0 return $self->isBlank($str);
112 }
113  
114  
115 =head2 isInt
116  
117 Just a pass-through to String::Util::Numeric::isint.
118  
119 =over
120  
121 =item usage:
122  
123 $bool = $util->isInt($str);
124  
125 $bool = $util->isInt(str => $str);
126  
127 =item args:
128  
129 =over
130  
131 =item str [Str]
132  
133 The string you wish to check for an integer.
134  
135 =back
136  
137 =back
138
139 =cut
140  
141 8 ▶multi method isInt (Str :$str!) {
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine isInt: called CC=15 SCAR=29.9
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 4 0 4
@_ ? : 4 0 4
unless ($____nobble_checks) 0 4 4
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 4 4
if ($slice_length % 2 != 0) 0 4 4
if ($i <= $#_) 4 4 8
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 4 4
exists $_{'str'} ? : 4 0 4
unless ($____nobble_checks) 0 4 4
if (exists $_{"str"}) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition33%1/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
400
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
142  
143 4 ▶ if (Scalar::Util::Numeric::isint($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Scalar::Util::Numeric::isint($str)) 3 1 4
144 3 return 1;
145 }
146
147 1 return 0;
148 }
149  
150 8 ▶multi method isInt (Str $str) {
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine isInt: called CC=9 SCAR=26.2
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 4 0 4
@_ ? : 4 0 4
unless ($____nobble_checks) 0 4 4
if @_ != 1 0 4 4
$#_ >= 0 ? : 4 0 4
unless ($____nobble_checks) 0 4 4
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
151  
152 4 return $self->isInt(str => $str);
153 }
154  
155 =head2 isUpper
156  
157 todo
158  
159 =over
160  
161 =item usage:
162  
163 $bool = $util->isUpper($str);
164  
165 $bool = $util->isUpper(str => $str);
166  
167 =item args:
168  
169 =over
170  
171 =item str [Str]
172  
173 The string you wish to check for uppercase.
174  
175 =back
176  
177 =back
178
179 =cut
180  
181 8 ▶multi method isUpper (Str :$str!) {
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine isUpper: not called CC=15 SCAR=48.0
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'str'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"str"}) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
182  
183 0 my $lookfor = 'A-Z0-9_()';
184
185 0 ▶ if ($str =~ /^[$lookfor]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^[$lookfor]+$/u) 0 0 0
186 0 return 1;
187 }
188
189 0 return 0;
190 }
191  
192 8 ▶multi method isUpper (Str $str) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine isUpper: not called CC=9 SCAR=39.4
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
193  
194 0 return $self->isUpper(str => $str);
195 }
196  
197  
198 =head2 lTrim
199  
200 Just a pass-through to String::Util::lTrim.
201  
202 =over
203  
204 =item usage:
205  
206 $lTrimmed = $util->lTrim($str);
207  
208 $lTrimmed = $util->lTrim(str => $str);
209  
210 =item args:
211  
212 =over
213  
214 =item str [Str]
215  
216 The string to lTrim.
217  
218 =back
219  
220 =back
221
222 =cut
223  
224 8 ▶multi method lTrim (Str $str) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine lTrim: not called CC=9 SCAR=39.4
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
225  
226 0 return String::Util::ltrim($str);
227 }
228  
229 8 ▶multi method lTrim (Str :$str!) {
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine lTrim: not called CC=14 SCAR=46.2
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'str'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"str"}) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
230
231 0 return $self->lTrim($str);
232 }
233  
234 =head2 pascalize
235  
236 Converts a string to Pascal case.
237  
238 =over
239  
240 =item usage:
241  
242 $pascalCase = $util->pascalize($str);
243  
244 $pascalCase = $util->pascalize(str => $str);
245  
246 =item args:
247  
248 =over
249  
250 =item str [Str]
251  
252 The string you wish to camelize.
253  
254 =back
255  
256 =back
257
258 =cut
259  
260 8 ▶multi method pascalize (Str $str) {
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine pascalize: called CC=9 SCAR=25.2
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 2 0 2
@_ ? : 2 0 2
unless ($____nobble_checks) 0 2 2
if @_ != 1 0 2 2
$#_ >= 0 ? : 2 0 2
unless ($____nobble_checks) 0 2 2
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
261  
262 2 my @a = split( /[:_-]+/, $str );
263 2 my @b;
264 2 push @b, map { ucfirst lc $_ } @a;
265  
266 2 return join '', @b;
267 }
268  
269 8 ▶multi method pascalize (Str :$str!) {
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine pascalize: not called CC=14 SCAR=46.2
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'str'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"str"}) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
270  
271 0 return $self->pascalize($str);
272 }
273  
274  
275 =head2 rTrim
276  
277 Just a pass-through to String::Util::rTrim.
278  
279 =over
280  
281 =item usage:
282  
283 $rTrimmed = $util->rTrim($str);
284  
285 $rTrimmed = $util->rTrim(str => $str);
286  
287 =item args:
288  
289 =over
290  
291 =item str [Str]
292  
293 The string to rTrim.
294  
295 =back
296  
297 =back
298
299 =cut
300  
301 8 ▶multi method rTrim (Str :$str!) {
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine rTrim: not called CC=14 SCAR=46.2
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'str'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"str"}) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
302
303 0 return $self->rTrim($str);
304 }
305  
306 8 ▶multi method rTrim (Str $str) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine rTrim: not called CC=9 SCAR=39.4
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
307  
308 0 return String::Util::rtrim($str);
309 }
310  
311 =head2 snakelize
312  
313 Converts a string to snake case.
314  
315 =over
316  
317 =item usage:
318  
319 $snakeCase = $util->snakeize($str);
320  
321 $snakeCase = $util->snakeize(str => $str);
322  
323 =item args:
324  
325 =over
326  
327 =item str [Str]
328  
329 The string to snakeize.
330  
331 =back
332  
333 =back
334
335 =cut
336  
337 8 ▶multi method snakeize (Str $str) {
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine snakeize: called CC=11 SCAR=27.8
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 1 0 1
@_ ? : 1 0 1
unless ($____nobble_checks) 0 1 1
if @_ != 1 0 1 1
$#_ >= 0 ? : 1 0 1
unless ($____nobble_checks) 0 1 1
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
338  
339 1 $str =~ s/:+/_/g;
340 1 $str =~ s/ +/_/g;
341  
342 1 my @a = split( /_/, $str );
343 1 my @b;
344 1 foreach my $a (@a) {
345 1 ▶ if ( $a eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a eq '') { } 0 1 1
346 0 push @b, '';
347 }
348 else {
349 1 push @b, split( /(?=[A-Z])/, $a );
350 }
351 }
352  
353 1 return lc join( '_', @b );
354 }
355  
356 8 ▶multi method snakeize (Str :$str!) {
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine snakeize: not called CC=14 SCAR=46.2
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'str'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"str"}) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
357
358 0 return $self->snakeize($str);
359 }
360  
361  
362 =head2 titleize
363  
364 Converts a string to title case.
365  
366 =over
367  
368 =item usage:
369  
370 $titleCase = $util->titleize($str);
371  
372 $titleCase = $util->titleize(str => $str);
373  
374 =item args:
375  
376 =over
377  
378 =item str [Str]
379  
380 The string to titleize.
381  
382 =back
383  
384 =back
385
386 =cut
387  
388 8 ▶multi method titleize (Str $str) {
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine titleize: called CC=9 SCAR=26.2
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 1 0 1
@_ ? : 1 0 1
unless ($____nobble_checks) 0 1 1
if @_ != 1 0 1 1
$#_ >= 0 ? : 1 0 1
unless ($____nobble_checks) 0 1 1
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
389  
390 1 return $self->pascalize($str);
391 }
392  
393 8 ▶multi method titleize (Str :$str!) {
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine titleize: not called CC=14 SCAR=46.2
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'str'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"str"}) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
394  
395 0 return $self->pascalize($str);
396 }
397  
398 =head2 trim
399  
400 Just a pass-through to String::Util::trim.
401  
402 =over
403  
404 =item usage:
405  
406 $trimmed = $util->trim($str);
407  
408 $trimmed = $util->trim(str => $str);
409  
410 =item args:
411  
412 =over
413  
414 =item str [Str]
415  
416 The string to trim.
417  
418 =back
419  
420 =back
421
422 =cut
423  
424 8 ▶multi method trim (Str $str) {
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine trim: called CC=9 SCAR=26.2
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 752 0 752
@_ ? : 752 0 752
unless ($____nobble_checks) 0 752 752
if @_ != 1 0 752 752
$#_ >= 0 ? : 752 0 752
unless ($____nobble_checks) 0 752 752
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
425  
426 752 return String::Util::trim($str);
427 }
428  
429 8 ▶multi method trim (Str :$str!) {
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine trim: not called CC=14 SCAR=46.2
Branch: 11 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'str'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"str"}) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
430
431 0 return $self->trim($str);
432 }
433  
434  
435 =head2 undefToString
436  
437 Convert scalar to a string if its value is undef. The string arg
438 is optional and defaults to ''.
439  
440 =over
441  
442 =item usage:
443  
444 $str = $util->undefToString($str);
445  
446 $str = $util->undefToString(str => $str);
447  
448 =item args:
449  
450 =over
451  
452 =item val [Str]
453  
454 The string to check for undef.
455  
456 =item str [Str]
457  
458 The string to replace undef with.
459  
460 =back
461  
462 =back
463
464 =cut
465  
466 multi method undefToString (Str|Undef $val,
467 8 ▶ Str $str = '' ) {
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine BEGIN: called CC=1 SCAR=0.6
Subroutine undefToString: called CC=14 SCAR=31.7
Branch: 12 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 3 0 3
@_ ? : 3 0 3
unless ($____nobble_checks) 0 3 3
if @_ < 1 0 3 3
if @_ > 2 0 3 3
$#_ >= 0 ? : 3 0 3
unless ($____nobble_checks) 0 3 3
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::AUTO::TC1($val) or _failed_check(47, "Str|Undef", $val, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 1 ? : 1 2 3
unless ($____nobble_checks) 0 3 3
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
468  
469 3 ▶ if ( !defined $val ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 2 1 3
470 2 return $str;
471 }
472  
473 1 return $val;
474 }
475  
476 multi method undefToString (Str|Undef :$val!,
477 8 ▶ Str :$str = '' ) {
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine BEGIN: called CC=1 SCAR=3.7
Subroutine undefToString: not called CC=17 SCAR=50.0
Branch: 14 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'val'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"val"}) 0 0 0
Type::Tiny::XS::AUTO::TC1($val) or _failed_check(48, "Str|Undef", $val, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'str'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
Type::Tiny::XS::Str($str) or _failed_check(9, "Str", $str, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
478  
479 0 return $self->undefToString($val, $str);
480 }
481
482 8 1;
« Medley/File/Zip.pm ↑ Summary Medley/Spawn.pm »