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