Articulate/Navigation.pm

filter: Statementstmt 60.0% 30 / 50 Branchbran 33.3% 2 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod 100% 3 / 3 totaltotal 56.7% 42 / 74 SCAR 28.2
CC
9
Cov
54%
undefine_locspec
20.0
define_locspec
12.0
valid_location
3.0
CRAP 16.8
« Articulate/Flow/ContentType.pm ↑ Summary Articulate/Serialisation/Asset.pm »
1 package Articulate::Navigation;
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 with 'Articulate::Role::Component';
7  
8 4 ▶use Articulate::Location;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Articulate::LocationSpecification;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Articulate::Navigation - determine valid locations
14  
15 =head1 SYNOPSIS
16  
17 components:
18 navigation:
19 Articulate::Navigation:
20 locations:
21 - zone/*
22 - zone/*/article/*
23 - user/*
24 - []
25  
26 Provides validation for locations.
27  
28 =head1 ATTRIBUTE
29  
30 =head3 locations
31  
32 Any location specifications configured in the locations attribute are valid locations for deposition and retrieval of items from storage.
33  
34 =cut
35  
36 has locations => (
37 is => 'rw', # rwp?
38 0 ▶ default => sub{ [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 coerce => sub{
40 3 ▶ my $orig = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
41 3 my $new = [];
42 3 foreach my $l (@{ $orig }){
43 12 push @$new, locspec $l;
44 }
45 3 return $new;
46 },
47 4 );
48  
49 # A locspec is like a location except it can contain "*": "/zone/*/article/"
50  
51 =head1 METHODS
52  
53 =cut
54  
55 =head3 valid_location
56  
57 do_something if $self->valid_location('zone/public')
58 do_something if $self->valid_location($location_object)
59  
60 Returns the location if valid (matches one of the locspecs in C<locations>), undef otherwise.
61  
62 =cut
63  
64 sub valid_location {
65 101 ▶ my $self = shift;
Subroutine valid_location: called CC=3 SCAR=11.0
Pod documented
66 101 my $location = loc shift;
67 101 foreach my $defined_location ( @{ $self->locations } ) {
68 190 ▶ if ( $defined_location->matches($location) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($defined_location->matches($location)) 101 89 190
69 101 return $location;
70 }
71 }
72 0 return undef;
73 }
74  
75 =head3 define_locspec
76  
77 $self->define_locspec('zone/*')
78 $self->define_locspec($locspec)
79  
80 Adds a locspec to C<locations>, unless it is already there
81  
82 =cut
83  
84  
85 sub define_locspec {
86 0 ▶ my $self = shift;
Subroutine define_locspec: not called CC=3 SCAR=24.8
Pod documented
87 0 my $location = locspec shift;
88 0 foreach my $defined_location ( @{ $self->locations } ) {
89 0 ▶ if ( ( $location eq $defined_location ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($location eq $defined_location) 0 0 0
90 0 return undef;
91 }
92 }
93 0 push @{ $self->locations }, $location;
94 }
95  
96 =head3 undefine_locspec
97  
98 $self->undefine_locspec('zone/*')
99 $self->undefine_locspec($locspec)
100  
101 Removes a locspec from C<locations>.
102  
103 =cut
104  
105  
106 sub undefine_locspec {
107 0 ▶ my $self = shift;
Subroutine undefine_locspec: not called CC=4 SCAR=30.0
Pod documented
108 0 my $location = locspec shift;
109 0 my ($removed, $kept) = ([], []);
110 0 foreach my $defined_location ( @{ $self->locations } ){
111 0 ▶ if ( ( $location eq $defined_location ) or $defined_location->matches_descendant_of($location) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($location eq $defined_location or $defined_location->matches_descendant_of($location)) { } 0 0 0
Condition0%0/3
$location eq $defined_location or $defined_location->matches_descendant_of($location)
l!l&&r!l&&!r
000
MC/DC0%0/2
$location eq $defined_location or $defined_location->matches_descendant_of($location)
$location eq $defined_location $defined_location->matches_descendant_of($location)
Truth table0%0/3
A or B
A= $location eq $defined_locationB= $defined_location->matches_descendant_of($location)
ABresult
1X1
011
000
112 0 push @$removed, $location;
113 }
114 else {
115 0 push @$kept, $location;
116 }
117 }
118 0 $self->locations($kept);
119 0 return $removed;
120 }
121  
122 =head1 SEE ALSO
123  
124 =over
125  
126 =item * L<Articulate::Location>
127  
128 =item * L<Articulate::LocationSpecification>
129  
130 =back
131  
132 =cut
133  
134 4 1;
« Articulate/Flow/ContentType.pm ↑ Summary Articulate/Serialisation/Asset.pm »