lib/Blio.pm

filter: Statementstmt 77.0% 104 / 135 Branchbran 65.0% 13 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 81.4% 22 / 27 Podpod 0.0% 0 / 7 totaltotal 72.1% 140 / 194 CC 15 SCAR 14.9
CC
15
Cov
75%
write_tree_up
12.0
collect
10.5
write_tree_down
6.0
CRAP 4.4
« lib/Blio/Node.pm ↑ Summary lib/Blio/Image.pm »
1 package Blio;
2 15 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 # ABSTRACT: domms blogging "engine"
5  
6 15 our $VERSION = '2.009'; # VERSION
7  
8 15 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use MooseX::Types::Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶use Path::Class::Iterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶use File::ShareDir qw(dist_dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 15 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 15 ▶use MIME::Base64 qw(encode_base64url);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 15 ▶use Blio::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 15 with 'MooseX::Getopt';
20 15 with 'MooseX::SimpleConfig';
21  
22 15 has '+configfile' => ( default => 'blio.ini' );
23 15 has 'source_dir' => (
24 is => 'ro',
25 isa => 'Path::Class::Dir',
26 required => 1,
27 coerce => 1,
28 lazy_build => 1
29 );
30 1 ▶sub _build_source_dir {
Subroutine _build_source_dir: called CC=1 SCAR=0.0
31 1 my $self = shift;
32 1 return Path::Class::Dir->new->subdir('src');
33 }
34  
35 15 has 'output_dir' => (
36 is => 'ro',
37 isa => 'Path::Class::Dir',
38 required => 1,
39 coerce => 1,
40 lazy_build => 1
41 );
42 1 ▶sub _build_output_dir {
Subroutine _build_output_dir: called CC=1 SCAR=0.0
43 1 my $self = shift;
44 1 return Path::Class::Dir->new->subdir('out');
45 }
46  
47 15 has 'template_dir' => (
48 is => 'ro',
49 isa => 'Path::Class::Dir',
50 required => 1,
51 coerce => 1,
52 lazy_build => 1
53 );
54 1 ▶sub _build_template_dir {
Subroutine _build_template_dir: called CC=1 SCAR=0.0
55 1 my $self = shift;
56 1 return Path::Class::Dir->new->subdir('templates');
57 }
58  
59 15 has 'name' => (is=>'ro',isa=>'Str',default=>'Blio',required=>1);
60 15 has 'site_url' => (is=>'ro',isa=>'Str',required=>0);
61 15 has 'site_author' => (is=>'ro',isa=>'Str',required=>0);
62 15 has 'language' => (is=>'ro',isa=>'Str',default=>'en',required=>1);
63 15 has 'converter' => (is=>'ro',isa=>'Maybe[Str]',default=>undef,required=>1);
64 15 has 'thumbnail' => (is=>'ro',isa=>'Int',default=>300,required=>1);
65 15 has 'tags' => (is=>'ro',isa=>'Bool',default=>0);
66 15 has 'schedule' => (is=>'ro',isa=>'Bool',default=>0);
67 15 has 'time_zone' => (is=>'ro',isa=>'Str', default=>'UTC');
68 15 has 'images_as_nodes' => (is=>'ro',isa=>'Bool',default=>0);
69  
70 15 has 'force' => (is=>'ro',isa=>'Bool',default=>0);
71 15 has 'quiet' => (is=>'ro',isa=>'Bool',default=>0);
72 15 has 'recent' => (is=>'ro',isa=>'Bool',default=>0);
73  
74 13 ▶has 'nodes_by_url' => ( is => 'ro', isa => 'HashRef', default => sub { {} } ,traits => [ 'NoGetopt' ]);
Subroutine __ANON__: called CC=1 SCAR=0.0
75 has 'tree' => (
76 is => 'ro',
77 isa => 'ArrayRef[Blio::Node]',
78 13 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
79 15 traits => ['Array', 'NoGetopt'],
80 handles => { add_top_node => 'push', },
81 );
82 15 has 'tt' => (
83 is=>'ro',
84 isa=>'Template',
85 lazy_build => 1,
86 traits => [ 'NoGetopt' ],
87 );
88 4 ▶sub _build_tt {
Subroutine _build_tt: called CC=1 SCAR=0.0
89 4 my $self = shift;
90 4 return Template->new({
91 OUTPUT_PATH=>$self->output_dir->stringify,
92 INCLUDE_PATH=>[$self->template_dir->stringify, dir(dist_dir('Blio'),'templates')->stringify],
93 WRAPPER=>'wrapper.tt',
94 ENCODING => 'UTF8',
95 });
96 }
97  
98 15 has 'nodes_by_date' => (is=>'ro', isa=>'ArrayRef',lazy_build=>1,traits => [ 'NoGetopt' ]);
99 0 ▶sub _build_nodes_by_date {
Subroutine _build_nodes_by_date: not called CC=1 SCAR=6.9
100 0 my $self = shift;
101  
102 my @sorted =
103 0 map { $_->[0] }
104 0 sort { $b->[1] <=> $a->[1] }
105 0 map { [$_ => $_->date->epoch] }
106 0 values %{$self->nodes_by_url};
107 0 return \@sorted;
108 }
109 13 ▶has 'stash' => (is=>'ro',isa=>'HashRef',default=>sub {{}},traits => [ 'NoGetopt' ]);
Subroutine __ANON__: called CC=1 SCAR=0.0
110  
111 15 has 'tagindex' => (
112 is=>'rw',
113 isa=>'Blio::Node',
114 lazy_build=>1,
115 traits => [ 'NoGetopt' ],
116 );
117 1 ▶sub _build_tagindex {
Subroutine _build_tagindex: called CC=1 SCAR=0.0
118 1 my $self = shift;
119 1 my $tagindex = Blio::Node->new(
120 base_dir => $self->source_dir,
121 source_file => $0,
122 id=>'tags.html',
123 url=>'tags.html',
124 title=>'Tags',
125 date=>DateTime->now,
126 content=>'',
127 list=>1,
128 );
129 1 $self->nodes_by_url->{'tags.html'}=$tagindex;
130 1 return $tagindex;
131 }
132  
133 3 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
134 3 my $self = shift;
135  
136 3 $self->collect;
137 3 $self->write;
138 }
139  
140 6 ▶sub collect {
Subroutine collect: called CC=9 SCAR=23.5
Pod undocumented
141 6 my $self = shift;
142 6 my $iterator = Path::Class::Iterator->new(
143 root => $self->source_dir,
144 breadth_first => 1,
145 );
146  
147 6 my $schedule = $self->schedule;
148 6 my $now = DateTime->now(time_zone=>$self->time_zone);
149  
150 6 ▶ until ( $iterator->done ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($iterator->done) 48 6 54
151 48 my $file = $iterator->next;
152 48 ▶ next if -d $file;
Branch: 1 branch
BranchTrueFalseTotal
if -d $file 13 35 48
153 35 ▶ next unless $file =~ /\.txt$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /\.txt$/u 6 29 35
154  
155 29 my $node = Blio::Node->new_from_file( $self, $file );
156 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
157 0 say "skipping ".$node->id." (scheduled for ".$node->date." but now is ".$now.")";
158 0 next;
159 }
160 29 $self->nodes_by_url->{ $node->url } = $node;
161  
162 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
163 $self->source_dir->stringify ) {
164 12 $self->add_top_node($node);
165 }
166 else {
167 17 my $possible_parent_url = $node->possible_parent_url;
168 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
169 17 $node->parent($parent);
170 17 $parent->add_child($node);
171 #say $node->url .' is child of '.$parent->url;
172 }
173 else {
174 0 say "Cannot find parent, but not a root node: " . $node->url;
175 0 say "For each subdirectoy, you need a file in the parent directory";
176 0 say "with the name of the subdirectory and .txt extension";
177 0 say "Need a file called " . $node->source_file->parent->stringify . '.txt';
178 0 exit 0;
179 }
180 }
181 }
182  
183 6 ▶ unless ($self->nodes_by_url->{'index.html'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->nodes_by_url->{"index.html"}) 6 0 6
184 6 my $index = Blio::Node->new(
185 base_dir => $self->source_dir,
186 source_file => $0,
187 id=>'index.html',
188 url=>'index.html',
189 title=>'Index',
190 date=>DateTime->now,
191 content=>'',
192 );
193 6 $self->nodes_by_url->{'index.html'}=$index;
194 6 $index->children($self->tree);
195 }
196 }
197  
198 3 ▶sub write {
Subroutine write: called CC=2 SCAR=6.9
Pod undocumented
199 3 my $self = shift;
200  
201 3 for my $node (values %{$self->nodes_by_url}) {
202 8 $self->_write($node);
203 }
204 }
205  
206 0 ▶sub write_tree_up {
Subroutine write_tree_up: not called CC=3 SCAR=24.8
Pod undocumented
207 0 my ($self, $node) = @_;
208  
209 0 $self->_write($node);
210 0 my $siblings = $node->older_younger;
211 0 for my $sib (values %$siblings) {
212 0 $self->_write($sib, $node->date);
213 }
214  
215 0 ▶ if (my $p = $node->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $p = $node->parent) 0 0 0
216 0 $p->date($node->date);
217 0 $self->write_tree_up($p);
218 }
219 }
220  
221 0 ▶sub write_tree_down {
Subroutine write_tree_down: not called CC=2 SCAR=17.9
Pod undocumented
222 0 my ($self, $node) = @_;
223  
224 0 $self->_write($node);
225 0 for my $child ($node->children->@*) {
226 0 $self->write_tree_down($child);
227 }
228 }
229  
230  
231 8 ▶sub _write {
Subroutine _write: called CC=3 SCAR=12.0
232 8 my ($self, $node, $utime) = @_;
233 8 ▶ say "writing ".$node->url unless $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quiet 8 0 8
234 8 ▶ if ($node->paged_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->paged_list) { } 0 8 8
235 0 $node->write_paged_list($self);
236 }
237 else {
238 8 $node->write($self, $utime);
239 }
240 }
241  
242 0 ▶sub absolute_url {
Subroutine absolute_url: not called CC=1 SCAR=6.9
Pod undocumented
243 0 my ($self, $node) = @_;
244 0 return $self->site_url.'/'.$node->url;
245 }
246  
247 0 ▶sub absolute_base64_url {
Subroutine absolute_base64_url: not called CC=1 SCAR=6.9
Pod undocumented
248 0 my ($self, $node) = @_;
249 0 return encode_base64url($self->absolute_url($node));
250 }
251  
252 15 __PACKAGE__->meta->make_immutable;
253 15 1;
254  
255 __END__
« lib/Blio/Node.pm ↑ Summary lib/Blio/Image.pm »