Articulate/Construction/LocationBased.pm

filter: Statementstmt 92.5% 25 / 27 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 79.5% 35 / 44 CC 4 SCAR 9.1
CC
4
Cov
82%
construct
4.5
__ANON__
2.0
BEGIN
1.0
CRAP 2.5
« Articulate/Sortation.pm ↑ Summary Articulate/Sortation/MetaDelver.pm »
1 package Articulate::Construction::LocationBased;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =head1 NAME
6  
7 Articulate::Construction::LocationBased - Create an item based on its location
8  
9 =head1 ATTRIBUTES
10  
11 =head3 types
12  
13 This should be a hashref mapping types to class names to be used in constructors, where a type in this case is the penultimate endpoint of locations with an even number of parts
14  
15 So:
16  
17 article: Articulate::Item::Article
18  
19 ...would result in C</article/foo> or C<zone/public/article/foo> becoming C<Articulate::Item::Article>s but not C<article>, C<zone/article>, or C<zone/public/article>.
20  
21 =head1 METHODS
22  
23 =head3 construct
24  
25 $self->construct( {
26 location => 'zone/public/article/hello-world',
27 meta => { ... }
28 content => " ... "
29 } );
30  
31 Attempts to construct the item. Determines the desired class based on the mapping in the C<types> attribute, then calls C<< $class->new($args) >> on the class. Returns C<undef> if no appropriate class found.
32  
33 In the above example, C<< $self->types->{article} >> would be consulted.
34  
35 If the location is root or not a multiple of 2 (e.g. C<zone/public> is even and a C<zone> but C<zone/public/article> is odd), returns C<undef>.
36  
37 =cut
38  
39 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 5 ▶use Articulate::Syntax;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 5 ▶use Module::Load ();
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 has types => (
46 is => 'rw',
47 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 5 );
49  
50 sub construct {
51 8 ▶ my $self = shift;
Subroutine construct: called CC=4 SCAR=15.0
Pod documented
52 8 my $args = shift;
53 8 my $location = loc( $args->{location} );
54 8 ▶ if ( scalar(@$location) and 0 == ( scalar(@$location) % 2 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$location and 0 == scalar(@$location) % 2) 8 0 8
Condition33%1/3
scalar @$location and 0 == scalar(@$location) % 2
!ll&&!rl&&r
008
MC/DC0%0/2
scalar @$location and 0 == scalar(@$location) % 2
scalar @$location 0 == scalar(@$location) % 2
Truth table33%1/3
A and B
A= scalar @$locationB= 0 == scalar(@$location) % 2
ABresult
0X0
100
111
55 8 ▶ if ( exists $self->types->{ $location->[-2] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->types->{$location->[-2]}) 8 0 8
56 8 my $class = $self->types->{ $location->[-2] };
57 8 Module::Load::load($class);
58 8 return $class->new($args);
59 }
60 }
61 0 return undef;
62 }
63  
64 5 1;
« Articulate/Sortation.pm ↑ Summary Articulate/Sortation/MetaDelver.pm »