| 1 | package Articulate::Location; | ||||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use overload '""' => \&to_file_path, '@{}' => sub { shift->path }; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Exporter::Declare; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | default_exports qw(loc); | |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | Articulate::Location - represent an item's location | ||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | loc ['zone', 'public', 'article', 'hello-world'] | ||||||||||||||||||||||||||||||||||||||||||||
| 21 | loc 'zone/public/article/hello-world' # same thing | ||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | An object class which represents an item's location within the | ||||||||||||||||||||||||||||||||||||||||||||
| 24 | Articulate ecosystem. It contains an array of slugs, and stringifies to | ||||||||||||||||||||||||||||||||||||||||||||
| 25 | the 'file path' representation of them. | ||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | =head3 loc | ||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | C<loc> is a constructor. It takes either a string (in the form of a | ||||||||||||||||||||||||||||||||||||||||||||
| 34 | path) or an arrayref. Either will be stored as an arrayref in the | ||||||||||||||||||||||||||||||||||||||||||||
| 35 | C<path> attribute. | ||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | sub loc { | ||||||||||||||||||||||||||||||||||||||||||||
| 40 | 396 | ▶ | if ( 1 == scalar @_ ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loc: called CC=8 SCAR=25.8
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 396 | ▶ | if ( blessed $_[0] and $_[0]->can('location') ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition66%2/3
builtin::blessed($_[0]) and $_[0]->can("location")
MC/DC50%1/2
builtin::blessed($_[0]) and $_[0]->can("location")
builtin::blessed($_[0])
$_[0]->can("location")
Truth table66%2/3
A and B
A= builtin::blessed($_[0])B= $_[0]->can("location")
| |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 336 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 44 | elsif ( ref $_[0] eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | return __PACKAGE__->new( { path => $_[0] } ); | |||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 47 | elsif ( !defined $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | return __PACKAGE__->new; | |||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 50 | elsif ( !ref $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 51 | return __PACKAGE__->new( | ||||||||||||||||||||||||||||||||||||||||||||
| 52 | 60 | { path => [ grep { $_ ne '' } split /\//, $_[0] ] } ); | |||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 54 | elsif ( ref $_[0] eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | return __PACKAGE__->new( $_[0] ); | |||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | =head1 ATTRIBUTE | ||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | =head3 path | ||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | An arrayref representing the path to the location. This is how the | ||||||||||||||||||||||||||||||||||||||||||||
| 65 | location is actually stored and is used for overloaded array | ||||||||||||||||||||||||||||||||||||||||||||
| 66 | dereferencing. | ||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | has path => ( | ||||||||||||||||||||||||||||||||||||||||||||
| 71 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||
| 72 | 19 | ▶ | default => sub { []; }, | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 11 | ); | |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | =head3 location | ||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | $location->location->location # same as $location | ||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | This method always returns the object itself. It is useful when you | ||||||||||||||||||||||||||||||||||||||||||||
| 82 | want to allow either an Item or a Location as an argument. | ||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | sub location { | ||||||||||||||||||||||||||||||||||||||||||||
| 87 | 76 | ▶ | return shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
location: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | =head3 to_file_path | ||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | Joins the contents of C<path> on C</> and returns the result. This is | ||||||||||||||||||||||||||||||||||||||||||||
| 93 | used for overloaded stringification. | ||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | sub to_file_path { | ||||||||||||||||||||||||||||||||||||||||||||
| 98 | 348 | ▶ | return join '/', @{ $_[0]->path }; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_file_path: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | =over | ||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | =item * L<Articulate::Item> | ||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | =item * L<Articulate::LocationSpecification> | ||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | =back | ||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||