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 CC 9 SCAR 20.2
CC
9
Cov
54%
undefine_locspec
20.0
define_locspec
12.0
valid_location
3.0
CRAP 7.6
« Articulate/Authentication/Internal.pm ↑ Summary Articulate/Service/List.pm »
1 package Articulate::Navigation;
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 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 with 'Articulate::Role::Component';
7  
8 5 ▶use Articulate::Location;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶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 4 ▶ my $orig = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
41 4 my $new = [];
42 4 foreach my $l ( @{$orig} ) {
43 16 push @$new, locspec $l;
44 }
45 4 return $new;
46 },
47 5 );
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 sub define_locspec {
85 0 ▶ my $self = shift;
Subroutine define_locspec: not called CC=3 SCAR=24.8
Pod documented
86 0 my $location = locspec shift;
87 0 foreach my $defined_location ( @{ $self->locations } ) {
88 0 ▶ if ( ( $location eq $defined_location ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($location eq $defined_location) 0 0 0
89 0 return undef;
90 }
91 }
92 0 push @{ $self->locations }, $location;
93 }
94  
95 =head3 undefine_locspec
96  
97 $self->undefine_locspec('zone/*')
98 $self->undefine_locspec($locspec)
99  
100 Removes a locspec from C<locations>.
101  
102 =cut
103  
104 sub undefine_locspec {
105 0 ▶ my $self = shift;
Subroutine undefine_locspec: not called CC=4 SCAR=30.0
Pod documented
106 0 my $location = locspec shift;
107 0 my ( $removed, $kept ) = ( [], [] );
108 0 foreach my $defined_location ( @{ $self->locations } ) {
109 0 ▶ if ( ( $location eq $defined_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
110 or $defined_location->matches_descendant_of($location) )
111 {
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 5 1;
« Articulate/Authentication/Internal.pm ↑ Summary Articulate/Service/List.pm »