Articulate/Location.pm

filter: Statementstmt 91.1% 31 / 34 Branchbran 50.0% 6 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 3 / 3 totaltotal 83.0% 54 / 65 CC 8 SCAR 18.6
CC
8
Cov
80%
loc
13.3
BEGIN
1.0
BEGIN
1.0
CRAP 6.4
« Articulate/Storage/Local.pm ↑ Summary Articulate/Syntax.pm »
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
BranchTrueFalseTotal
if (1 == scalar @_) 396 0 396
41 396 ▶ if ( blessed $_[0] and $_[0]->can('location') ) {
Branch: 5 branches
BranchTrueFalseTotal
if (builtin::blessed($_[0]) and $_[0]->can('location')) { } 336 60 396
elsif (ref $_[0] eq 'ARRAY') { } 0 60 60
elsif (not defined $_[0]) { } 0 60 60
elsif (not ref $_[0]) { } 60 0 60
elsif (ref $_[0] eq 'HASH') { } 0 0 0
Condition66%2/3
builtin::blessed($_[0]) and $_[0]->can("location")
!ll&&!rl&&r
600336
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")
ABresult
0X0
100
111
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;
« Articulate/Storage/Local.pm ↑ Summary Articulate/Syntax.pm »