line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mirror::JSON::URI; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
49
|
use 5.005; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
103
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
88
|
|
5
|
2
|
|
|
2
|
|
12
|
use URI (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
43
|
|
6
|
2
|
|
|
2
|
|
17
|
use Params::Util qw{ _STRING _INSTANCE }; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
129
|
|
7
|
2
|
|
|
2
|
|
10
|
use LWP::Simple (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
38
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
10
|
use vars qw{$VERSION}; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
110
|
|
10
|
|
|
|
|
|
|
BEGIN { |
11
|
2
|
|
|
2
|
|
878
|
$VERSION = '0.01'; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
##################################################################### |
19
|
|
|
|
|
|
|
# Constructor |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
1
|
|
|
1
|
0
|
2
|
my $class = shift; |
23
|
1
|
|
|
|
|
5
|
my $self = bless { @_ }, $class; |
24
|
1
|
50
|
|
|
|
5
|
unless ( _INSTANCE($self->uri, 'URI') ) { |
25
|
0
|
|
|
|
|
0
|
return undef; |
26
|
|
|
|
|
|
|
} |
27
|
1
|
|
|
|
|
15
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub uri { |
31
|
2
|
|
|
2
|
0
|
271
|
$_[0]->{uri}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub json { |
35
|
0
|
|
|
0
|
0
|
0
|
$_[0]->{json}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub live { |
39
|
1
|
|
|
1
|
0
|
9
|
!! $_[0]->{live}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub lag { |
43
|
0
|
|
|
0
|
0
|
0
|
$_[0]->{lag}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
##################################################################### |
51
|
|
|
|
|
|
|
# Main Methods |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub get { |
54
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
55
|
1
|
|
|
|
|
10
|
my $uri = URI->new('mirror.json')->abs( $self->uri ); |
56
|
1
|
|
|
|
|
796
|
my $before = Time::HiRes::time(); |
57
|
1
|
|
|
|
|
6
|
my $json = LWP::Simple::get($uri); |
58
|
1
|
50
|
33
|
|
|
4420
|
unless ( $json and $json =~ /^---/ ) { |
59
|
|
|
|
|
|
|
# Site does not exist, or is broken |
60
|
1
|
|
|
|
|
10
|
return $self->{live} = 0; |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
|
$self->{lag} = Time::HiRes::time() - $before; |
63
|
0
|
|
|
|
|
|
$self->{json} = Mirror::JSON->read_string( $json ); |
64
|
0
|
|
|
|
|
|
return $self->{live} = 1; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |