Articulate/Item.pm

filter: Statementstmt 73.9% 17 / 23 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod n/a totaltotal 70.5% 24 / 34 CC 2 SCAR 7.4
CC
2
Cov
68%
__ANON__
6.0
_meta_accessor
2.0
BEGIN
1.0
CRAP 2.1
« Articulate/Storage/DBIC/Simple.pm ↑ Summary Articulate/TestEnv.pm »
1 package Articulate::Item;
2 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶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 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<new> class
27 method, it is recommended that you construct items using
28 L<Articulate::Construction>, 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<Articulate::Location>). Coerces into a location using
40 C<Articulate::Location::new_location>.
41  
42 =cut
43  
44 has location => (
45 is => 'rw',
46 19 ▶ default => sub { Articulate::Location->new; },
Subroutine __ANON__: called CC=1 SCAR=0.0
47 49 ▶ coerce => sub { Articulate::Location::new_location(shift); }
Subroutine __ANON__: called CC=1 SCAR=0.0
48 12 );
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 24 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
59 12 );
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<Articulate::File> object.
66  
67 =cut
68  
69 has content => (
70 is => 'rw',
71 20 ▶ default => sub { '' },
Subroutine __ANON__: called CC=1 SCAR=0.0
72 12 );
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<Articulate::Syntax> to find or
86 assign the relevant field in the metadata.
87  
88 =cut
89  
90 0 ▶sub _meta_accessor {
Subroutine _meta_accessor: not called CC=1 SCAR=6.9
91 0 my $self = shift;
92 0 my $path = shift;
93 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
94 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
95 0 dpath_set( $self->meta, $path, @_ );
96 }
97 else {
98 0 dpath_get( $self->meta, $path );
99 }
100 }
101 0 }
102  
103 12 1;
« Articulate/Storage/DBIC/Simple.pm ↑ Summary Articulate/TestEnv.pm »