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