File Coverage

blib/lib/Articulate/Construction.pm
Criterion Covered Total %
statement 22 23 95.6
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 30 32 93.7


line stmt bran cond sub pod time code
1             package Articulate::Construction;
2 6     6   3133 use strict;
  6         12  
  6         193  
3 6     6   26 use warnings;
  6         10  
  6         126  
4              
5 6     6   23 use Moo;
  6         7  
  6         27  
6 6     6   1420 use Articulate::Syntax qw(instantiate_array);
  6         10  
  6         44  
7 6     6   1425 use Articulate::Item;
  6         12  
  6         892  
8              
9             with 'Articulate::Role::Component';
10              
11             =head1 NAME
12              
13             Articulate::Construction - create appropriate content item objects
14             given location, meta, content.
15              
16             =cut
17              
18             =head1 CONFIGURATION
19              
20             components:
21             construction:
22             Articulate::Construction:
23             constructors:
24             - Articulate::Construction::LocationBased
25              
26             =head1 ATTRIBUTE
27              
28             =head3 constructors
29              
30             A list of classes which can be used to construct items.
31              
32             =cut
33              
34             has constructors => (
35             is => 'rw',
36             default => sub { [] },
37             coerce => sub { instantiate_array(@_) }
38             );
39              
40             =head1 METHODS
41              
42             =head3 construct
43              
44             my $item = $construction->construct( {
45             location => $location,
46             meta => $meta,
47             content => $content,
48             } );
49              
50             Iterates through the C and asks each to C an
51             item with the construction data. If no constructor returns a defined
52             vaue, then performs C<< Articulate::Item->new( $args ) >>.
53              
54             Note that of these three pieces of data, it is not guaranteed that all
55             will be available at the time of construction, particularly on inbound
56             communication (as opposed to when retrieving from storage). This is
57             largely dependant on the Service. Location should always be available.
58             Content is often not available.
59              
60             =cut
61              
62             sub construct {
63 5     5 1 90 my $self = shift;
64 5         9 my $args = shift;
65 5         8 my $constructed;
66 5         8 foreach my $constructor ( @{ $self->constructors } ) {
  5         131  
67 5         1371 $constructed = $constructor->construct($args);
68 5 50       232 return $constructed if defined $constructed;
69             }
70 0           return Articulate::Item->new($args);
71             }
72              
73             1;