line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Object::Name; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
39753
|
use 5.014; |
|
1
|
|
|
|
|
4
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
20
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
41
|
|
7
|
1
|
|
|
1
|
|
7
|
use routines; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '2.02'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# BUILD |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $sep = qr/'|__|::|\\|\//; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# METHODS |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
1
|
8
|
method dist() { |
|
1
|
|
|
|
|
2
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
5
|
return $self->label =~ s/_/-/gr; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
1
|
7
|
method file() { |
|
2
|
|
|
|
|
3
|
|
23
|
2
|
50
|
|
|
|
7
|
return $$self if $self->lookslike_a_file; |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
7
|
my $string = $self->package; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return join '__', map { |
28
|
2
|
|
|
|
|
11
|
join '_', map {lc} map {split /_/} grep {length} |
|
4
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
27
|
|
|
6
|
|
|
|
|
19
|
|
|
12
|
|
|
|
|
18
|
|
29
|
|
|
|
|
|
|
split /([A-Z]{1}[^A-Z]*)/ |
30
|
|
|
|
|
|
|
} split /$sep/, $string; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
1
|
6
|
method format($method, $format) { |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
34
|
1
|
|
|
|
|
4
|
my $string = $self->$method; |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
50
|
|
|
15
|
return sprintf($format || '%s', $string); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
2
|
1
|
9
|
method label() { |
|
2
|
|
|
|
|
4
|
|
40
|
2
|
50
|
|
|
|
6
|
return $$self if $self->lookslike_a_label; |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
10
|
return join '_', split /$sep/, $self->package; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
3
|
|
|
3
|
1
|
7
|
method lookslike_a_file() { |
|
3
|
|
|
|
|
6
|
|
46
|
3
|
|
|
|
|
5
|
my $string = $$self; |
47
|
|
|
|
|
|
|
|
48
|
3
|
|
|
|
|
22
|
return $string =~ /^[a-z](?:\w*[a-z])?$/; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
3
|
|
|
3
|
1
|
9
|
method lookslike_a_label() { |
|
3
|
|
|
|
|
6
|
|
52
|
3
|
|
|
|
|
13
|
my $string = $$self; |
53
|
|
|
|
|
|
|
|
54
|
3
|
|
|
|
|
27
|
return $string =~ /^[A-Z](?:\w*[a-zA-Z0-9])?$/; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
6
|
|
|
6
|
1
|
14
|
method lookslike_a_package() { |
|
6
|
|
|
|
|
19
|
|
58
|
6
|
|
|
|
|
18
|
my $string = $$self; |
59
|
|
|
|
|
|
|
|
60
|
6
|
|
|
|
|
47
|
return $string =~ /^[A-Z](?:(?:\w|::)*[a-zA-Z0-9])?$/; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
2
|
|
|
2
|
1
|
10
|
method lookslike_a_path() { |
|
2
|
|
|
|
|
5
|
|
64
|
2
|
|
|
|
|
5
|
my $string = $$self; |
65
|
|
|
|
|
|
|
|
66
|
2
|
|
|
|
|
38
|
return $string =~ /^[A-Z](?:(?:\w|\\|\/|[\:\.]{1}[a-zA-Z0-9])*[a-zA-Z0-9])?$/; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
12
|
100
|
|
12
|
1
|
131104
|
method new($class: $name = '') { |
|
12
|
|
|
|
|
60
|
|
|
12
|
|
|
|
|
19
|
|
70
|
|
|
|
|
|
|
|
71
|
12
|
|
|
|
|
254
|
return bless \$name, $class; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
5
|
|
|
5
|
1
|
16
|
method package() { |
|
5
|
|
|
|
|
9
|
|
75
|
5
|
50
|
|
|
|
14
|
return $$self if $self->lookslike_a_package; |
76
|
|
|
|
|
|
|
|
77
|
5
|
|
|
|
|
11
|
my $string = $$self; |
78
|
|
|
|
|
|
|
|
79
|
5
|
50
|
|
|
|
36
|
if ($string !~ $sep) { |
80
|
0
|
|
|
|
|
0
|
return join '', map {ucfirst} split /[^a-zA-Z0-9]/, $string; |
|
0
|
|
|
|
|
0
|
|
81
|
|
|
|
|
|
|
} else { |
82
|
|
|
|
|
|
|
return join '::', map { |
83
|
5
|
|
|
|
|
31
|
join '', map {ucfirst} split /[^a-zA-Z0-9]/ |
|
10
|
|
|
|
|
27
|
|
|
10
|
|
|
|
|
82
|
|
84
|
|
|
|
|
|
|
} split /$sep/, $string; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
1
|
1
|
18
|
method path() { |
|
1
|
|
|
|
|
3
|
|
89
|
1
|
50
|
|
|
|
3
|
return $$self if $self->lookslike_a_path; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return join '/', split /$sep/, $self->package; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=encoding utf8 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Data::Object::Name |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 ABSTRACT |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Name Class for Perl 5 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SYNOPSIS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
use Data::Object::Name; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $name = Data::Object::Name->new('FooBar/Baz'); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 DESCRIPTION |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This package provides methods for converting "name" strings. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 METHODS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This package implements the following methods: |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 dist |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
dist() : Str |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
The dist method returns a package distribution representation of the name. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=over 4 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item dist example #1 |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# given: synopsis |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
my $dist = $name->dist; # FooBar-Baz |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=back |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 file |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
file() : Str |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
The file method returns a file representation of the name. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=over 4 |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item file example #1 |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# given: synopsis |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
my $file = $name->file; # foo_bar__baz |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=back |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 format |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
format(Str $method, Str $format) : Str |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
The format method calls the specified method passing the result to the core |
171
|
|
|
|
|
|
|
L</sprintf> function with itself as an argument. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=over 4 |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item format example #1 |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# given: synopsis |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
my $file = $name->format('file', '%s.t'); # foo_bar__baz.t |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=back |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 label |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
label() : Str |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
The label method returns a label (or constant) representation of the name. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=over 4 |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item label example #1 |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# given: synopsis |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
my $label = $name->label; # FooBar_Baz |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=back |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 lookslike_a_file |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
lookslike_a_file() : Bool |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
The lookslike_a_file method returns truthy if its state resembles a filename. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=over 4 |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item lookslike_a_file example #1 |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
# given: synopsis |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
my $is_file = $name->lookslike_a_file; # falsey |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=back |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 lookslike_a_label |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
lookslike_a_label() : Bool |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
The lookslike_a_label method returns truthy if its state resembles a label (or |
226
|
|
|
|
|
|
|
constant). |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=over 4 |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item lookslike_a_label example #1 |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# given: synopsis |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
my $is_label = $name->lookslike_a_label; # falsey |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=back |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head2 lookslike_a_package |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
lookslike_a_package() : Bool |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
The lookslike_a_package method returns truthy if its state resembles a package |
245
|
|
|
|
|
|
|
name. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=over 4 |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=item lookslike_a_package example #1 |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
# given: synopsis |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
my $is_package = $name->lookslike_a_package; # falsey |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=back |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=cut |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head2 lookslike_a_path |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
lookslike_a_path() : Bool |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
The lookslike_a_path method returns truthy if its state resembles a file path. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=over 4 |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item lookslike_a_path example #1 |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
# given: synopsis |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
my $is_path = $name->lookslike_a_path; # truthy |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=back |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=cut |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=head2 new |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
new(Str $arg) : Object |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
The new method instantiates the class and returns an object. |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=over 4 |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=item new example #1 |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
use Data::Object::Name; |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
my $name = Data::Object::Name->new; |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=back |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=over 4 |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=item new example #2 |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
use Data::Object::Name; |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
my $name = Data::Object::Name->new('FooBar'); |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=back |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=cut |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=head2 package |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
package() : Str |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
The package method returns a package name representation of the name given. |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=over 4 |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=item package example #1 |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
# given: synopsis |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
my $package = $name->package; # FooBar::Baz |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=back |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=cut |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=head2 path |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
path() : Str |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
The path method returns a path representation of the name. |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=over 4 |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=item path example #1 |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
# given: synopsis |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
my $path = $name->path; # FooBar/Baz |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
=back |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=cut |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
=head1 AUTHOR |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
Al Newkirk, C<awncorp@cpan.org> |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=head1 LICENSE |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
Copyright (C) 2011-2019, Al Newkirk, et al. |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under the terms |
350
|
|
|
|
|
|
|
of the The Apache License, Version 2.0, as elucidated in the L<"license |
351
|
|
|
|
|
|
|
file"|https://github.com/iamalnewkirk/data-object-name/blob/master/LICENSE>. |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
=head1 PROJECT |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
L<Wiki|https://github.com/iamalnewkirk/data-object-name/wiki> |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
L<Project|https://github.com/iamalnewkirk/data-object-name> |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
L<Initiatives|https://github.com/iamalnewkirk/data-object-name/projects> |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
L<Milestones|https://github.com/iamalnewkirk/data-object-name/milestones> |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
L<Contributing|https://github.com/iamalnewkirk/data-object-name/blob/master/CONTRIBUTE.md> |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
L<Issues|https://github.com/iamalnewkirk/data-object-name/issues> |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
=cut |