blib/lib/Blio/Node.pm

filter: Statementstmt 56.1% 179 / 319 Branchbran 33.3% 36 / 108 Conditioncond 10.0% 4 / 40 MC/DCmcdc 8.0% 2 / 25 Subroutinesub 71.4% 30 / 42 Podpod 0.0% 0 / 18 totaltotal 45.4% 251 / 552 CC 76 SCAR 38.9
CC
76
Cov
47%
write_feed
240.0
prev_next_post
90.0
write_paged_list
56.0
CRAP 48.8
↑ Summary Build »
1 package Blio::Node;
2  
3 # ABSTRACT: A Blio Node
4  
5 16 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use MooseX::Types::Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use DateTime::Format::ISO8601;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 16 ▶use Markup::Unified;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 16 ▶use Blio::Image;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 16 ▶use XML::Atom::SimpleFeed;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 16 ▶use DateTime::Format::RFC3339;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 16 class_type 'DateTime';
18 coerce 'DateTime' => from 'Int' => via {
19 2 ▶ my $d = DateTime->from_epoch( epoch => $_ );
Subroutine __ANON__: called CC=1 SCAR=0.4
20 2 $d->set_time_zone('local');
21 0 return $d;
22 21 ▶} => from 'Str' => via { DateTime::Format::ISO8601->parse_datetime($_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
23  
24 16 has 'base_dir' => ( is => 'ro', isa => 'Path::Class::Dir', required => 1 );
25 16 has 'source_file' =>
26 ( is => 'ro', isa => 'Path::Class::File', required => 1, coerce => 1 );
27 16 has 'id' => (is => 'ro', isa=>'Str', required=>1, lazy_build=>1);
28 sub _build_id {
29 34 ▶ my $self = shift;
Subroutine _build_id: called CC=1 SCAR=0.0
30 34 my $path = $self->source_file->relative($self->base_dir)->stringify;
31 34 $path=~s/\.txt$//;
32 34 return $path;
33 }
34 16 has 'url' => ( is => 'ro', isa => 'Str', lazy_build => 1 );
35 sub _build_url {
36 34 ▶ my $self = shift;
Subroutine _build_url: called CC=1 SCAR=0.0
37 34 return $self->id.'.html';
38 }
39  
40 16 has 'template' => (is=>'rw',isa=>'Str',required=>1,default=>'node.tt');
41 16 has 'title' => ( is => 'ro', isa => 'Str', required => 1 );
42 16 has 'date' => (
43 is => 'rw',
44 isa => 'DateTime',
45 required => 1,
46 lazy_build => 1,
47 coerce => 1
48 );
49 sub _build_date {
50 2 ▶ my $self = shift;
Subroutine _build_date: called CC=1 SCAR=0.0
51 2 my $stat = $self->source_file->stat;
52 2 return $stat->mtime;
53 }
54  
55 16 has 'language' => (is=>'ro', isa=>'Maybe[Str]');
56 16 has 'converter' => (is=>'ro', isa=>'Maybe[Str]');
57 16 has 'feed' => (is=>'ro',isa=>'Bool',default=>0);
58 16 has 'author' => (is=>'ro',isa=>'Str');
59 16 has 'paged_list' => (is=>'ro',isa=>'Int',default=>0);
60 16 has 'prev_next_nav' => (is=>'ro',isa=>'Int',default=>0);
61 16 has 'list_image' => (is=>'ro',isa=>'Str');
62  
63 16 has 'raw_content' => ( is => 'rw', isa => 'Str' );
64 16 has 'content' => ( is => 'rw', isa => 'Str', lazy_build=>1 );
65 sub _build_content {
66 8 ▶ my $self = shift;
Subroutine _build_content: called CC=4 SCAR=16.5
67 8 my $converter = $self->converter;
68 8 my $raw_content = $self->raw_content;
69 8 ▶ return $raw_content unless $converter;
Branch: 1 branch
BranchTrueFalseTotal
unless $converter 7 1 8
70  
71 1 ▶ if ($self->inline_images) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->inline_images) 0 1 1
72 0 $raw_content=~s/<bliothumb:(.*?)>/$self->call_on_image_by_name($1,'thumbnail')/ge;
73 0 $raw_content=~s/<blioimg:(.*?)>/$self->call_on_image_by_name($1,'url')/ge;
74  
75 0 $raw_content=~s/<bliothumb#(\d+)>/$self->call_on_image_by_index($1,'thumbnail')/ge;
76 0 $raw_content=~s/<blioimg#(\d+)>/$self->call_on_image_by_index($1,'url')/ge;
77 }
78  
79 16 ▶ no if $] >= 5.018, 'warnings', "experimental::smartmatch"; # TODO # why, oh, why???
Subroutine BEGIN: called CC=1 SCAR=0.0
80 1 given ($converter) {
81 1 when ('html') { return $raw_content }
82 1 when ([qw(textile markdown bbcode)]) {
83 0 my $o = Markup::Unified->new();
84 0 return $o->format($raw_content, 'textile')->formatted;
85 }
86 1 default {
87 1 my $method = 'convert_'.$converter;
88 1 ▶ if ($self->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($method)) { } 0 1 1
89 0 return $self->$method($raw_content);
90 }
91 else {
92 1 return "<pre>No such converter: $converter</pre>".$raw_content;
93 }
94 }
95 }
96 }
97 has 'tags' => (
98 is => 'rw',
99 isa => 'ArrayRef',
100 46 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
101 16 traits => ['Array'],
102 handles => {
103 has_tags => 'count',
104 },
105 );
106 has 'images' => (
107 is => 'rw',
108 isa => 'ArrayRef[Blio::Image]',
109 46 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
110 16 traits => ['Array'],
111 handles => {
112 has_images => 'count',
113 add_image => 'push',
114 },
115 );
116 16 has 'inline_images' => (is=>'ro',isa=>'Bool',default=>0);
117 16 has 'thumbnail' => (is=>'ro',isa=>'Int');
118  
119 has 'children' => (
120 is => 'rw',
121 isa => 'ArrayRef[Blio::Node]',
122 46 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
123 16 traits => ['Array'],
124 handles => {
125 has_children => 'count',
126 add_child => 'push',
127 },
128  
129 );
130 16 has 'parent' => ( is => 'rw', isa => 'Maybe[Blio::Node]', weak_ref => 1);
131 10 ▶has 'stash' => (is=>'ro',isa=>'HashRef',default=>sub {{}});
Subroutine __ANON__: called CC=1 SCAR=0.0
132 16 has 'feed_url' => (is=>'ro',isa=>'Str',lazy_build=>1);
133 sub _build_feed_url {
134 0 ▶ my $self = shift;
Subroutine _build_feed_url: not called CC=1 SCAR=6.9
135 0 return $self->id.'.xml';
136 }
137  
138 sub new_from_file {
139 36 ▶ my ( $class, $blio, $file ) = @_;
Subroutine new_from_file: called CC=8 SCAR=20.8
Pod undocumented
140 36 my @lines = $file->slurp(
141 chomp => 1,
142 iomode => '<:encoding(UTF-8)',
143 );
144 36 my ( $header, $raw_content ) = $class->parse(@lines);
145 36 my $tags = delete $header->{tags};
146 36 my $node = $class->new(
147 base_dir => $blio->source_dir,
148 language => $blio->language,
149 converter => $blio->converter,
150 source_file => $file,
151 %$header,
152 raw_content => $raw_content,
153 stash=>$header,
154 );
155  
156 36 ▶ $node->register_tags($blio, $tags) if $tags && $blio->tags;
Branch: 1 branch
BranchTrueFalseTotal
if $tags and $blio->tags 2 34 36
Condition100%3/3
$tags and $blio->tags
!ll&&!rl&&r
2772
MC/DC100%2/2
$tags and $blio->tags
$tags $blio->tags
Truth table100%3/3
A and B
A= $tagsB= $blio->tags
ABresult
0X0
100
111
157  
158 # check and add single image
159 36 foreach my $ext (qw(jpg jpeg png)) {
160 108 my $single_image = $file->basename;
161 108 $single_image =~ s/\.txt$/.$ext/i;
162 108 my $single_image_file = $file->parent->file($single_image);
163 108 ▶ if (-e $single_image_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $single_image_file) 0 108 108
164 0 my $img = Blio::Image->new(
165 base_dir => $blio->source_dir,
166 source_file => $single_image_file,
167 );
168 0 $node->add_image($img);
169 }
170 }
171  
172 # check and add images dir
173 36 my $img_dir = $file->basename;
174 36 $img_dir=~s/\.txt$//;
175 36 $img_dir = $file->parent->subdir($img_dir.'_images');
176 36 ▶ if (-d $img_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $img_dir) 5 31 36
177 5 ▶ while (my $image_file = $img_dir->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $image_file = $img_dir->next) 18 5 23
178 18 ▶ next unless $image_file =~ /\.(jpe?g|png)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $image_file =~ /\.(jpe?g|png)$/i 10 8 18
179 8 my $img = Blio::Image->new(
180 base_dir => $blio->source_dir,
181 source_file => $image_file,
182 );
183 8 $node->add_image($img);
184 }
185 }
186  
187 36 return $node;
188 }
189  
190 sub parse {
191 38 ▶ my ( $class, @lines ) = @_;
Subroutine parse: called CC=4 SCAR=13.9
Pod undocumented
192 38 my %header;
193 38 ▶ while ( my $line = shift(@lines) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = shift @lines) 86 37 123
194 86 ▶ last if $line =~ /^\s+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s+$/ 1 85 86
195 85 ▶ last unless $line =~ /:/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /:/ 0 85 85
196 85 chomp($line);
197 85 $line=~s/\s+$//;
198 85 my ( $key, $value ) = split( /\s*:\s*/, $line, 2 );
199 85 $header{ lc($key) } = $value;
200 }
201 38 my $content = join( "\n", @lines );
202 38 return \%header, $content;
203 }
204  
205 sub write {
206 9 ▶ my ($self, $blio) = @_;
Subroutine write: called CC=11 SCAR=29.1
Pod undocumented
207  
208 9 my $tt = $blio->tt;
209 9 my $outfile = $blio->output_dir->file($self->url);
210 9 ▶ $outfile->parent->mkpath unless (-d $outfile->parent);
Branch: 1 branch
BranchTrueFalseTotal
unless -d $outfile->parent 4 5 9
211  
212 9 ▶ $tt->process($self->template,
Branch: 1 branch
BranchTrueFalseTotal
$tt->process($self->template, {"node", $self, "blio", $blio, "base", $self->relative_root}, $outfile->relative($blio->output_dir)->stringify, "binmode", ":utf8") or die $tt->error 1 8 9
213 {
214 node=>$self,
215 blio=>$blio,
216 base=>$self->relative_root,
217 },
218 ,$outfile->relative($blio->output_dir)->stringify,
219 binmode => ':utf8',
220 ) || die $tt->error;
221  
222 8 my $utime = $self->date->epoch;
223 7 ▶ if ($self->has_children) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_children) 2 5 7
224 2 my $children = $self->sorted_children;
225 2 my $child_utime = $children->[0]->date->epoch;
226 2 ▶ $utime = $child_utime if $child_utime > $utime;
Branch: 1 branch
BranchTrueFalseTotal
if $child_utime > $utime 1 1 2
227 }
228 7 utime($utime,$utime,$outfile->stringify);
229  
230 7 ▶ if ($self->has_images) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_images) 0 7 7
231 0 foreach my $img (@{$self->images}) {
232 0 ▶ if ($blio->force || !-e $blio->output_dir->file($img->thumbnail)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($blio->force or not -e $blio->output_dir->file($img->thumbnail)) 0 0 0
Condition0%0/3
$blio->force or not -e $blio->output_dir->file($img->thumbnail)
l!l&&r!l&&!r
000
MC/DC0%0/2
$blio->force or not -e $blio->output_dir->file($img->thumbnail)
$blio->force not -e $blio->output_dir->file($img->thumbnail)
Truth table0%0/3
A or not(B)
A= $blio->forceB= not -e $blio->output_dir->file($img->thumbnail)
ABresult
1X1
011
000
233 0 ▶ say "\timage ".$img->url unless $blio->quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $blio->quiet 0 0 0
234 0 $img->publish($blio);
235 0 $img->make_thumbnail($blio, $self->thumbnail);
236 }
237 }
238 }
239  
240 7 ▶ $self->write_feed($blio) if $self->feed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->feed 0 7 7
241 }
242  
243 sub write_paged_list {
244 0 ▶ my ($self, $blio) = @_;
Subroutine write_paged_list: not called CC=7 SCAR=40.3
Pod undocumented
245  
246 0 my $list = $self->sorted_children;
247 0 my $items_per_page = $self->paged_list;
248 0 my $current_page = 1;
249 0 my $outfile = $blio->output_dir->file($self->url);
250 0 my $utime=0;
251 0 my @page;
252 0 foreach my $i (0 .. $#{$list}) {
253 0 ▶ if ($i>0 && $i % $items_per_page == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0 and $i % $items_per_page == 0) 0 0 0
Condition0%0/3
$i > 0 and $i % $items_per_page == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$i > 0 and $i % $items_per_page == 0
$i > 0 $i % $items_per_page == 0
Truth table0%0/3
A and B
A= $i > 0B= $i % $items_per_page == 0
ABresult
0X0
100
111
254 # write this page
255 0 $self->_write_page($blio, \@page, $current_page, $list, $outfile, $utime, $i);
256  
257 # start new page
258 0 my $utime=0;
259 0 @page=();
260 0 $current_page++;
261 0 $outfile = $blio->output_dir->file($self->id."_".$current_page.'.html');
262 }
263 0 push(@page, $list->[$i]);
264 0 my $this_utime = $list->[$i]->date->epoch;
265 0 ▶ $utime = $this_utime if $this_utime > $utime;
Branch: 1 branch
BranchTrueFalseTotal
if $this_utime > $utime 0 0 0
266 # write last page
267 0 ▶ $self->_write_page($blio, \@page, $current_page, $list, $outfile, $utime) if $i == $#{$list} ;
Branch: 1 branch
BranchTrueFalseTotal
if $i == $#{$list;} 0 0 0
268 }
269  
270 0 ▶ $self->write_feed($blio) if $self->feed;
Branch: 1 branch
BranchTrueFalseTotal
if $self->feed 0 0 0
271 }
272  
273 sub _write_page {
274 0 ▶ my ($self, $blio, $page, $current_page, $list, $outfile, $utime, $i ) = @_;
Subroutine _write_page: not called CC=6 SCAR=37.4
275 0 my $tt = $blio->tt;
276 0 my $data = {
277 node=>$self,
278 page=>$page,
279 blio=>$blio,
280 base=>$self->relative_root,
281 };
282 0 ▶ $data->{prev} = sprintf("%s_%i.html",$self->id, $current_page-1) if $current_page > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $current_page > 1 0 0 0
283 0 ▶ $data->{prev} = $self->url if $current_page==2;
Branch: 1 branch
BranchTrueFalseTotal
if $current_page == 2 0 0 0
284 0 ▶ $data->{next} = sprintf("%s_%i.html",$self->id, $current_page+1) if $i && $list->[$i+1];
Branch: 1 branch
BranchTrueFalseTotal
if $i and $$list[$i + 1] 0 0 0
Condition0%0/3
$i and $$list[$i + 1]
!ll&&!rl&&r
000
MC/DC0%0/2
$i and $$list[$i + 1]
$i $$list[$i + 1]
Truth table0%0/3
A and B
A= $iB= $$list[$i + 1]
ABresult
0X0
100
111
285 0 ▶ $tt->process($self->template,
Branch: 1 branch
BranchTrueFalseTotal
$tt->process($self->template, $data, $outfile->relative($blio->output_dir)->stringify, "binmode", ":utf8") or die $tt->error 0 0 0
286 $data,
287 ,$outfile->relative($blio->output_dir)->stringify,
288 binmode => ':utf8',
289 ) || die $tt->error;
290 0 utime($utime,$utime,$outfile->stringify);
291 }
292  
293 sub relative_root {
294 13 ▶ my $self = shift;
Subroutine relative_root: called CC=2 SCAR=6.9
Pod undocumented
295 13 my $url = $self->url;
296 13 my @level = $url=~m{/}g;
297
298 13 ▶ return '' unless @level;
Branch: 1 branch
BranchTrueFalseTotal
unless @level 5 8 13
299
300 8 return join('/',map { '..' } @level).'/';
301 }
302  
303 sub possible_parent_url {
304 17 ▶ my $self = shift;
Subroutine possible_parent_url: called CC=1 SCAR=0.0
Pod undocumented
305 17 my $ppurl = $self->url;
306 17 $ppurl =~ s{/[\-\w]+.html$}{.html};
307 17 return $ppurl;
308 }
309  
310 sub sorted_children {
311 6 ▶ my ($self, $limit) = @_;
Subroutine sorted_children: called CC=3 SCAR=11.7
Pod undocumented
312 my @sorted =
313 12 map { $_->[0] }
314 9 sort { $b->[1] <=> $a->[1] }
315 6 map { [$_ => $_->date->epoch] } @{$self->children};
316 5 ▶ if ($limit && $limit < @sorted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit and $limit < @sorted) 0 5 5
Condition33%1/3
$limit and $limit < @sorted
!ll&&!rl&&r
500
MC/DC0%0/2
$limit and $limit < @sorted
$limit $limit < @sorted
Truth table33%1/3
A and B
A= $limitB= $limit < @sorted
ABresult
0X0
100
111
317 0 @sorted = splice(@sorted,0,$limit);
318 }
319 5 return \@sorted;
320 }
321  
322 sub sort_children_by {
323 0 ▶ my ($self, $order_by, $limit) = @_;
Subroutine sort_children_by: not called CC=3 SCAR=24.8
Pod undocumented
324 my @sorted =
325 0 map { $_->[0] }
326 0 sort { $a->[1] cmp $b->[1] }
327 0 map { [$_ => lc($_->$order_by)] } @{$self->children};
328 0 ▶ if ($limit && $limit < @sorted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit and $limit < @sorted) 0 0 0
Condition0%0/3
$limit and $limit < @sorted
!ll&&!rl&&r
000
MC/DC0%0/2
$limit and $limit < @sorted
$limit $limit < @sorted
Truth table0%0/3
A and B
A= $limitB= $limit < @sorted
ABresult
0X0
100
111
329 0 @sorted = splice(@sorted,0,$limit);
330 }
331 0 return \@sorted;
332 }
333  
334 sub sorted_images {
335 2 ▶ my $self = shift;
Subroutine sorted_images: called CC=1 SCAR=0.0
Pod undocumented
336 my @sorted =
337 3 map { $_->[0] }
338 1 sort { $a->[1] cmp $b->[1] }
339 2 map { [$_ => $_->source_file->basename ] } @{$self->images};
340 2 return \@sorted;
341 }
342  
343 sub teaser { # TODO enable simple "--fold--" syntax
344 0 ▶ my ($self, $length) = @_;
Subroutine teaser: not called CC=5 SCAR=34.0
Pod undocumented
345 0 ▶ return unless $self->raw_content;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->raw_content 0 0 0
346 0 ▶ $length ||= 200;
Condition0%0/2
$length ||= 200
l!l
00
MC/DC0%0/1
$length ||= 200
$length
Truth table0%0/2
A
A= $length
Aresult
11
00
347 0 my $teaser;
348 0 ▶ if ($length =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length =~ /^\d+$/) { } 0 0 0
349 0 $teaser = $self->content;
350 0 $teaser =~ s{</?(.*?)>}{}g;
351 0 $teaser = substr($teaser,0,$length);
352 0 $teaser =~s/\s\S+$/ .../;
353 }
354 else {
355 0 my $rest;
356 0 ($teaser, $rest) = split($length, $self->content, 2);
357 0 ▶ unless ($rest) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rest) 0 0 0
358 0 $teaser = $self->teaser(200);
359 }
360 }
361 0 return $teaser;
362 }
363  
364 sub write_feed {
365 0 ▶ my ($self, $blio) = @_;
Subroutine write_feed: not called CC=15 SCAR=54.8
Pod undocumented
366  
367 0 my $site_url = $blio->site_url;
368 0 ▶ die "Cannot generate Atom Feed without site_url, use --site_url to set it" unless $site_url;
Branch: 1 branch
BranchTrueFalseTotal
unless $site_url 0 0 0
369 0 ▶ $site_url .= '/' unless $site_url =~m{/$};
Branch: 1 branch
BranchTrueFalseTotal
unless $site_url =~ m[/$] 0 0 0
370  
371 0 my $children = $self->sorted_children(5);
372  
373 0 ▶ return unless @$children;
Branch: 1 branch
BranchTrueFalseTotal
unless @$children 0 0 0
374 0 my $rfc3339 = DateTime::Format::RFC3339->new();
375  
376 0 ▶ my $feed = XML::Atom::SimpleFeed->new(
Condition0%0/5
$self->title || 'no title'
l!l
00
$blio->site_author || $0
l!l&&r!l&&!r
000
MC/DC0%0/1
$self->title || 'no title'
$self->title
MC/DC0%0/2
$blio->site_author || $0
$blio->site_author $0
Truth table0%0/2
A
A= $self->title
Aresult
11
00
Truth table0%0/3
A || B
A= $blio->site_authorB= $0
ABresult
1X1
011
000
377 title=>$self->title || 'no title',
378 author=>$blio->site_author || $0,
379 link=>{
380 href=>$site_url.$self->feed_url,
381 rel=>'self',
382 },
383 id=>$site_url.$self->feed_url,
384 updated=>$rfc3339->format_datetime($children->[0]->date),
385 );
386  
387 0 foreach my $child (@$children) {
388 0 ▶ next unless $child->parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $child->parent 0 0 0
389 0 eval {
390 0 ▶ my @entry = (
Condition0%0/4
$child->title || 'no title'
l!l
00
$child->teaser || ' '
l!l
00
MC/DC0%0/1
$child->title || 'no title'
$child->title
MC/DC0%0/1
$child->teaser || ' '
$child->teaser
Truth table0%0/2
A
A= $child->title
Aresult
11
00
Truth table0%0/2
A
A= $child->teaser
Aresult
11
00
391 title=>$child->title || 'no title',
392 link=>$site_url.$child->url,
393 id=>$site_url.$child->url,
394 updated=>$rfc3339->format_datetime($child->date),
395 category=>$child->parent->id,
396 summary=>($child->teaser || ' '),
397 content=>$child->content,
398 );
399 0 ▶ push (@entry,author => $self->author) if $self->author;
Branch: 1 branch
BranchTrueFalseTotal
if $self->author 0 0 0
400 0 ▶ if ($child->has_tags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child->has_tags) 0 0 0
401 0 foreach my $tag (@{$child->tags}) {
402 0 push (@entry, category => $tag->title);
403 }
404 }
405 0 $feed->add_entry( @entry );
406 };
407 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
408 0 say "ERR $@";
409 }
410 }
411 0 my $feed_file = $blio->output_dir->file($self->feed_url);
412 0 ▶ open(my $fh,'>:encoding(UTF-8)',$feed_file->stringify) || die "Cannot write to Atom feed file $feed_file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:encoding(UTF-8)", $feed_file->stringify or die "Cannot write to Atom feed file ${feed_file}: $!" 0 0 0
413 0 $feed->print($fh);
414 0 close $fh;
415  
416 0 my $utime = $children->[0]->date->epoch;
417 0 utime($utime,$utime,$feed_file->stringify);
418 }
419  
420 sub register_tags {
421 2 ▶ my ($self, $blio, $tags ) = @_;
Subroutine register_tags: called CC=5 SCAR=16.1
Pod undocumented
422 2 my @tags = split(/\s*,\s*/,$tags);
423 2 my $tagindex = $blio->tagindex;
424 2 my @tagnodes;
425 2 foreach my $tag (@tags) {
426 4 my $tagid = $tag;
427 4 $tagid=~s/\s/_/g;
428 4 $tagid=~s/\W/_/g;
429 4 my $tagnode = $blio->nodes_by_url->{"tags/$tagid.html"};
430 4 ▶ unless ($tagnode) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagnode) 3 1 4
431 3 $tagnode = Blio::Node->new(
432 base_dir => $blio->source_dir,
433 source_file => $0,
434 id=>"tags/".$tagid.'.html',
435 url=>"tags/$tagid.html",
436 title=>$tag,
437 date=>DateTime->new(year=>1980),
438 content=>'',
439 );
440 3 $blio->nodes_by_url->{$tagnode->url} = $tagnode;
441 3 $tagnode->parent($tagindex);
442 3 $tagindex->add_child($tagnode);
443 }
444 4 $tagnode->add_child($self);
445 4 ▶ if ($self->date > $tagnode->date) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->date > $tagnode->date) 3 1 4
446 3 $tagnode->date($self->date);
447 }
448 4 push(@tagnodes,$tagnode);
449 }
450 2 ▶ $self->tags(\@tagnodes) if @tagnodes;
Branch: 1 branch
BranchTrueFalseTotal
if @tagnodes 2 0 2
451 }
452  
453 sub image_by_name {
454 0 ▶ my ($self, $name) = @_;
Subroutine image_by_name: not called CC=2 SCAR=17.9
Pod undocumented
455 0 my @found = grep { $name eq $_->source_file->basename } @{$self->images};
456 0 ▶ return $found[0] if @found == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @found == 1 0 0 0
457 0 return;
458 }
459  
460 sub call_on_image_by_name {
461 0 ▶ my ($self, $name, $method) = @_;
Subroutine call_on_image_by_name: not called CC=3 SCAR=24.8
Pod undocumented
462 0 ▶ $method ||= 'url';
Condition0%0/2
$method ||= "url"
l!l
00
MC/DC0%0/1
$method ||= "url"
$method
Truth table0%0/2
A
A= $method
Aresult
11
00
463 0 my $img = $self->image_by_name($name);
464 0 ▶ return "cannnot_resolve_image_$name" unless $img;
Branch: 1 branch
BranchTrueFalseTotal
unless $img 0 0 0
465 0 return $self->relative_root . $img->$method;
466 }
467  
468 sub image_by_index {
469 0 ▶ my ($self, $index) = @_;
Subroutine image_by_index: not called CC=1 SCAR=6.9
Pod undocumented
470  
471 0 return $self->images->[$index - 1];
472 }
473  
474 sub call_on_image_by_index {
475 0 ▶ my ($self, $index, $method) = @_;
Subroutine call_on_image_by_index: not called CC=2 SCAR=17.9
Pod undocumented
476 0 my $img = $self->image_by_index($index);
477 0 ▶ return "cannnot_resolve_image_$index" unless $img;
Branch: 1 branch
BranchTrueFalseTotal
unless $img 0 0 0
478 0 return $self->relative_root . $img->$method;
479 }
480  
481 sub primary_image {
482 0 ▶ my $self = shift;
Subroutine primary_image: not called CC=3 SCAR=24.8
Pod undocumented
483 0 my $img;
484 0 ▶ if ($self->list_image) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->list_image) 0 0 0
485 0 $img = $self->image_by_name( $self->list_image);
486 }
487 0 ▶ $img ||= $self->sorted_images->[0];
Condition0%0/3
$img ||= $self->sorted_images->[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$img ||= $self->sorted_images->[0]
$img $self->sorted_images->[0]
Truth table0%0/3
A ||= B
A= $imgB= $self->sorted_images->[0]
ABresult
1X1
011
000
488 0 return $img;
489 }
490  
491 sub prev_next_post {
492 0 ▶ my $self = shift;
Subroutine prev_next_post: not called CC=9 SCAR=45.0
Pod undocumented
493 0 ▶ return unless my $p = $self->parent;
Branch: 1 branch
BranchTrueFalseTotal
unless my $p = $self->parent 0 0 0
494 0 ▶ return unless $p->prev_next_nav;
Branch: 1 branch
BranchTrueFalseTotal
unless $p->prev_next_nav 0 0 0
495 0 my $siblings = $p->sorted_children;
496 0 my $hit;
497 my $i;
498 0 ▶ for ($i=0;$i<@$siblings;$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$siblings) 0 0 0
499 0 my $this = $siblings->[$i];
500 0 ▶ if ($this->id eq $self->id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->id eq $self->id) 0 0 0
501 0 $hit = $i;
502 0 last;
503 }
504 }
505 0 my %sib;
506 0 ▶ $sib{prev} = $siblings->[$i+1] if $i < $#{$siblings} && $siblings->[$i+1];
Branch: 1 branch
BranchTrueFalseTotal
if $i < $#{$siblings;} and $$siblings[$i + 1] 0 0 0
Condition0%0/3
$i < $#{$siblings;} and $$siblings[$i + 1]
!ll&&!rl&&r
000
MC/DC0%0/2
$i < $#{$siblings;} and $$siblings[$i + 1]
$i < $#{$siblings;} $$siblings[$i + 1]
Truth table0%0/3
A and B
A= $i < $#{$siblings;}B= $$siblings[$i + 1]
ABresult
0X0
100
111
507 0 ▶ $sib{next} = $siblings->[$i-1] if ($i-1 >= 0 && $siblings->[$i-1]);
Branch: 1 branch
BranchTrueFalseTotal
if $i - 1 >= 0 and $$siblings[$i - 1] 0 0 0
Condition0%0/3
$i - 1 >= 0 and $$siblings[$i - 1]
!ll&&!rl&&r
000
MC/DC0%0/2
$i - 1 >= 0 and $$siblings[$i - 1]
$i - 1 >= 0 $$siblings[$i - 1]
Truth table0%0/3
A and B
A= $i - 1 >= 0B= $$siblings[$i - 1]
ABresult
0X0
100
111
508 0 return \%sib;
509 }
510  
511 16 __PACKAGE__->meta->make_immutable;
512 16 1;
513  
514 =pod
515  
516 =encoding UTF-8
517  
518 =head1 NAME
519  
520 Blio::Node - A Blio Node
521  
522 =head1 VERSION
523  
524 version 2.003
525  
526 =head1 AUTHOR
527  
528 Thomas Klausner <domm@cpan.org>
529  
530 =head1 COPYRIGHT AND LICENSE
531  
532 This software is copyright (c) 2013 by Thomas Klausner.
533  
534 This is free software; you can redistribute it and/or modify it under
535 the same terms as the Perl 5 programming language system itself.
536  
537 =cut
538  
539 __END__
540  
541 A Blio Node.
542  
543 See L<blio.pl> for more info.
544  
545 more docs pending...
546  
↑ Summary Build »