File Coverage

blib/lib/HTML/TagCloud/Extended/Tag.pm
Criterion Covered Total %
statement 35 36 97.2
branch 3 4 75.0
condition 3 6 50.0
subroutine 7 7 100.0
pod 1 1 100.0
total 49 54 90.7


line stmt bran cond sub pod time code
1             package HTML::TagCloud::Extended::Tag;
2 3     3   23485 use strict;
  3         6  
  3         115  
3 3     3   17 use base qw/Class::Accessor::Fast/;
  3         6  
  3         1984  
4 3     3   10411 use Time::Local;
  3         5737  
  3         227  
5 3     3   1196 use HTML::TagCloud::Extended::Exception;
  3         9  
  3         1194  
6              
7             __PACKAGE__->mk_accessors(qw/name url count epoch/);
8              
9             sub new {
10 7     7 1 5931 my $class = shift;
11 7         25 my $self = bless { }, $class;
12 7         27 $self->_init(@_);
13 6         41 return $self;
14             }
15              
16             sub _init {
17 7     7   36 my ($self, %args) = @_;
18 7         20 my $epoch = $self->_timestamp2epoch($args{timestamp});
19 6   50     36 $self->name( $args{name} || '' );
20 6   50     76 $self->url( $args{url} || '' );
21 6   50     49 $self->count( $args{count} || 0 );
22 6         37 $self->epoch( $epoch );
23             }
24              
25             sub _timestamp2epoch {
26 7     7   9 my ($self, $timestamp) = @_;
27 7 50       20 if($timestamp) {
28 7         8 my($year, $month, $mday, $hour, $min, $sec);
29 7 100       48 if($timestamp =~ /^(\d{4})[-\/]{0,1}(\d{2})[-\/]{0,1}(\d{2})\s{0,1}(\d{2}):{0,1}(\d{2}):{0,1}(\d{2})$/) {
30 6         15 $year = $1;
31 6         13 $month = $2;
32 6         10 $mday = $3;
33 6         13 $hour = $4;
34 6         10 $min = $5;
35 6         11 $sec = $6;
36             } else {
37 1         10 HTML::TagCloud::Extended::Exception->throw(qq/
38             Wrong timestamp format "$timestamp".
39             /);
40             }
41 6         32 my $epoch = timelocal($sec, $min, $hour, $mday, $month - 1, $year - 1900);
42 6         399 return $epoch;
43             } else {
44 0           return time;
45             }
46             }
47             1;
48             __END__