File Coverage

blib/lib/Bootylicious/Article.pm
Criterion Covered Total %
statement 64 73 87.6
branch 9 16 56.2
condition 2 3 66.6
subroutine 19 20 95.0
pod 0 11 0.0
total 94 123 76.4


line stmt bran cond sub pod time code
1             package Bootylicious::Article;
2              
3 13     13   3415 use strict;
  13         15  
  13         959  
4 13     13   37 use warnings;
  13         11  
  13         266  
5              
6 13     13   42 use base 'Bootylicious::Document';
  13         12  
  13         4062  
7              
8 13     13   50 use Bootylicious::Timestamp;
  13         14  
  13         56  
9 13     13   4443 use Bootylicious::Pingback;
  13         21  
  13         70  
10 13     13   4467 use Bootylicious::PingbackIterator;
  13         18  
  13         70  
11 13     13   4463 use Bootylicious::PingbackIteratorFinder;
  13         20  
  13         45  
12 13     13   4138 use Bootylicious::Comment;
  13         20  
  13         73  
13 13     13   4339 use Bootylicious::CommentIteratorLoader;
  13         23  
  13         61  
14              
15 18 50   18 0 28 sub title { my $self = shift; $self->metadata(title => @_) || $self->name }
  18         50  
16 1     1 0 8 sub description { shift->metadata(description => @_) }
17 8     8 0 381 sub link { shift->metadata(link => @_) }
18              
19             sub tags {
20 20     20 0 26 my $self = shift;
21 20         19 my $value = shift;
22              
23 20 50       39 if (defined $value) {
24             $value = join ', ' => sort keys %{
25 0 0       0 { map { $_ => 1 }
  0         0  
26 0         0 map { s/^\s+//; s/\s+$//; $_ }
  0         0  
  0         0  
27 0         0 grep { $_ ne '' } split ',' => $value
  0         0  
28             }
29             } if $value ne '';
30 0         0 return $self->metadata(tags => $value);
31             }
32              
33 20         42 my $tags = $self->metadata('tags');
34 20 50       39 return [] unless $tags;
35              
36 20         76 return [map { s/^\s+//; s/\s+$//; $_ } split ',' => $tags];
  50         100  
  50         65  
  50         103  
37             }
38              
39 0 0   0 0 0 sub has_tags { shift->tags ? 1 : 0 }
40              
41             sub comments_enabled {
42 3     3 0 33 my $self = shift;
43              
44 3         16 my $comments = $self->metadata('comments');
45              
46 3 100 66     28 return defined $comments && $comments =~ /^(no|false|disable)$/i ? 0 : 1;
47             }
48              
49             sub pingbacks {
50 8     8 0 1545 my $self = shift;
51              
52 8         24 return Bootylicious::PingbackIterator->new(
53             path => $self->path . '.pingbacks');
54             }
55              
56             sub has_pingback {
57 5     5 0 21 my $self = shift;
58 5         6 my $source_uri = shift;
59              
60 5         12 my $finder =
61             Bootylicious::PingbackIteratorFinder->new(iterator => $self->pingbacks);
62              
63 5 100       16 return $finder->find($source_uri) ? 1 : 0;
64             }
65              
66             sub pingback {
67 2     2 0 7 my $self = shift;
68 2         3 my $source_uri = shift;
69              
70 2         14 my $pingback = Bootylicious::Pingback->new(
71             created => Bootylicious::Timestamp->new(epoch => time),
72             source_uri => $source_uri
73             );
74 2         13 return $pingback->create($self->path . '.pingbacks');
75             }
76              
77             sub comments {
78 15     15 0 25 my $self = shift;
79              
80 15         47 return Bootylicious::CommentIteratorLoader->new(path => $self->path)
81             ->load(Bootylicious::Iterator->new);
82             }
83              
84             sub comment {
85 4     4 0 9 my $self = shift;
86 4         16 my %params = @_;
87              
88 4         5 my $number = 1;
89              
90 4 100       9 if (my $last = $self->comments->last) {
91 3         7 ($number) = ($last->path =~ m/\.comment-(\d+)/);
92 3         44 $number++;
93             }
94              
95 4         17 my $path = $self->path . '.comment-' . $number;
96              
97 4         29 my $comment = Bootylicious::Comment->new(@_);
98              
99 4         13 return $comment->create($path);
100             }
101              
102             1;