| 1 | package Articulate::Navigation; | ||||||||||||||||||||||||||||
| 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 | 6 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 6 | with 'Articulate::Role::Component'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Articulate::Location; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | 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 | ||||||||||||||||||||||||||||
| 33 | valid locations for deposition and retrieval of items from storage. | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =cut | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | has locations => ( | ||||||||||||||||||||||||||||
| 38 | is => 'rw', # rwp? | ||||||||||||||||||||||||||||
| 39 | 1 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 7 | ▶ | coerce => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 41 | 7 | my $orig = shift; | |||||||||||||||||||||||||||
| 42 | 7 | my $new = []; | |||||||||||||||||||||||||||
| 43 | 7 | foreach my $l ( @{$orig} ) { | |||||||||||||||||||||||||||
| 44 | 20 | push @$new, new_location_specification $l; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 7 | return $new; | |||||||||||||||||||||||||||
| 47 | }, | ||||||||||||||||||||||||||||
| 48 | 6 | ); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # A new_location_specification is like a location except it can contain "*": "/zone/*/article/" | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =head1 METHODS | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head3 valid_location | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | do_something if $self->valid_location('zone/public') | ||||||||||||||||||||||||||||
| 59 | do_something if $self->valid_location($location_object) | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Returns the location if valid (matches one of the locspecs in | ||||||||||||||||||||||||||||
| 62 | C<locations>), undef otherwise. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 103 | ▶ | sub valid_location { | ||||||||||||||||||||||||||
|
Subroutine
valid_location: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 103 | my $self = shift; | |||||||||||||||||||||||||||
| 68 | 103 | my $location = new_location shift; | |||||||||||||||||||||||||||
| 69 | 103 | foreach my $defined_location ( @{ $self->locations } ) { | |||||||||||||||||||||||||||
| 70 | 191 | ▶ | if ( $defined_location->matches($location) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 102 | return $location; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 1 | return undef; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head3 define_locspec | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | $self->define_locspec('zone/*') | ||||||||||||||||||||||||||||
| 80 | $self->define_locspec($location_specification) | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | Adds a new_location_specification to C<locations>, unless it is already | ||||||||||||||||||||||||||||
| 83 | there | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =cut | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | ▶ | sub define_locspec { | ||||||||||||||||||||||||||
|
Subroutine
define_locspec: called CC=3 SCAR=12.7
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 89 | 1 | my $location = new_location_specification shift; | |||||||||||||||||||||||||||
| 90 | 1 | foreach my $defined_location ( @{ $self->locations } ) { | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ( ( $location eq $defined_location ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | return undef; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 1 | push @{ $self->locations }, $location; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head3 undefine_locspec | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | $self->undefine_locspec('zone/*') | ||||||||||||||||||||||||||||
| 101 | $self->undefine_locspec($location_specification) | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | Removes a new_location_specification from C<locations>. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =cut | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 1 | ▶ | sub undefine_locspec { | ||||||||||||||||||||||||||
|
Subroutine
undefine_locspec: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 109 | 1 | my $location = new_location_specification shift; | |||||||||||||||||||||||||||
| 110 | 1 | my ( $removed, $kept ) = ( [], [] ); | |||||||||||||||||||||||||||
| 111 | 1 | foreach my $defined_location ( @{ $self->locations } ) { | |||||||||||||||||||||||||||
| 112 | 1 | ▶ | if ( ( "$location" eq "$defined_location" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/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 table33%1/3
A or B
A= "$location" eq "$defined_location"B= $defined_location->matches_descendant_of($location)
| |||||||||||||||||||||||||||||
| 113 | or $defined_location->matches_descendant_of($location) ) | ||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||
| 115 | 1 | push @$removed, $location; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | else { | ||||||||||||||||||||||||||||
| 118 | 0 | push @$kept, $location; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 1 | $self->locations($kept); | |||||||||||||||||||||||||||
| 122 | 1 | return $removed; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =over | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =item * L<Articulate::Location> | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =item * L<Articulate::LocationSpecification> | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =back | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =cut | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 6 | 1; | |||||||||||||||||||||||||||