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