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/Navigation.pm ↑ Summary Articulate/Authorisation.pm »
1 package Articulate::Construction::LocationBased;
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 =head1 NAME
6  
7 Articulate::Construction::LocationBased - Create an item based on its
8 location
9  
10 =head1 ATTRIBUTES
11  
12 =head3 types
13  
14 This should be a hashref mapping types to class names to be used in
15 constructors, where a type in this case is the penultimate endpoint of
16 locations with an even number of parts
17  
18 So:
19  
20 article: Articulate::Item::Article
21  
22 ...would result in C</article/foo> or C<zone/public/article/foo>
23 becoming C<Articulate::Item::Article>s but not C<article>,
24 C<zone/article>, or C<zone/public/article>.
25  
26 =head1 METHODS
27  
28 =head3 construct
29  
30 $self->construct( {
31 location => 'zone/public/article/hello-world',
32 meta => { ... }
33 content => " ... "
34 } );
35  
36 Attempts to construct the item. Determines the desired class based on
37 the mapping in the C<types> attribute, then calls C<<
38 $class->new($args) >> on the class. Returns C<undef> if no appropriate
39 class found.
40  
41 In the above example, C<< $self->types->{article} >> would be
42 consulted.
43  
44 If the location is root or not a multiple of 2 (e.g. C<zone/public> is
45 even and a C<zone> but C<zone/public/article> is odd), returns
46 C<undef>.
47  
48 =cut
49  
50 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 6 ▶use Articulate::Syntax;
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 6 ▶use Module::Load ();
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 has types => (
57 is => 'rw',
58 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 6 );
60  
61 8 ▶sub construct {
Subroutine construct: called CC=4 SCAR=15.0
Pod documented
62 8 my $self = shift;
63 8 my $args = shift;
64 8 my $location = new_location( $args->{location} );
65 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
66 8 ▶ if ( exists $self->types->{ $location->[-2] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->types->{$location->[-2]}) 8 0 8
67 8 my $class = $self->types->{ $location->[-2] };
68 8 Module::Load::load($class);
69 8 return $class->new($args);
70 }
71 }
72 0 return undef;
73 }
74  
75 6 1;
« Articulate/Navigation.pm ↑ Summary Articulate/Authorisation.pm »