blib/lib/Statocles/Role/PageAttrs.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 83.3% 10 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.0% 9 / 10 Podpod 100% 2 / 2 totaltotal 90.0% 63 / 70 CC 9 SCAR 10.1
CC
9
Cov
93%
links
5.0
__ANON__
3.0
images
2.1
CRAP 2.7
« blib/lib/Statocles/Util.pm ↑ Summary blib/lib/Statocles/Deploy/File.pm »
1 package Statocles::Role::PageAttrs;
2 101 our $VERSION = '0.099';
3 # ABSTRACT: A role implementing common attributes for pages/documents
4  
5 101 ▶use Statocles::Base 'Role';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 101 ▶use Statocles::Util qw( uniq_by );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 101 ▶use Statocles::Person;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 #pod =attr title
10 #pod
11 #pod The title of the page. Any unsafe characters in the title (C<E<lt>>,
12 #pod C<E<gt>>, C<">, and C<&>) will be escaped by the template, so no HTML
13 #pod allowed.
14 #pod
15 #pod =cut
16  
17 101 has title => (
18 is => 'rw',
19 isa => Str,
20 default => '',
21 );
22  
23 #pod =attr author
24 #pod
25 #pod The author of the page.
26 #pod
27 #pod =cut
28  
29 101 has author => (
30 is => 'rw',
31 isa => Maybe[PersonType],
32 coerce => PersonType->coercion,
33 lazy => 1,
34 builder => '_build_author',
35 );
36  
37 13 ▶sub _build_author {
Subroutine _build_author: called CC=2 SCAR=7.1
38 13 my ( $self ) = @_;
39 13 ▶ return $self->site->author || Statocles::Person->new( name => '' );
Condition66%2/3
$self->site->author || 'Statocles::Person'->new('name', '')
l!l&&r!l&&!r
1120
MC/DC0%0/2
$self->site->author || 'Statocles::Person'->new('name', '')
$self->site->author 'Statocles::Person'->new('name', '')
Truth table66%2/3
A || B
A= $self->site->authorB= 'Statocles::Person'->new('name', '')
ABresult
1X1
011
000
40 }
41  
42 #pod =attr links
43 #pod
44 #pod A hash of arrays of links to pages related to this page. Possible keys:
45 #pod
46 #pod feed - Feed pages related to this page
47 #pod alternate - Alternate versions of this page posted to other sites
48 #pod stylesheet - Additional stylesheets for this page
49 #pod script - Additional scripts for this page
50 #pod
51 #pod Each item in the array is a L<link object|Statocles::Link>. The most common
52 #pod attributes are:
53 #pod
54 #pod text - The text of the link
55 #pod href - The page for the link
56 #pod type - The MIME type of the link, optional
57 #pod
58 #pod =cut
59  
60 has _links => (
61 is => 'ro',
62 isa => LinkHash,
63 lazy => 1,
64 34 ▶ default => sub { +{} },
Subroutine __ANON__: called CC=1 SCAR=0.0
65 101 coerce => LinkHash->coercion,
66 init_arg => 'links',
67 );
68  
69 #pod =attr images
70 #pod
71 #pod A hash of images related to this page. Each value should be an L<image
72 #pod object|Statocles::Image>. These are used by themes to show images next
73 #pod to articles, thumbnails, and/or shortcut icons.
74 #pod
75 #pod =cut
76  
77 has _images => (
78 is => 'ro',
79 isa => HashRef[InstanceOf['Statocles::Image']],
80 lazy => 1,
81 0 ▶ default => sub { +{} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
82 init_arg => 'images',
83 3 ▶ coerce => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
84 3 my ( $ref ) = @_;
85 3 my %img;
86 3 for my $name ( keys %$ref ) {
87 5 my $attrs = $ref->{ $name };
88 5 ▶ if ( !ref $attrs ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $attrs) 1 4 5
89 1 $attrs = { src => $attrs };
90 }
91 $img{ $name } = Statocles::Image->new(
92 5 %{ $attrs },
93 );
94 }
95 3 return \%img;
96 },
97 101 );
98  
99 #pod =method links
100 #pod
101 #pod my @links = $page->links( $key );
102 #pod my $link = $page->links( $key );
103 #pod $page->links( $key => $add_link );
104 #pod
105 #pod Get or append to the links set for the given key. See L<the links
106 #pod attribute|/links> for some commonly-used keys.
107 #pod
108 #pod If only one argument is given, returns a list of L<link
109 #pod objects|Statocles::Link>. In scalar context, returns the first link in
110 #pod the list.
111 #pod
112 #pod If two or more arguments are given, append the new links to the given
113 #pod key. C<$add_link> may be a URL string, a hash reference of L<link
114 #pod attributes|Statocles::Link/ATTRIBUTES>, or a L<Statocles::Link
115 #pod object|Statocles::Link>. When adding links, nothing is returned.
116 #pod
117 #pod =cut
118  
119 188 ▶sub links {
Subroutine links: called CC=5 SCAR=16.1
Pod documented
120 188 my ( $self, $name, @add_links ) = @_;
121 188 ▶ if ( @add_links ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@add_links) 14 174 188
122 14 push @{ $self->_links->{ $name } }, map { LinkType->coerce( $_ ) } @add_links;
123 14 return;
124 }
125 174 ▶ return $self->_links if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 174 174
126 94 ▶ my @links = uniq_by { $_->href }
Subroutine __ANON__: called CC=1 SCAR=0.0
127 174 ▶ $self->_links->{ $name } ? @{ $self->_links->{ $name } } : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->_links->{$name} ? : 65 109 174
128 174 ▶ return wantarray ? @links : $links[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 147 27 174
129 }
130  
131 #pod =method images
132 #pod
133 #pod my $image = $page->images( $key );
134 #pod
135 #pod Get the images for the given key. See L<the images attribute|/images> for some
136 #pod commonly-used keys. Returns an L<image object|Statocles::Image>.
137 #pod
138 #pod =cut
139  
140 3 ▶sub images {
Subroutine images: called CC=2 SCAR=7.2
Pod documented
141 3 my ( $self, $name ) = @_;
142 # This exists here as a placeholder in case we ever need to handle
143 # arrays of images, which I anticipate will happen when we build
144 # image galleries or want to be able to pick a single random image
145 # from an array.
146 3 ▶ return $name ? $self->_images->{ $name } : $self->_images;
Branch: 1 branch
BranchTrueFalseTotal
$name ? : 3 0 3
147 }
148  
149 101 1;
150  
151 __END__
« blib/lib/Statocles/Util.pm ↑ Summary blib/lib/Statocles/Deploy/File.pm »