line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Articulate::Item; |
2
|
10
|
|
|
10
|
|
82163
|
use strict; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
322
|
|
3
|
10
|
|
|
10
|
|
42
|
use warnings; |
|
10
|
|
|
|
|
12
|
|
|
10
|
|
|
|
|
255
|
|
4
|
10
|
|
|
10
|
|
2159
|
use Moo; |
|
10
|
|
|
|
|
54428
|
|
|
10
|
|
|
|
|
98
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Articulate::Item - represent an item |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=cut |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 METHODS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head3 location |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Returns the location of the item, as a location object (see L). Coerces into a location using C. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has location => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
default => sub { Articulate::Location->new; }, |
23
|
|
|
|
|
|
|
coerce => sub { Articulate::Location::loc(shift); } |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head3 meta |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Returns the item's metadata, as a hashref. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has meta => ( |
33
|
|
|
|
|
|
|
is => 'rw', |
34
|
|
|
|
|
|
|
default => sub { {} }, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head3 content |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Returns the item's content. What it might look like depends entirely on the content. Typically this is an unblessed scalar value, but it MAY contain binary data or an L object. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has content => ( |
44
|
|
|
|
|
|
|
is => 'rw', |
45
|
|
|
|
|
|
|
default => sub { '' }, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head3 _meta_accessor |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# In a subclass of Item |
51
|
|
|
|
|
|
|
sub author { shift->meta_accessor('schema/article/author')->(@_) } |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Then, on that subclass |
54
|
|
|
|
|
|
|
$article->author('user/alice'); |
55
|
|
|
|
|
|
|
$article->author; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Uses dpath_set or dpath_get from L to find or assign the relevant field in the metadata. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _meta_accessor { |
62
|
0
|
|
|
0
|
|
|
my $self = shift; |
63
|
0
|
|
|
|
|
|
my $path = shift; |
64
|
|
|
|
|
|
|
return sub { |
65
|
0
|
0
|
|
0
|
|
|
if (@_) { |
66
|
0
|
|
|
|
|
|
dpath_set ($self->meta, $path, @_) |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else { |
69
|
0
|
|
|
|
|
|
dpath_get ($self->meta, $path) |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |