blib/lib/perl5i/1/SCALAR.pm

filter: Statementstmt 26.3% 24 / 91 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 21.7% 5 / 23 Podpod 0.0% 0 / 18 totaltotal 16.0% 29 / 181 SCAR 56.7
CC
22
Cov
18%
center
42.0
wrap
20.0
path2module
12.0
CRAP 289.7
« blib/lib/perl5i/2/ARRAY.pm ↑ Summary blib/lib/perl5i/1/DateTime.pm »
1 # vi: set ts=4 sw=4 ht=4 et :
2 package perl5i::1::SCALAR;
3 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 require Carp;
8 1 ▶use autobox;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use perl5i::1::autobox;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub title_case {
12 0 ▶ my ($string) = @_;
Subroutine title_case: not called CC=1 SCAR=6.9
Pod undocumented
13 0 $string =~ s/\b(\w)/\U$1/g;
14 0 return $string;
15 }
16  
17  
18 sub center {
19 0 ▶ my ($string, $size, $char) = @_;
Subroutine center: not called CC=6 SCAR=37.4
Pod undocumented
20 0 ▶ Carp::carp("Use of uninitialized value for size in center()") if !defined $size;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size 0 0 0
21 0 ▶ $size //= 0;
Condition0%0/2
$size //= 0
l!l
00
MC/DC0%0/1
$size //= 0
$size
Truth table0%0/2
A
A= $size
Aresult
11
00
22 0 ▶ $char //= ' ';
Condition0%0/2
$char //= " "
l!l
00
MC/DC0%0/1
$char //= " "
$char
Truth table0%0/2
A
A= $char
Aresult
11
00
23  
24 0 ▶ if (length $char > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $char > 1) 0 0 0
25 0 my $bad = $char;
26 0 $char = substr $char, 0, 1;
27 0 Carp::carp("'$bad' is longer than one character, using '$char' instead");
28 }
29  
30 0 my $len = length $string;
31  
32 0 ▶ return $string if $size <= $len;
Branch: 1 branch
BranchTrueFalseTotal
if $size <= $len 0 0 0
33  
34 0 my $padlen = $size - $len;
35  
36 # pad right with half the remaining characters
37 0 my $rpad = int( $padlen / 2 );
38  
39 # bias the left padding to one more space, if $size - $len is odd
40 0 my $lpad = $padlen - $rpad;
41  
42 0 return $char x $lpad . $string . $char x $rpad;
43 }
44  
45  
46 sub ltrim {
47 0 ▶ my ($string,$trim_charset) = @_;
Subroutine ltrim: not called CC=2 SCAR=17.9
Pod undocumented
48 0 ▶ $trim_charset = '\s' unless defined $trim_charset;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trim_charset 0 0 0
49 0 my $re = qr/^[$trim_charset]*/;
50 0 $string =~ s/$re//;
51 0 return $string;
52 }
53  
54  
55 sub rtrim {
56 0 ▶ my ($string,$trim_charset) = @_;
Subroutine rtrim: not called CC=2 SCAR=17.9
Pod undocumented
57 0 ▶ $trim_charset = '\s' unless defined $trim_charset;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trim_charset 0 0 0
58 0 my $re = qr/[$trim_charset]*$/;
59 0 $string =~ s/$re//;
60 0 return $string;
61 }
62  
63  
64 sub trim {
65 0 ▶ my $charset = $_[1];
Subroutine trim: not called CC=1 SCAR=6.9
Pod undocumented
66  
67 0 return rtrim(ltrim($_[0], $charset), $charset);
68 }
69  
70  
71 sub wrap {
72 0 ▶ my ($string, %args) = @_;
Subroutine wrap: not called CC=4 SCAR=30.0
Pod undocumented
73  
74 0 ▶ my $width = $args{width} // 76;
Condition0%0/2
$args{"width"} // 76
l!l
00
MC/DC0%0/1
$args{"width"} // 76
$args{"width"}
Truth table0%0/2
A
A= $args{"width"}
Aresult
11
00
75 0 ▶ my $separator = $args{separator} // "\n";
Condition0%0/2
$args{"separator"} // "\n"
l!l
00
MC/DC0%0/1
$args{"separator"} // "\n"
$args{"separator"}
Truth table0%0/2
A
A= $args{"separator"}
Aresult
11
00
76  
77 0 ▶ return $string if $width <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $width <= 0 0 0 0
78  
79 0 require Text::Wrap;
80 0 local $Text::Wrap::separator = $separator;
81 0 local $Text::Wrap::columns = $width;
82  
83 0 return Text::Wrap::wrap('', '', $string);
84  
85 }
86  
87  
88 # untaint the scalar itself, not the reference
89 sub untaint {
90 0 ▶ return $_[0]->mo->untaint if ref $_[0];
Subroutine untaint: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
91  
92 0 require Taint::Util;
93 0 Taint::Util::untaint($_[0]);
94 0 return 1;
95 }
96  
97  
98 # untaint the scalar itself, not the reference
99 sub taint {
100 0 ▶ return $_[0]->mo->taint if ref $_[0];
Subroutine taint: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
101  
102 0 require Taint::Util;
103 0 Taint::Util::taint($_[0]);
104 0 return 1;
105 }
106  
107 # Could use the version in Meta but this removes the need to check
108 # for overloading.
109 sub is_tainted {
110 0 ▶ require Taint::Util;
Subroutine is_tainted: not called CC=2 SCAR=17.9
Pod undocumented
111 0 ▶ return ref $_[0] ? Taint::Util::tainted(${$_[0]}) : Taint::Util::tainted($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
112 }
113  
114  
115 sub load {
116 0 ▶ require Module::Load;
Subroutine load: not called CC=1 SCAR=6.9
Pod undocumented
117 0 goto &Module::Load::load;
118 }
119  
120  
121 sub alias {
122 0 ▶ Carp::croak(<<ERROR) if !ref $_[0];
Subroutine alias: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 0 0 0
123 Due to limitations in autoboxing, scalars cannot be aliased.
124 Sorry. Use a scalar reference instead.
125 ERROR
126  
127 0 goto &perl5i::1::UNIVERSAL::alias;
128 }
129  
130  
131 1 require POSIX;
132 1 *ceil = \&POSIX::ceil;
133 1 *floor = \&POSIX::floor;
134 1 *round_up = \&ceil;
135 1 *round_down = \&floor;
136 sub round {
137 0 ▶ abs($_[0] - int($_[0])) < 0.5 ? round_down($_[0])
Subroutine round: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
abs $_[0] - int($_[0]) < 0.5 ? : 0 0 0
138 : round_up($_[0])
139 }
140  
141 1 require Scalar::Util;
142 1 *is_number = \&Scalar::Util::looks_like_number;
143 0 ▶sub is_positive { $_[0]->is_number && $_[0] > 0 }
Subroutine is_positive: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->is_number and $_[0] > 0 0 0 0
144 0 ▶sub is_negative { $_[0]->is_number && $_[0] < 0 }
Subroutine is_negative: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->is_number and $_[0] < 0 0 0 0
145 0 ▶sub is_integer { $_[0]->is_number && ((int($_[0]) - $_[0]) == 0) }
Subroutine is_integer: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->is_number and int($_[0]) - $_[0] == 0 0 0 0
146 1 *is_int = \&is_integer;
147 0 ▶sub is_decimal { $_[0]->is_number && ((int($_[0]) - $_[0]) != 0) }
Subroutine is_decimal: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->is_number and int($_[0]) - $_[0] != 0 0 0 0
148  
149  
150 sub path2module {
151 0 ▶ my $path = shift;
Subroutine path2module: not called CC=3 SCAR=24.8
Pod undocumented
152  
153 0 my($vol, $dirs, $file) = File::Spec->splitpath($path);
154 0 my @dirs = grep length, File::Spec->splitdir($dirs);
155  
156 0 ▶ Carp::croak("'$path' does not look like a Perl module path")
Branch: 1 branch
BranchTrueFalseTotal
if not $file =~ /\.pm$/ or "File::Spec"->file_name_is_absolute($path) 0 0 0
Condition0%0/3
not $file =~ /\.pm$/ or "File::Spec"->file_name_is_absolute($path)
l!l&&r!l&&!r
000
MC/DC0%0/2
not $file =~ /\.pm$/ or "File::Spec"->file_name_is_absolute($path)
not $file =~ /\.pm$/ "File::Spec"->file_name_is_absolute($path)
Truth table0%0/3
not(A) or B
A= not $file =~ /\.pm$/B= "File::Spec"->file_name_is_absolute($path)
ABresult
1X1
011
000
157 if $file !~ m{\.pm$} or File::Spec->file_name_is_absolute($path);
158  
159 0 $file =~ s{\.pm$}{};
160  
161 0 return join "::", @dirs, $file;
162 }
163  
164  
165 sub module2path {
166 0 ▶ my $module = shift;
Subroutine module2path: not called CC=1 SCAR=6.9
Pod undocumented
167  
168 0 my @parts = split /::/, $module;
169 0 $parts[-1] .= ".pm";
170  
171 0 return join "/", @parts;
172 }
173  
174 1 1;
« blib/lib/perl5i/2/ARRAY.pm ↑ Summary blib/lib/perl5i/1/DateTime.pm »