File Coverage

blib/lib/Bootylicious/TagCloud.pm
Criterion Covered Total %
statement 35 36 97.2
branch 4 6 66.6
condition 4 4 100.0
subroutine 7 8 87.5
pod 1 3 33.3
total 51 57 89.4


line stmt bran cond sub pod time code
1             package Bootylicious::TagCloud;
2              
3 5     5   567 use strict;
  5         7  
  5         113  
4 5     5   24 use warnings;
  5         5  
  5         99  
5              
6 5     5   15 use base 'Mojo::Base';
  5         5  
  5         323  
7              
8             __PACKAGE__->attr('articles');
9              
10 5     5   18 use Bootylicious::Iterator;
  5         4  
  5         28  
11 5     5   1650 use Bootylicious::Tag;
  5         9  
  5         21  
12              
13             sub new {
14 3     3 1 26 my $self = shift->SUPER::new(@_);
15              
16 3         25 return $self->build;
17             }
18              
19 0     0 0 0 sub modified { shift->articles->modified }
20              
21             sub build {
22 3     3 0 5 my $self = shift;
23              
24 3         6 my $tags = {};
25 3         18 while (my $article = $self->articles->next) {
26 3         5 foreach my $name (@{$article->tags}) {
  3         8  
27 7         10 my $tag = $tags->{$name};
28              
29 7   100     24 $tag->{count} ||= 0;
30 7         8 $tag->{count}++;
31              
32 7 100       24 $tag->{created} = $article->created unless $tag->{created};
33             $tag->{created} = $article->created
34 7 50       13 if $article->created < $tag->{created};
35 7   100     18 $tag->{modified} ||= 0;
36             $tag->{modified} = $article->modified
37 7 50       18 if $article->modified > $tag->{modified};
38              
39 7         17 $tags->{$name} = $tag;
40             }
41             }
42              
43 3         5 my @tags;
44 3         17 foreach my $name (sort keys %$tags) {
45 6         29 my $tag = $tags->{$name};
46              
47             push @tags,
48             Bootylicious::Tag->new(
49             name => $name,
50             count => $tag->{count},
51             created => $tag->{created},
52             modified => $tag->{modified}
53 6         22 );
54             }
55              
56 3         22 return Bootylicious::Iterator->new(elements => [@tags]);
57             }
58              
59             1;