| 1 | package Articulate::Item; | ||||||||||
| 2 | 10 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 10 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 10 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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<Articulate::Location>). Coerces into a location using C<Articulate::Location::loc>. | ||||||||||
| 17 | |||||||||||
| 18 | =cut | ||||||||||
| 19 | |||||||||||
| 20 | has location => ( | ||||||||||
| 21 | is => 'rw', | ||||||||||
| 22 | 16 | ▶ | default => sub { Articulate::Location->new; }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 46 | ▶ | coerce => sub { Articulate::Location::loc(shift); } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 10 | ); | |||||||||
| 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 | 24 | ▶ | default => sub { {} }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 35 | 10 | ); | |||||||||
| 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<Articulate::File> object. | ||||||||||
| 40 | |||||||||||
| 41 | =cut | ||||||||||
| 42 | |||||||||||
| 43 | has content => ( | ||||||||||
| 44 | is => 'rw', | ||||||||||
| 45 | 20 | ▶ | default => sub { '' }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 10 | ); | |||||||||
| 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<Atticulate::Syntax> to find or assign the relevant field in the metadata. | ||||||||||
| 58 | |||||||||||
| 59 | =cut | ||||||||||
| 60 | |||||||||||
| 61 | sub _meta_accessor { | ||||||||||
| 62 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_meta_accessor: not called CC=1 SCAR=6.9
| |||||||||||
| 63 | 0 | my $path = shift; | |||||||||
| 64 | return sub { | ||||||||||
| 65 | 0 | ▶ | if (@_) { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||
| 66 | 0 | dpath_set ($self->meta, $path, @_) | |||||||||
| 67 | } | ||||||||||
| 68 | else { | ||||||||||
| 69 | 0 | dpath_get ($self->meta, $path) | |||||||||
| 70 | } | ||||||||||
| 71 | } | ||||||||||
| 72 | 0 | } | |||||||||
| 73 | |||||||||||
| 74 | |||||||||||
| 75 | 10 | 1; | |||||||||