Articulate/Construction.pm

filter: Statementstmt 92.8% 26 / 28 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 89.7% 35 / 39 CC 3 SCAR 5.4
CC
3
Cov
90%
construct
3.1
__ANON__
2.0
BEGIN
1.0
CRAP 1.7
« Articulate/Validation.pm ↑ Summary Articulate/Error.pm »
1 package Articulate::Construction;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Articulate::Syntax qw(instantiate_array);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Articulate::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 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 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 5 ▶ coerce => sub { instantiate_array(@_) }
Subroutine __ANON__: called CC=1 SCAR=0.0
38 6 );
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<constructors> and asks each to C<construct> 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 8 ▶sub construct {
Subroutine construct: called CC=3 SCAR=11.2
Pod documented
63 8 my $self = shift;
64 8 my $args = shift;
65 8 my $constructed;
66 8 foreach my $constructor ( @{ $self->constructors } ) {
67 8 $constructed = $constructor->construct($args);
68 8 ▶ return $constructed if defined $constructed;
Branch: 1 branch
BranchTrueFalseTotal
if defined $constructed 8 0 8
69 }
70 0 return Articulate::Item->new($args);
71 }
72  
73 6 1;
« Articulate/Validation.pm ↑ Summary Articulate/Error.pm »