File Coverage

blib/lib/HiD/Role/IsPublished.pm
Criterion Covered Total %
statement 35 38 92.1
branch 0 2 0.0
condition n/a
subroutine 12 13 92.3
pod n/a
total 47 53 88.6


line stmt bran cond sub pod time code
1             # ABSTRACT: Role to be consumed by classes that are published during processing
2              
3              
4             package HiD::Role::IsPublished;
5             our $AUTHORITY = 'cpan:GENEHACK';
6             $HiD::Role::IsPublished::VERSION = '1.99';
7 12     12   8517 use Moose::Role;
  12         23588  
  12         113  
8 12     12   63350 use namespace::autoclean;
  12         66  
  12         238  
9              
10 12     12   1086 use 5.014; # strict, unicode_strings
  12         37  
11 12     12   66 use utf8;
  12         20  
  12         82  
12 12     12   295 use autodie;
  12         26  
  12         74  
13 12     12   55765 use warnings qw/ FATAL utf8 /;
  12         31  
  12         618  
14 12     12   65 use open qw/ :std :utf8 /;
  12         24  
  12         83  
15 12     12   1812 use charnames qw/ :full /;
  12         23  
  12         92  
16              
17 12     12   2494 use Path::Tiny;
  12         25  
  12         670  
18              
19 12     12   4464 use HiD::Types;
  12         69  
  12         5952  
20              
21             requires 'publish';
22              
23              
24             has basename => (
25             is => 'ro',
26             isa => 'Str' ,
27             lazy => 1 ,
28             builder => '_build_basename',
29             );
30              
31             sub _build_basename {
32 42     42   124 my $self = shift;
33 42         1088 my $ext = '.' . $self->ext;
34 42         1020 return path( $self->input_filename )->basename( $ext );
35             }
36              
37              
38             has baseurl => (
39             is => 'ro',
40             isa => 'Str',
41             lazy => 1,
42             builder => '_build_baseurl',
43             );
44              
45             sub _build_baseurl {
46 0     0     my $self = shift;
47              
48 0           my $base_url = $self->get_config('baseurl');
49 0 0         return defined $base_url ? $base_url : '/';
50             }
51              
52              
53             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             my $self = shift;
66             my( $extension ) = $self->input_filename =~ m|\.([^.]+)$|;
67             return $extension;
68             },
69             );
70              
71              
72             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             default => sub { path( shift->input_filename )->parent->stringify() },
84             );
85              
86              
87             has output_filename => (
88             is => 'ro' ,
89             isa => 'Str' ,
90             lazy => 1 ,
91             default => sub {
92             my $self = shift;
93              
94             my $url = $self->url;
95             $url .= 'index.html' if $url =~ m|/$|;
96              
97             return path( $self->dest_dir , $url )->stringify;
98             },
99             );
100              
101              
102             has source => (
103             is => 'ro' ,
104             isa => 'Str' ,
105             default => '' ,
106             );
107              
108              
109             has url => (
110             is => 'ro' ,
111             isa => 'Str' ,
112             lazy => 1 ,
113             builder => '_build_url' ,
114             );
115              
116 12     12   107 no Moose::Role;
  12         24  
  12         114  
117             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.99
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