File Coverage

lib/WWW/Mixi/Scraper/Utils.pm
Criterion Covered Total %
statement 15 33 45.4
branch 0 14 0.0
condition 0 3 0.0
subroutine 5 8 62.5
pod n/a
total 20 58 34.4


line stmt bran cond sub pod time code
1             package WWW::Mixi::Scraper::Utils;
2            
3 1     1   4 use strict;
  1         1  
  1         28  
4 1     1   5 use warnings;
  1         1  
  1         22  
5 1     1   3 use base qw/Exporter/;
  1         2  
  1         58  
6 1     1   981 use URI;
  1         5375  
  1         21  
7 1     1   961 use URI::QueryParam;
  1         615  
  1         10  
8            
9             our @EXPORT_OK = qw( _force_arrayref _uri _datetime );
10            
11             sub _force_arrayref {
12 0     0     my $thingy = shift;
13            
14 0 0 0       return [] if !defined $thingy || $thingy eq '';
15 0 0         return [$thingy] if ref $thingy ne 'ARRAY';
16 0           return $thingy;
17             }
18            
19             sub _datetime {
20 0     0     my $date = shift;
21            
22 0 0         unless ( defined $date ) {
23 0           warn "datetime is not defined"; return;
  0            
24             }
25            
26 0           my $time;
27 0 0         if ( $date =~ s/\s*(\d+:\d+(?::\d+)?)\s*$// ) {
28 0           $time = $1;
29             }
30            
31 0           $date =~ s/\D/\-/g;
32 0           $date =~ s/\-+$//;
33            
34 0 0         return $time ? "$date $time" : $date; # should be DateTime object?
35             }
36            
37             sub _uri {
38 0     0     my $uri = URI->new(shift);
39 0 0         $uri->authority('mixi.jp') unless $uri->authority;
40 0 0         $uri->scheme('http') unless $uri->scheme;
41 0           return $uri;
42             }
43            
44             1;
45            
46             __END__