line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Articulate::Location; |
2
|
12
|
|
|
12
|
|
28576
|
use strict; |
|
12
|
|
|
|
|
17
|
|
|
12
|
|
|
|
|
383
|
|
3
|
12
|
|
|
12
|
|
52
|
use warnings; |
|
12
|
|
|
|
|
19
|
|
|
12
|
|
|
|
|
448
|
|
4
|
|
|
|
|
|
|
|
5
|
12
|
|
|
12
|
|
763
|
use Moo; |
|
12
|
|
|
|
|
16334
|
|
|
12
|
|
|
|
|
63
|
|
6
|
12
|
|
|
12
|
|
4392
|
use Scalar::Util qw(blessed); |
|
12
|
|
|
|
|
18
|
|
|
12
|
|
|
|
|
1184
|
|
7
|
12
|
|
|
12
|
|
1754
|
use overload '""' => sub { shift->to_file_path }, '@{}' => sub { shift->path }; |
|
12
|
|
|
553
|
|
1221
|
|
|
12
|
|
|
198
|
|
135
|
|
|
266
|
|
|
|
|
1141
|
|
|
555
|
|
|
|
|
1640
|
|
8
|
|
|
|
|
|
|
|
9
|
12
|
|
|
12
|
|
1460
|
use Exporter::Declare; |
|
12
|
|
|
|
|
27170
|
|
|
12
|
|
|
|
|
82
|
|
10
|
|
|
|
|
|
|
default_exports qw(new_location); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Articulate::Location - represent an item's location |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
new_location ['zone', 'public', 'article', 'hello-world'] |
21
|
|
|
|
|
|
|
new_location 'zone/public/article/hello-world' # same thing |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
An object class which represents an item's location within the |
24
|
|
|
|
|
|
|
Articulate ecosystem. It contains an array of slugs, and stringifies to |
25
|
|
|
|
|
|
|
the 'file path' representation of them. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 FUNCTIONS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head3 new_location |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
C is a constructor. It takes either a string (in the form |
34
|
|
|
|
|
|
|
of a path) or an arrayref. Either will be stored as an arrayref in the |
35
|
|
|
|
|
|
|
C attribute. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub new_location { |
40
|
311
|
50
|
|
311
|
1
|
13399
|
if ( 1 == scalar @_ ) { |
41
|
311
|
100
|
66
|
|
|
2144
|
if ( blessed $_[0] and $_[0]->can('location') ) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
42
|
270
|
|
|
|
|
828
|
return $_[0]; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif ( ref $_[0] eq 'ARRAY' ) { |
45
|
0
|
|
|
|
|
0
|
return __PACKAGE__->new( { path => $_[0] } ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif ( !defined $_[0] ) { |
48
|
0
|
|
|
|
|
0
|
return __PACKAGE__->new; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif ( !ref $_[0] ) { |
51
|
148
|
|
|
|
|
1190
|
return __PACKAGE__->new( |
52
|
41
|
|
|
|
|
176
|
{ path => [ grep { $_ ne '' } split /\//, $_[0] ] } ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif ( ref $_[0] eq 'HASH' ) { |
55
|
0
|
|
|
|
|
0
|
return __PACKAGE__->new( $_[0] ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 ATTRIBUTE |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head3 path |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
An arrayref representing the path to the location. This is how the |
65
|
|
|
|
|
|
|
location is actually stored and is used for overloaded array |
66
|
|
|
|
|
|
|
dereferencing. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
has path => ( |
71
|
|
|
|
|
|
|
is => 'rw', |
72
|
|
|
|
|
|
|
default => sub { []; }, |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 METHODS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head3 location |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$location->location->location # same as $location |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This method always returns the object itself. It is useful when you |
82
|
|
|
|
|
|
|
want to allow either an Item or a Location as an argument. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub location { |
87
|
57
|
|
|
57
|
1
|
100
|
return shift; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head3 to_file_path |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Joins the contents of C on C> and returns the result. This is |
93
|
|
|
|
|
|
|
used for overloaded stringification. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub to_file_path { |
98
|
266
|
|
|
266
|
1
|
218
|
return join '/', @{ $_[0]->path }; |
|
266
|
|
|
|
|
1301
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 SEE ALSO |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=over |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * L |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item * L |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item * L |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=back |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |