| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Articulate::Item; | 
| 2 | 12 |  |  | 12 |  | 93854 | use strict; | 
|  | 12 |  |  |  |  | 19 |  | 
|  | 12 |  |  |  |  | 401 |  | 
| 3 | 12 |  |  | 12 |  | 54 | use warnings; | 
|  | 12 |  |  |  |  | 21 |  | 
|  | 12 |  |  |  |  | 316 |  | 
| 4 | 12 |  |  | 12 |  | 2370 | use Moo; | 
|  | 12 |  |  |  |  | 49550 |  | 
|  | 12 |  |  |  |  | 70 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | =head1 NAME | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | Articulate::Item - represent an item | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | =cut | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | Articulate::Item->new( { | 
| 15 |  |  |  |  |  |  | meta     => {}, | 
| 16 |  |  |  |  |  |  | content  => 'Hello, World!', | 
| 17 |  |  |  |  |  |  | location => 'zone/public/article/hello-world', | 
| 18 |  |  |  |  |  |  | } ); | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | # Construction defaults to item if no better option is available | 
| 21 |  |  |  |  |  |  | Articulate::Construction->construct( { ... } ); | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | An item is a simple storage class for any sort of item which. Items | 
| 24 |  |  |  |  |  |  | have metadata, content, and a location. | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | Although it is acceptable to create items using the C class | 
| 27 |  |  |  |  |  |  | method, it is recommended that you construct items using | 
| 28 |  |  |  |  |  |  | L, which will be able to pick an appropriate | 
| 29 |  |  |  |  |  |  | subclass of item to construct based on the argument you supply, if you | 
| 30 |  |  |  |  |  |  | have configured it to do so. Such a subclass can have semantically | 
| 31 |  |  |  |  |  |  | appropriate methods available (see C<_meta_accessor> below for | 
| 32 |  |  |  |  |  |  | information on how to create these). | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =head1 ATTRIBUTES | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =head3 location | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | Returns the location of the item, as a location object (see | 
| 39 |  |  |  |  |  |  | L). Coerces into a location using | 
| 40 |  |  |  |  |  |  | C. | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =cut | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | has location => ( | 
| 45 |  |  |  |  |  |  | is      => 'rw', | 
| 46 |  |  |  |  |  |  | default => sub { Articulate::Location->new; }, | 
| 47 |  |  |  |  |  |  | coerce  => sub { Articulate::Location::new_location(shift); } | 
| 48 |  |  |  |  |  |  | ); | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | =head3 meta | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | Returns the item's metadata, as a hashref. | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | =cut | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | has meta => ( | 
| 57 |  |  |  |  |  |  | is      => 'rw', | 
| 58 |  |  |  |  |  |  | default => sub { {} }, | 
| 59 |  |  |  |  |  |  | ); | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =head3 content | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | Returns the item's content. What it might look like depends entirely on | 
| 64 |  |  |  |  |  |  | the content. Typically this is an unblessed scalar value, but it MAY | 
| 65 |  |  |  |  |  |  | contain binary data or an L object. | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | =cut | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | has content => ( | 
| 70 |  |  |  |  |  |  | is      => 'rw', | 
| 71 |  |  |  |  |  |  | default => sub { '' }, | 
| 72 |  |  |  |  |  |  | ); | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head1 METHOD | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | =head3 _meta_accessor | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | # In a subclass of Item | 
| 79 |  |  |  |  |  |  | sub author { shift->_meta_accessor('schema/article/author')->(@_) } | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | # Then, on that subclass | 
| 82 |  |  |  |  |  |  | $article->author('user/alice'); | 
| 83 |  |  |  |  |  |  | $article->author; | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | Uses dpath_set or dpath_get from L to find or | 
| 86 |  |  |  |  |  |  | assign the relevant field in the metadata. | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | =cut | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | sub _meta_accessor { | 
| 91 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 92 | 0 |  |  |  |  |  | my $path = shift; | 
| 93 |  |  |  |  |  |  | return sub { | 
| 94 | 0 | 0 |  | 0 |  |  | if (@_) { | 
| 95 | 0 |  |  |  |  |  | dpath_set( $self->meta, $path, @_ ); | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  | else { | 
| 98 | 0 |  |  |  |  |  | dpath_get( $self->meta, $path ); | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  | } | 
| 101 | 0 |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | 1; |