| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$location eq $defined_location or $defined_location->matches_descendant_of($location)
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)
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||