line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# vi: set ts=4 sw=4 ht=4 et : |
2
|
|
|
|
|
|
|
package perl5i::1::SCALAR; |
3
|
2
|
|
|
2
|
|
60
|
use 5.010; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
81
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
6
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
95
|
|
7
|
|
|
|
|
|
|
require Carp; |
8
|
2
|
|
|
2
|
|
12
|
use autobox; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
16
|
|
9
|
2
|
|
|
2
|
|
1195
|
use perl5i::1::autobox; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
79
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub title_case { |
12
|
0
|
|
|
0
|
0
|
|
my ($string) = @_; |
13
|
0
|
|
|
|
|
|
$string =~ s/\b(\w)/\U$1/g; |
14
|
0
|
|
|
|
|
|
return $string; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub center { |
19
|
0
|
|
|
0
|
0
|
|
my ($string, $size, $char) = @_; |
20
|
0
|
0
|
|
|
|
|
Carp::carp("Use of uninitialized value for size in center()") if !defined $size; |
21
|
0
|
|
0
|
|
|
|
$size //= 0; |
22
|
0
|
|
0
|
|
|
|
$char //= ' '; |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
if (length $char > 1) { |
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
|
0
|
|
|
|
|
return $string if $size <= $len; |
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
|
|
|
0
|
0
|
|
my ($string,$trim_charset) = @_; |
48
|
0
|
0
|
|
|
|
|
$trim_charset = '\s' unless defined $trim_charset; |
49
|
0
|
|
|
|
|
|
my $re = qr/^[$trim_charset]*/; |
50
|
0
|
|
|
|
|
|
$string =~ s/$re//; |
51
|
0
|
|
|
|
|
|
return $string; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub rtrim { |
56
|
0
|
|
|
0
|
0
|
|
my ($string,$trim_charset) = @_; |
57
|
0
|
0
|
|
|
|
|
$trim_charset = '\s' unless defined $trim_charset; |
58
|
0
|
|
|
|
|
|
my $re = qr/[$trim_charset]*$/; |
59
|
0
|
|
|
|
|
|
$string =~ s/$re//; |
60
|
0
|
|
|
|
|
|
return $string; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub trim { |
65
|
0
|
|
|
0
|
0
|
|
my $charset = $_[1]; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return rtrim(ltrim($_[0], $charset), $charset); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub wrap { |
72
|
0
|
|
|
0
|
0
|
|
my ($string, %args) = @_; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
0
|
|
|
|
my $width = $args{width} // 76; |
75
|
0
|
|
0
|
|
|
|
my $separator = $args{separator} // "\n"; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
return $string if $width <= 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
|
0
|
|
0
|
0
|
|
return $_[0]->mo->untaint if ref $_[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
|
0
|
|
0
|
0
|
|
return $_[0]->mo->taint if ref $_[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
|
|
|
0
|
0
|
|
require Taint::Util; |
111
|
0
|
0
|
|
|
|
|
return ref $_[0] ? Taint::Util::tainted(${$_[0]}) : Taint::Util::tainted($_[0]); |
|
0
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub load { |
116
|
0
|
|
|
0
|
0
|
|
require Module::Load; |
117
|
0
|
|
|
|
|
|
goto &Module::Load::load; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub alias { |
122
|
0
|
0
|
|
0
|
0
|
|
Carp::croak(<
|
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
|
|
|
|
|
|
|
require POSIX; |
132
|
|
|
|
|
|
|
*ceil = \&POSIX::ceil; |
133
|
|
|
|
|
|
|
*floor = \&POSIX::floor; |
134
|
|
|
|
|
|
|
*round_up = \&ceil; |
135
|
|
|
|
|
|
|
*round_down = \&floor; |
136
|
|
|
|
|
|
|
sub round { |
137
|
0
|
0
|
|
0
|
0
|
|
abs($_[0] - int($_[0])) < 0.5 ? round_down($_[0]) |
138
|
|
|
|
|
|
|
: round_up($_[0]) |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
require Scalar::Util; |
142
|
|
|
|
|
|
|
*is_number = \&Scalar::Util::looks_like_number; |
143
|
0
|
0
|
|
0
|
0
|
|
sub is_positive { $_[0]->is_number && $_[0] > 0 } |
144
|
0
|
0
|
|
0
|
0
|
|
sub is_negative { $_[0]->is_number && $_[0] < 0 } |
145
|
0
|
0
|
|
0
|
0
|
|
sub is_integer { $_[0]->is_number && ((int($_[0]) - $_[0]) == 0) } |
146
|
|
|
|
|
|
|
*is_int = \&is_integer; |
147
|
0
|
0
|
|
0
|
0
|
|
sub is_decimal { $_[0]->is_number && ((int($_[0]) - $_[0]) != 0) } |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub path2module { |
151
|
0
|
|
|
0
|
0
|
|
my $path = shift; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my($vol, $dirs, $file) = File::Spec->splitpath($path); |
154
|
0
|
|
|
|
|
|
my @dirs = grep length, File::Spec->splitdir($dirs); |
155
|
|
|
|
|
|
|
|
156
|
0
|
0
|
0
|
|
|
|
Carp::croak("'$path' does not look like a Perl module path") |
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
|
|
|
0
|
0
|
|
my $module = shift; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
my @parts = split /::/, $module; |
169
|
0
|
|
|
|
|
|
$parts[-1] .= ".pm"; |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
return join "/", @parts; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |