HiD/Role/IsPublished.pm

filter: Statementstmt 94.9% 56 / 59 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.7% 15 / 16 Podpod n/a totaltotal 92.4% 73 / 79 CC 3 SCAR 5.1
CC
3
Cov
92%
_build_baseurl
6.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.7
« HiD/Role/DoesLogging.pm ↑ Summary HiD/Processor/Handlebars.pm »
1 # ABSTRACT: Role to be consumed by classes that are published during processing
2  
3  
4 package HiD::Role::IsPublished;
5 24 our $AUTHORITY = 'cpan:GENEHACK';
6 24 $HiD::Role::IsPublished::VERSION = '1.96';
7 24 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 24 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 24 ▶use 5.014; # strict, unicode_strings
Subroutine BEGIN: called CC=1 SCAR=0.0
11 24 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 24 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 24 ▶use warnings qw/ FATAL utf8 /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 24 ▶use open qw/ :std :utf8 /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 24 ▶use charnames qw/ :full /;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 24 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 24 ▶use HiD::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 24 requires 'publish';
22  
23  
24 24 has basename => (
25 is => 'ro',
26 isa => 'Str' ,
27 lazy => 1 ,
28 builder => '_build_basename',
29 );
30  
31 sub _build_basename {
32 33 ▶ my $self = shift;
Subroutine _build_basename: called CC=1 SCAR=0.0
33 33 my $ext = '.' . $self->ext;
34 33 return path( $self->input_filename )->basename( $ext );
35 }
36  
37  
38 24 has baseurl => (
39 is => 'ro',
40 isa => 'Str',
41 lazy => 1,
42 builder => '_build_baseurl',
43 );
44  
45 sub _build_baseurl {
46 0 ▶ my $self = shift;
Subroutine _build_baseurl: not called CC=2 SCAR=17.9
47  
48 0 my $base_url = $self->get_config('baseurl');
49 0 ▶ return defined $base_url ? $base_url : '/';
Branch: 1 branch
BranchTrueFalseTotal
defined $base_url ? : 0 0 0
50 }
51  
52  
53 24 has dest_dir => (
54 is => 'ro' ,
55 isa => 'HiD_DirPath' ,
56 required => 1 ,
57 );
58  
59  
60 has ext => (
61 is => 'ro' ,
62 isa => 'HiD_FileExtension' ,
63 lazy => 1 ,
64 default => sub {
65 53 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
66 53 my( $extension ) = $self->input_filename =~ m|\.([^.]+)$|;
67 53 return $extension;
68 },
69 24 );
70  
71  
72 24 has input_filename => (
73 is => 'ro' ,
74 isa => 'HiD_FilePath' ,
75 required => 1 ,
76 );
77  
78  
79 has input_path => (
80 is => 'ro' ,
81 isa => 'HiD_DirPath' ,
82 lazy => 1 ,
83 43 ▶ default => sub { path( shift->input_filename )->parent->stringify() },
Subroutine __ANON__: called CC=1 SCAR=0.0
84 24 );
85  
86  
87 has output_filename => (
88 is => 'ro' ,
89 isa => 'Str' ,
90 lazy => 1 ,
91 default => sub {
92 75 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
93  
94 75 my $url = $self->url;
95 73 ▶ $url .= 'index.html' if $url =~ m|/$|;
Branch: 1 branch
BranchTrueFalseTotal
if $url =~ m[/$]u 6 67 73
96  
97 73 return path( $self->dest_dir , $url )->stringify;
98 },
99 24 );
100  
101  
102 24 has source => (
103 is => 'ro' ,
104 isa => 'Str' ,
105 default => '' ,
106 );
107  
108  
109 24 has url => (
110 is => 'ro' ,
111 isa => 'Str' ,
112 lazy => 1 ,
113 builder => '_build_url' ,
114 );
115  
116 24 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
117 24 1;
118  
119 __END__
120  
121 =pod
122  
123 =encoding UTF-8
124  
125 =head1 NAME
126  
127 HiD::Role::IsPublished - Role to be consumed by classes that are published during processing
128  
129 =head1 SYNOPSIS
130  
131 package MyThingThatIsPublished;
132 use Moose;
133 with 'HiD::Role::IsPublished';
134  
135 ...
136  
137 1;
138  
139 =head1 DESCRIPTION
140  
141 This role is for all objects that go through the HiD publishing process. It
142 provides attributes and methods that are needed during that process.
143  
144 =head1 ATTRIBUTES
145  
146 =head2 basename ( ro / isa = Str / lazily built from input_filename )
147  
148 Basename of the file for this object (that is, without any leading directory
149 path and without any file extension).
150  
151 =head2 baseurl
152  
153 Base URL for use in Templates
154  
155 =head2 dest_dir ( ro / isa = HiD_DirPath / required )
156  
157 The path to the directory where the output_filename will be written.
158  
159 =head2 ext ( ro / isa = HiD_FileExtension / lazily built from filename )
160  
161 The extension on the input filename of the consuming object.
162  
163 =head2 input_filename ( ro / isa = HiD_FilePath / required )
164  
165 The path of the consuming object's file. Required for instantiation.
166  
167 =head2 input_path ( ro / isa = HiD_DirPath / lazily built from input_filename )
168  
169 The path component of the input filename.
170  
171 =head2 output_filename
172  
173 Path to the file that will be created when the C<write> method is called.
174  
175 =head2 source ( ro / isa = Str )
176  
177 Same as 'source' in HiD.pm. Normally shouldn't need to be provided.
178  
179 =head2 url ( ro / isa = Str / lazily built from output_filename and dest_dir )
180  
181 The URL to the output path for the written file.
182  
183 =head1 VERSION
184  
185 version 1.96
186  
187 =head1 AUTHOR
188  
189 John SJ Anderson <genehack@genehack.org>
190  
191 =head1 COPYRIGHT AND LICENSE
192  
193 This software is copyright (c) 2015 by John SJ Anderson.
194  
195 This is free software; you can redistribute it and/or modify it under
196 the same terms as the Perl 5 programming language system itself.
197  
198 =cut
« HiD/Role/DoesLogging.pm ↑ Summary HiD/Processor/Handlebars.pm »