line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Util::Underscore::Scalars; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#ABSTRACT: Functions for introspecting and manipulating scalars |
4
|
|
|
|
|
|
|
|
5
|
12
|
|
|
12
|
|
39
|
use strict; |
|
12
|
|
|
|
|
14
|
|
|
12
|
|
|
|
|
256
|
|
6
|
12
|
|
|
12
|
|
35
|
use warnings; |
|
12
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
6473
|
|
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
|
|
|
|
|
|
|
$Util::Underscore::_ASSIGN_ALIASES->('Scalar::Util', new_dual => 'dualvar'); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub is_dual(_) { |
19
|
4
|
|
|
4
|
|
103653
|
goto &Scalar::Util::isdual; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub is_vstring(_) { |
23
|
7
|
|
|
7
|
|
2335
|
goto &Scalar::Util::isvstring; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub is_readonly(_) { |
27
|
8
|
|
|
8
|
|
4911
|
goto &Scalar::Util::readonly; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
## no critic (ProtectPrivateVars) |
31
|
|
|
|
|
|
|
$Util::Underscore::_ASSIGN_ALIASES->('Const::Fast', const => 'const'); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub is_tainted (_) { |
34
|
4
|
|
|
4
|
|
7835
|
goto &Scalar::Util::tainted; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
12
|
|
|
12
|
|
2139
|
if (eval q{use Data::Alias 1.18 (); 1}) { ## no critic (ProhibitStringyEval) |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
38
|
|
|
|
|
|
|
## no critic (ProtectPrivateVars) |
39
|
|
|
|
|
|
|
$Util::Underscore::_ASSIGN_ALIASES->('Data::Alias', alias => 'alias'); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub is_plain(_) { |
43
|
7
|
100
|
|
7
|
|
3125
|
defined $_[0] |
44
|
|
|
|
|
|
|
&& !defined ref_type $_[0]; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub is_string(_) { |
48
|
27
|
100
|
100
|
27
|
|
4231
|
defined $_[0] |
49
|
|
|
|
|
|
|
&& (!defined ref_type $_[0] |
50
|
|
|
|
|
|
|
|| overload::Method($_[0], q[""])); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub is_bool(_) { |
54
|
10
|
100
|
|
10
|
|
3441
|
!defined ref_type $_[0] |
55
|
|
|
|
|
|
|
|| overload::Method($_[0], q[bool]); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub is_identifier(_) { |
59
|
11
|
100
|
|
11
|
|
1965
|
defined $_[0] |
60
|
|
|
|
|
|
|
&& scalar($_[0] =~ /\A [^\W\d]\w* \z/xsm); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub is_package(_) { |
64
|
25
|
100
|
|
25
|
|
2642
|
defined $_[0] |
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
|
|
|
8
|
|
3001
|
local $/ = $/; |
72
|
8
|
100
|
|
|
|
19
|
if (@_ > 1) { |
73
|
4
|
50
|
|
|
|
11
|
if (_::is_string $_[1]) { |
74
|
4
|
|
|
|
|
10
|
$/ = "$_[1]"; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
else { |
77
|
0
|
|
|
|
|
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
|
100
|
|
|
|
11
|
if (_::is_string $_[0]) { |
|
|
50
|
|
|
|
|
|
84
|
4
|
|
|
|
|
9
|
CORE::chomp(my $copy = $_[0]); |
85
|
4
|
|
|
|
|
16
|
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
|
|
|
|
|
2
|
my @result = @{ $_[0] }; |
|
4
|
|
|
|
|
8
|
|
92
|
4
|
|
|
|
|
9
|
for (@result) { |
93
|
8
|
50
|
|
|
|
7
|
goto ERROR if not _::is_string; |
94
|
8
|
|
|
|
|
12
|
CORE::chomp; |
95
|
|
|
|
|
|
|
} |
96
|
4
|
|
|
|
|
16
|
return \@result; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
ERROR: |
100
|
0
|
|
|
|
|
0
|
Carp::croak |
101
|
|
|
|
|
|
|
q(_::chomp: first argument must be string or arrayref of strings); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub index($$;$) { |
105
|
7
|
50
|
66
|
7
|
|
1637
|
if (@_ >= 3 and $_[2] < 0) { |
106
|
0
|
|
|
|
|
0
|
Carp::croak q(_::index: starting position must be non-negative.) |
107
|
|
|
|
|
|
|
} |
108
|
7
|
|
100
|
|
|
25
|
my $result = CORE::index($_[0], $_[1], $_[2] // 0); |
109
|
7
|
100
|
|
|
|
26
|
return ($result >= 0) ? $result : undef; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |