line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::TimeAndDateCom::NewYearsCountdown; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
151597
|
use Moo; |
|
2
|
|
|
|
|
11616
|
|
|
2
|
|
|
|
|
13
|
|
4
|
2
|
|
|
2
|
|
2069
|
use Mojo::DOM; |
|
2
|
|
|
|
|
59420
|
|
|
2
|
|
|
|
|
55
|
|
5
|
2
|
|
|
2
|
|
638
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
33497
|
|
|
2
|
|
|
|
|
82
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.002'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
|
|
799
|
use constant TIME_AND_DATE_SITE_URL |
9
|
2
|
|
|
2
|
|
11
|
=> 'http://www.timeanddate.com/counters/multicountdown.html'; |
|
2
|
|
|
|
|
2
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has error => ( is => 'rw', init_arg => undef, ); |
13
|
|
|
|
|
|
|
has _ua => ( |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
|
|
|
|
|
|
init_arg => undef, |
16
|
|
|
|
|
|
|
default => sub { |
17
|
|
|
|
|
|
|
LWP::UserAgent->new( |
18
|
|
|
|
|
|
|
timeout => 30, |
19
|
|
|
|
|
|
|
agent => 'Mozilla/5.0 (X11; Ubuntu; Linux i686; ' |
20
|
|
|
|
|
|
|
.'rv:26.0) Gecko/20100101 Firefox/26.0', |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub hny { |
26
|
3
|
|
|
3
|
1
|
51360
|
my ( $self, $tz ) = @_; |
27
|
|
|
|
|
|
|
|
28
|
3
|
50
|
|
|
|
14
|
my $data = $self->_get_data |
29
|
|
|
|
|
|
|
or return; |
30
|
|
|
|
|
|
|
|
31
|
3
|
100
|
|
|
|
13
|
if ( $tz ) { |
32
|
2
|
|
|
|
|
6
|
$tz = uc $tz; |
33
|
2
|
50
|
|
|
|
8
|
$tz = 'GMT' if $tz eq 'UTC'; |
34
|
|
|
|
|
|
|
|
35
|
2
|
100
|
|
|
|
42
|
my ( $tz_data ) = grep $_->{tz} eq $tz, @$data |
36
|
|
|
|
|
|
|
or return $self->_set_error('Didn\'t find time zone ' . $tz); |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
22
|
return $tz_data; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
6
|
return $data; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _get_data { |
45
|
3
|
|
|
3
|
|
6
|
my $self = shift; |
46
|
|
|
|
|
|
|
|
47
|
3
|
|
|
|
|
29
|
my $res = $self->_ua->get( TIME_AND_DATE_SITE_URL ); |
48
|
|
|
|
|
|
|
|
49
|
3
|
50
|
|
|
|
399036
|
return $self->_set_error('Network error: ' . $res->status_line) |
50
|
|
|
|
|
|
|
unless $res->is_success; |
51
|
|
|
|
|
|
|
|
52
|
3
|
50
|
|
|
|
51
|
my $parsed_data = $self->_parse( $res->content ) |
53
|
|
|
|
|
|
|
or return; # errored out and the error is already set |
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
110
|
return $parsed_data; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _parse { |
59
|
3
|
|
|
3
|
|
217
|
my ( $self, $content ) = @_; |
60
|
|
|
|
|
|
|
|
61
|
3
|
|
|
|
|
8
|
my @data; |
62
|
3
|
|
|
|
|
7
|
eval { |
63
|
3
|
|
|
|
|
30
|
my $dom = Mojo::DOM->new( $content ); |
64
|
3
|
|
|
|
|
183898
|
for my $tr ( $dom->find('table.mpad.tbbox tbody tr')->each ) { |
65
|
120
|
|
|
|
|
66718
|
my %row; |
66
|
120
|
|
|
|
|
297
|
@row{qw/countries tz cities time_left/} |
67
|
|
|
|
|
|
|
= map $_->all_text, $tr->find('td')->each; |
68
|
120
|
|
|
|
|
162208
|
push @data, +{ %row }; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
|
72
|
3
|
50
|
|
|
|
2412
|
$@ and return $self->_set_error('Parse error: ' . $@); |
73
|
3
|
|
|
|
|
29
|
return \@data; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _set_error { |
77
|
1
|
|
|
1
|
|
3
|
my ( $self, $error ) = @_; |
78
|
1
|
|
|
|
|
13
|
$self->error( $error ); |
79
|
1
|
|
|
|
|
21
|
return; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
'HAPPY NEW YEAR!!!!'; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |