line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: String Object Role for Perl 5 |
2
|
|
|
|
|
|
|
package Data::Object::Role::String; |
3
|
|
|
|
|
|
|
|
4
|
49
|
|
|
49
|
|
348269
|
use 5.010; |
|
49
|
|
|
|
|
173
|
|
5
|
49
|
|
|
49
|
|
14491
|
use Data::Object::Role; |
|
49
|
|
|
|
|
116
|
|
|
49
|
|
|
|
|
463
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
map with($_), our @ROLES = qw( |
8
|
|
|
|
|
|
|
Data::Object::Role::Defined |
9
|
|
|
|
|
|
|
Data::Object::Role::Detract |
10
|
|
|
|
|
|
|
Data::Object::Role::Output |
11
|
|
|
|
|
|
|
Data::Object::Role::Type |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.42'; # VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub append { |
17
|
1
|
|
|
1
|
0
|
53
|
return join ' ', @_; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub camelcase { |
21
|
2
|
|
|
2
|
0
|
4
|
my ($string) = @_; |
22
|
2
|
|
|
|
|
55
|
$string = CORE::ucfirst(CORE::lc("$string")); |
23
|
2
|
|
|
|
|
16
|
$string =~ s/[^a-zA-Z0-9]+([a-z])/\U$1/g; |
24
|
2
|
|
|
|
|
5
|
$string =~ s/[^a-zA-Z0-9]+//g; |
25
|
2
|
|
|
|
|
7
|
return $string; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub chomp { |
29
|
1
|
|
|
1
|
0
|
3
|
my ($string) = @_; |
30
|
1
|
50
|
|
|
|
48
|
CORE::chomp $string and return $string; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub chop { |
34
|
1
|
|
|
1
|
0
|
2
|
my ($string) = @_; |
35
|
1
|
50
|
|
|
|
50
|
CORE::chop $string and return $string; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub concat { |
39
|
1
|
|
|
1
|
0
|
3
|
my ($string, @args) = @_; |
40
|
1
|
|
|
|
|
56
|
return join '', $string, @args; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub contains { |
44
|
4
|
|
|
4
|
0
|
6
|
my ($string, $pattern) = @_; |
45
|
|
|
|
|
|
|
|
46
|
4
|
100
|
|
|
|
18
|
return ($string =~ $pattern) ? 1 : 0 |
|
|
100
|
|
|
|
|
|
47
|
|
|
|
|
|
|
if 'Regexp' eq ref $pattern; |
48
|
|
|
|
|
|
|
|
49
|
2
|
100
|
|
|
|
62
|
return index($string, $pattern) < 0 ? 0 : 1 |
|
|
50
|
|
|
|
|
|
50
|
|
|
|
|
|
|
if defined $pattern; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
return 0; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub hex { |
56
|
1
|
|
|
1
|
0
|
3
|
my ($string) = @_; |
57
|
1
|
|
|
|
|
50
|
return CORE::hex $string; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub index { |
61
|
6
|
|
|
6
|
0
|
10
|
my ($string, $substr, $start) = @_; |
62
|
6
|
100
|
|
|
|
66
|
return CORE::index $string, $substr if not defined $start; |
63
|
4
|
|
|
|
|
14
|
return CORE::index $string, $substr, $start; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub lc { |
67
|
2
|
|
|
2
|
0
|
6
|
my ($string) = @_; |
68
|
2
|
|
|
|
|
105
|
return CORE::lc $string; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub lcfirst { |
72
|
1
|
|
|
1
|
0
|
2
|
my ($string) = @_; |
73
|
1
|
|
|
|
|
63
|
return CORE::lcfirst $string; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub length { |
77
|
1
|
|
|
1
|
0
|
3
|
my ($string) = @_; |
78
|
1
|
|
|
|
|
58
|
return CORE::length $string; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub lines { |
82
|
1
|
|
|
1
|
0
|
3
|
my ($string) = @_; |
83
|
1
|
|
|
|
|
50
|
return [CORE::split /\n+/, $string]; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub lowercase { |
87
|
1
|
|
|
1
|
0
|
6
|
goto &lc |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub replace { |
91
|
4
|
|
|
4
|
0
|
5
|
my ($self, $find, $replace, $flags) = @_; |
92
|
4
|
100
|
|
|
|
11
|
$flags = defined $flags ? $flags : ''; |
93
|
4
|
100
|
66
|
|
|
19
|
$find = quotemeta $find if $find and 'Regexp' ne ref $find; |
94
|
|
|
|
|
|
|
|
95
|
4
|
|
|
|
|
6
|
local $@; |
96
|
4
|
|
|
|
|
312
|
eval("sub { \$_[0] =~ s/$find/$replace/$flags }")->($self); |
97
|
|
|
|
|
|
|
|
98
|
4
|
|
|
|
|
35
|
return $self; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub reverse { |
102
|
1
|
|
|
1
|
0
|
3
|
my ($string) = @_; |
103
|
1
|
|
|
|
|
58
|
return CORE::reverse $string; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub rindex { |
107
|
10
|
|
|
10
|
0
|
18
|
my ($string, $substr, $start) = @_; |
108
|
10
|
100
|
|
|
|
74
|
return CORE::rindex $string, $substr if not defined $start; |
109
|
8
|
|
|
|
|
34
|
return CORE::rindex $string, $substr, $start; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub snakecase { |
113
|
1
|
|
|
1
|
0
|
2
|
my ($string) = @_; |
114
|
1
|
|
|
|
|
50
|
$string = CORE::lc("$string"); |
115
|
1
|
|
|
|
|
10
|
$string =~ s/[^a-zA-Z0-9]+([a-z])/\U$1/g; |
116
|
1
|
|
|
|
|
3
|
$string =~ s/[^a-zA-Z0-9]+//g; |
117
|
1
|
|
|
|
|
3
|
return $string; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub split { |
121
|
5
|
|
|
5
|
0
|
7
|
my ($string, $pattern, $limit) = @_; |
122
|
5
|
100
|
100
|
|
|
25
|
$pattern = quotemeta $pattern if $pattern and !ref $pattern; |
123
|
5
|
100
|
|
|
|
160
|
return [CORE::split /$pattern/, $string] if !defined $limit; |
124
|
2
|
|
|
|
|
93
|
return [CORE::split /$pattern/, $string, $limit]; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub strip { |
128
|
1
|
|
|
1
|
0
|
2
|
my ($string) = @_; |
129
|
1
|
50
|
|
|
|
52
|
$string =~ s/\s{2,}/ /g and return $string; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub titlecase { |
133
|
1
|
|
|
1
|
0
|
2
|
my ($string) = @_; |
134
|
1
|
50
|
|
|
|
46
|
$string =~ s/\b(\w)/\U$1/g and return $string; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub trim { |
138
|
1
|
|
|
1
|
0
|
4
|
my ($string) = @_; |
139
|
1
|
50
|
|
|
|
51
|
$string =~ s/^\s+|\s+$//g and return $string; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub uc { |
143
|
2
|
|
|
2
|
0
|
3
|
my ($string) = @_; |
144
|
2
|
|
|
|
|
99
|
return CORE::uc $string; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub ucfirst { |
148
|
1
|
|
|
1
|
0
|
2
|
my ($string) = @_; |
149
|
1
|
|
|
|
|
48
|
return CORE::ucfirst $string; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub uppercase { |
153
|
1
|
|
|
1
|
0
|
6
|
goto &uc; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub words { |
157
|
1
|
|
|
1
|
0
|
2
|
my ($string) = @_; |
158
|
1
|
|
|
|
|
48
|
return [CORE::split /\s+/, $string]; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
__END__ |