HiD/Role/IsPublished.pm

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