blib/lib/Blio.pm

filter: Statementstmt 86.4% 96 / 111 Branchbran 75.0% 15 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 95.2% 20 / 21 Podpod 0.0% 0 / 3 totaltotal 82.5% 132 / 160 CC 12 SCAR 14.1
CC
12
Cov
84%
collect
10.5
write
4.2
_build_nodes_by_date
2.0
CRAP 4.1
« blib/lib/Blio/Image.pm ↑ Summary blib/script/blio.pl »
1 package Blio;
2 14 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 # ABSTRACT: domms blogging "engine"
5  
6 14 our $VERSION = 2.003;
7  
8 14 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use MooseX::Types::Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 14 ▶use Path::Class::Iterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 14 ▶use File::ShareDir qw(dist_dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 14 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 14 ▶use Blio::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 14 with 'MooseX::Getopt';
19 14 with 'MooseX::SimpleConfig';
20  
21 14 has '+configfile' => ( default => 'blio.ini' );
22 14 has 'source_dir' => (
23 is => 'ro',
24 isa => 'Path::Class::Dir',
25 required => 1,
26 coerce => 1,
27 lazy_build => 1
28 );
29 sub _build_source_dir {
30 1 ▶ my $self = shift;
Subroutine _build_source_dir: called CC=1 SCAR=0.0
31 1 return Path::Class::Dir->new->subdir('src');
32 }
33  
34 14 has 'output_dir' => (
35 is => 'ro',
36 isa => 'Path::Class::Dir',
37 required => 1,
38 coerce => 1,
39 lazy_build => 1
40 );
41 sub _build_output_dir {
42 1 ▶ my $self = shift;
Subroutine _build_output_dir: called CC=1 SCAR=0.0
43 1 return Path::Class::Dir->new->subdir('out');
44 }
45  
46 14 has 'template_dir' => (
47 is => 'ro',
48 isa => 'Path::Class::Dir',
49 required => 1,
50 coerce => 1,
51 lazy_build => 1
52 );
53 sub _build_template_dir {
54 1 ▶ my $self = shift;
Subroutine _build_template_dir: called CC=1 SCAR=0.0
55 1 return Path::Class::Dir->new->subdir('templates');
56 }
57  
58 14 has 'name' => (is=>'ro',isa=>'Str',default=>'Blio',required=>1);
59 14 has 'site_url' => (is=>'ro',isa=>'Str',required=>0);
60 14 has 'site_author' => (is=>'ro',isa=>'Str',required=>0);
61 14 has 'language' => (is=>'ro',isa=>'Str',default=>'en',required=>1);
62 14 has 'converter' => (is=>'ro',isa=>'Maybe[Str]',default=>undef,required=>1);
63 14 has 'thumbnail' => (is=>'ro',isa=>'Int',default=>300,required=>1);
64 14 has 'tags' => (is=>'ro',isa=>'Bool',default=>0);
65 14 has 'schedule' => (is=>'ro',isa=>'Bool',default=>0);
66  
67 14 has 'force' => (is=>'ro',isa=>'Bool',default=>0);
68 14 has 'quiet' => (is=>'ro',isa=>'Bool',default=>0);
69  
70 13 ▶has 'nodes_by_url' => ( is => 'ro', isa => 'HashRef', default => sub { {} } ,traits => [ 'NoGetopt' ]);
Subroutine __ANON__: called CC=1 SCAR=0.0
71 has 'tree' => (
72 is => 'ro',
73 isa => 'ArrayRef[Blio::Node]',
74 13 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
75 14 traits => ['Array', 'NoGetopt'],
76 handles => { add_top_node => 'push', },
77 );
78 14 has 'tt' => (
79 is=>'ro',
80 isa=>'Template',
81 lazy_build => 1,
82 traits => [ 'NoGetopt' ],
83 );
84 sub _build_tt {
85 4 ▶ my $self = shift;
Subroutine _build_tt: called CC=1 SCAR=0.0
86 4 return Template->new({
87 OUTPUT_PATH=>$self->output_dir->stringify,
88 INCLUDE_PATH=>[$self->template_dir->stringify, dir(dist_dir('Blio'),'templates')->stringify],
89 WRAPPER=>'wrapper.tt',
90 ENCODING => 'UTF8',
91 });
92 }
93  
94 14 has 'nodes_by_date' => (is=>'ro', isa=>'ArrayRef',lazy_build=>1,traits => [ 'NoGetopt' ]);
95 sub _build_nodes_by_date {
96 0 ▶ my $self = shift;
Subroutine _build_nodes_by_date: not called CC=1 SCAR=6.9
97  
98 my @sorted =
99 0 map { $_->[0] }
100 0 sort { $b->[1] <=> $a->[1] }
101 0 map { [$_ => $_->date->epoch] }
102 0 values %{$self->nodes_by_url};
103 0 return \@sorted;
104 }
105 13 ▶has 'stash' => (is=>'ro',isa=>'HashRef',default=>sub {{}},traits => [ 'NoGetopt' ]);
Subroutine __ANON__: called CC=1 SCAR=0.0
106  
107 14 has 'tagindex' => (
108 is=>'rw',
109 isa=>'Blio::Node',
110 lazy_build=>1,
111 traits => [ 'NoGetopt' ],
112 );
113 sub _build_tagindex {
114 1 ▶ my $self = shift;
Subroutine _build_tagindex: called CC=1 SCAR=0.0
115 1 my $tagindex = Blio::Node->new(
116 base_dir => $self->source_dir,
117 source_file => $0,
118 id=>'tags.html',
119 url=>'tags.html',
120 title=>'Tags',
121 date=>DateTime->now,
122 content=>'',
123 );
124 1 $self->nodes_by_url->{'tags.html'}=$tagindex;
125 1 return $tagindex;
126 }
127  
128 sub run {
129 3 ▶ my $self = shift;
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
130  
131 3 $self->collect;
132 3 $self->write;
133 }
134  
135 sub collect {
136 6 ▶ my $self = shift;
Subroutine collect: called CC=9 SCAR=23.5
Pod undocumented
137 6 my $iterator = Path::Class::Iterator->new(
138 root => $self->source_dir,
139 breadth_first => 1,
140 );
141  
142 6 my $schedule = $self->schedule;
143 6 my $now = DateTime->now;
144  
145 6 ▶ until ( $iterator->done ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($iterator->done) 48 6 54
146 48 my $file = $iterator->next;
147 48 ▶ next if -d $file;
Branch: 1 branch
BranchTrueFalseTotal
if -d $file 13 35 48
148 35 ▶ next unless $file =~ /\.txt$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /\.txt$/ 6 29 35
149  
150 29 my $node = Blio::Node->new_from_file( $self, $file );
151 29 ▶ if ($schedule && $node->date > $now) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schedule and $node->date > $now) 0 29 29
Condition33%1/3
$schedule and $node->date > $now
!ll&&!rl&&r
2900
MC/DC0%0/2
$schedule and $node->date > $now
$schedule $node->date > $now
Truth table33%1/3
A and B
A= $scheduleB= $node->date > $now
ABresult
0X0
100
111
152 0 say "skipping ".$node->id." (scheduled for ".$node->date." but now is ".$now.")";
153 0 next;
154 }
155 29 $self->nodes_by_url->{ $node->url } = $node;
156  
157 29 ▶ if ( $node->source_file->parent->stringify eq
Branch: 1 branch
BranchTrueFalseTotal
if ($node->source_file->parent->stringify eq $self->source_dir->stringify) { } 12 17 29
158 $self->source_dir->stringify ) {
159 12 $self->add_top_node($node);
160 }
161 else {
162 17 my $possible_parent_url = $node->possible_parent_url;
163 17 ▶ if ( my $parent = $self->nodes_by_url->{$possible_parent_url} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = $self->nodes_by_url->{$possible_parent_url}) { } 17 0 17
164 17 $node->parent($parent);
165 17 $parent->add_child($node);
166 #say $node->url .' is child of '.$parent->url;
167 }
168 else {
169 0 say "Cannot find parent, but not a root node: " . $node->url;
170 0 say "For each subdirectoy, you need a file in the parent directory";
171 0 say "with the name of the subdirectory and .txt extension";
172 0 say "Need a file called " . $node->source_file->parent->stringify . '.txt';
173 0 exit 0;
174 }
175 }
176 }
177  
178 6 ▶ unless ($self->nodes_by_url->{'index.html'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->nodes_by_url->{"index.html"}) 6 0 6
179 6 my $index = Blio::Node->new(
180 base_dir => $self->source_dir,
181 source_file => $0,
182 id=>'index.html',
183 url=>'index.html',
184 title=>'Index',
185 date=>DateTime->now,
186 content=>'',
187 );
188 6 $self->nodes_by_url->{'index.html'}=$index;
189 6 $index->children($self->tree);
190 }
191 }
192  
193 sub write {
194 3 ▶ my $self = shift;
Subroutine write: called CC=4 SCAR=14.3
Pod undocumented
195  
196 3 ▶ while (my ($url, $node) = each %{$self->nodes_by_url}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$self->nodes_by_url;}) 8 1 9
197 8 ▶ say "writing $url" unless $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quiet 8 0 8
198 8 ▶ if ($node->paged_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->paged_list) { } 0 8 8
199 0 $node->write_paged_list($self);
200 }
201 else {
202 8 $node->write($self);
203 }
204 }
205  
206 }
207  
208 14 __PACKAGE__->meta->make_immutable;
209 14 1;
210  
211 __END__
212  
213 =pod
214  
215 =encoding UTF-8
216  
217 =head1 NAME
218  
219 Blio - domms blogging "engine"
220  
221 =head1 VERSION
222  
223 version 2.003
224  
225 =head1 SYNOPSIS
226  
227 Backend for the C<blio.pl> command. See L<blio.pl> and/or C<perldoc blio.pl> for details.
228  
229 more docs pending...
230  
231 docs provided by gabor, need to be integrated:
232  
233 =head1 CONFIGURATION
234  
235 The configuration parameters can be provided either in the configuration file that defauts to blio.ini
236 or on the command line.
237  
238 The configuration file can look like this:
239  
240 name=Test site
241 source_dir=src/
242 output_dir=.
243 template_dir=templates/
244  
245 The configureation file must exists.
246 Otherwise you will get a warning like this:
247  
248 Specified configfile 'blio.ini' does not exist, is empty, or is not readable
249  
250 If no source_dir provided or there is no src/ directory, you get this exception:
251  
252 Can't call method "done" on an undefined value at .../Blio.pm line 137.
253  
254 =over 4
255  
256 =item name
257  
258 The name of the site in the title of the pages. Default to Blio
259  
260 =item source_dir
261  
262 The directory where the source files are. Each page of the site has a corresponding source file with .txt extension.
263 Defaults to the C<src/> directory relative to the current working directory where your run the C<build.pl> script.
264  
265 =item output_dir
266  
267 Directory where the generated html files should go. Defaults to C<out/> relative to the current working directory.
268  
269 =item template_dir
270  
271 The location of the template files. Defaults to C<templates/> relative to the current working directory.
272 As a fallback, there is a set of templates provided by Blio. They come in the share/templates directory of
273 the distribution and are installed along the module.
274  
275 =item site_url
276  
277 =item site_author
278  
279 =item converter
280  
281 =item thumbnail
282  
283 =back
284  
285 TODO - there are more fields that need explanation.
286  
287 =head2 Source directory hierarchy
288  
289 The source directory defined using the C<source_dir> paramater can havs subdirectories, but each subdirectory needs
290 a 'parent' page. The name of the parent page is the same as the name of the subdirectory with the additional .txt
291 extentsion. So if you'd like to have a C<src/project/> subdriectory, you also need to have a page called
292 C<src/project.txt>.
293  
294 If there is no index.txt in the src/ directory, Blio will generate a default index.html file.
295 This is not the case with subdirectories.
296  
297 =head2 Source files
298  
299 Each source file has a txt extension. It has several lines of header and a body.
300 The module that represents each file is L<Blio::Node>.
301  
302 title: The Project
303 date: 2013-02-10T00:27:53
304 language: en
305 converter: textile
306 tags: Perl
307  
308 This is the project page.
309  
310 The only required entry in the header is the C<title>.
311  
312 TODO - there are more fields that need explanation.
313  
314 =head1 AUTHOR
315  
316 Thomas Klausner <domm@cpan.org>
317  
318 =head1 COPYRIGHT AND LICENSE
319  
320 This software is copyright (c) 2013 by Thomas Klausner.
321  
322 This is free software; you can redistribute it and/or modify it under
323 the same terms as the Perl 5 programming language system itself.
324  
325 =cut
« blib/lib/Blio/Image.pm ↑ Summary blib/script/blio.pl »