| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CPAN::Testers::WWW::Reports::Query::Reports; |
|
2
|
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
99188
|
use strict; |
|
|
6
|
|
|
|
|
12
|
|
|
|
6
|
|
|
|
|
202
|
|
|
4
|
6
|
|
|
6
|
|
23
|
use warnings; |
|
|
6
|
|
|
|
|
7
|
|
|
|
6
|
|
|
|
|
290
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
CPAN::Testers::WWW::Reports::Query::Reports - Retrieve CPAN Testers metadata direct from the CPAN Testers website. |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This module queries the CPAN Testers website and retrieves a data set. For a |
|
17
|
|
|
|
|
|
|
date request, the data set returned relates to the ids that can be retrieved |
|
18
|
|
|
|
|
|
|
for that date. A range request will return the records for the requested IDs. |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# establish the object |
|
23
|
|
|
|
|
|
|
my $query = CPAN::Testers::WWW::Reports::Query::Reports->new; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# get list of ids for a particular date |
|
26
|
|
|
|
|
|
|
my $result = $query->date( |
|
27
|
|
|
|
|
|
|
'2012-02-08' # must be YYYY-MM-DD format |
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# $query is a hash ref |
|
31
|
|
|
|
|
|
|
print "From: $result->{from}, To: $result->{to}, Range: $result->{range}\n"; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# $result->{list} is an array of the actual ids posted for the given date. |
|
34
|
|
|
|
|
|
|
# note that this list may not include all ids within $result->{range}. |
|
35
|
|
|
|
|
|
|
print "List: " . join(', ',@{$result->{list}}) . "\n"; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# get metabase for a range of ids |
|
39
|
|
|
|
|
|
|
my $result = $query->range( |
|
40
|
|
|
|
|
|
|
'20080300-20120330' |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# '20120330' # just get |
|
43
|
|
|
|
|
|
|
# '20120330-' # from until the latest [see caveat] |
|
44
|
|
|
|
|
|
|
# '-20120330' # previous reports up to [see caveat] |
|
45
|
|
|
|
|
|
|
# '-' # the latest reports [see caveat] |
|
46
|
|
|
|
|
|
|
); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# $result is a hash ref, with the reports ids as the top level keys |
|
49
|
|
|
|
|
|
|
my @ids = sort keys %$result; |
|
50
|
|
|
|
|
|
|
my $id = $ids[0]; |
|
51
|
|
|
|
|
|
|
print "id = $id, dist = '$result->{$id}{dist}', version = '$result->{$id}{version}'\n"; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# get the raw data for all results, or a specific version if supplied |
|
55
|
|
|
|
|
|
|
my $data = $query->raw; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# get the last error |
|
59
|
|
|
|
|
|
|
my $error = $query->error; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 Caveat |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Note that when using the range parameter, at most only 2500 records will be |
|
64
|
|
|
|
|
|
|
returned. This is to avoid accidental requests for all records! |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This value may change in the future. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
|
71
|
|
|
|
|
|
|
# Library Modules |
|
72
|
|
|
|
|
|
|
|
|
73
|
6
|
|
|
6
|
|
5056
|
use WWW::Mechanize; |
|
|
6
|
|
|
|
|
819445
|
|
|
|
6
|
|
|
|
|
234
|
|
|
74
|
6
|
|
|
6
|
|
3656
|
use JSON::XS; |
|
|
6
|
|
|
|
|
22729
|
|
|
|
6
|
|
|
|
|
2725
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
|
77
|
|
|
|
|
|
|
# Variables |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $URL = 'http://www.cpantesters.org/cgi-bin/reports-metadata.cgi'; |
|
80
|
|
|
|
|
|
|
#$URL = 'http://reports/cgi-bin/reports-metadata.cgi'; # local test version |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $mech = WWW::Mechanize->new(); |
|
83
|
|
|
|
|
|
|
$mech->agent_alias( 'Linux Mozilla' ); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# ------------------------------------- |
|
86
|
|
|
|
|
|
|
# Program |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub new { |
|
89
|
1
|
|
|
1
|
1
|
65
|
my($class, %hash) = @_; |
|
90
|
1
|
|
|
|
|
2
|
my $self = {}; |
|
91
|
1
|
|
|
|
|
4
|
bless $self, $class; |
|
92
|
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
2
|
return $self; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub raw { |
|
97
|
2
|
|
|
2
|
1
|
7
|
my $self = shift; |
|
98
|
2
|
|
|
|
|
17
|
return $self->{content}; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub date { |
|
102
|
3
|
|
|
3
|
1
|
11400
|
my $self = shift; |
|
103
|
3
|
|
100
|
|
|
21
|
my $date = shift || return; |
|
104
|
|
|
|
|
|
|
|
|
105
|
2
|
100
|
|
|
|
18
|
return unless($date =~ /^\d{4}\-\d{2}\-\d{2}$/); |
|
106
|
|
|
|
|
|
|
|
|
107
|
1
|
50
|
|
|
|
12
|
return unless($self->_request( "date=$date" )); |
|
108
|
|
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
34
|
return $self->_parse(); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub range { |
|
113
|
6
|
|
|
6
|
1
|
31327
|
my $self = shift; |
|
114
|
6
|
|
100
|
|
|
24
|
my $range = shift || return; |
|
115
|
|
|
|
|
|
|
|
|
116
|
5
|
100
|
100
|
|
|
53
|
return unless($range =~ /^(\d+)?\-(\d+)?$/ || $range =~ /^(\d+)$/); |
|
117
|
|
|
|
|
|
|
|
|
118
|
4
|
50
|
|
|
|
22
|
return unless($self->_request( "range=$range" )); |
|
119
|
|
|
|
|
|
|
|
|
120
|
4
|
|
|
|
|
235
|
return $self->_parse(); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _request { |
|
124
|
5
|
|
|
5
|
|
11
|
my $self = shift; |
|
125
|
5
|
|
|
|
|
9
|
my $param = shift; |
|
126
|
5
|
|
|
|
|
26
|
$self->{error} = ''; |
|
127
|
|
|
|
|
|
|
|
|
128
|
5
|
|
|
|
|
18
|
my $url = join( '?', $URL, $param ); |
|
129
|
|
|
|
|
|
|
#print "URL: $url\n"; |
|
130
|
5
|
|
|
|
|
11
|
eval { $mech->get( $url ); }; |
|
|
5
|
|
|
|
|
37
|
|
|
131
|
5
|
50
|
33
|
|
|
890724
|
if($@ || !$mech->success()) { |
|
132
|
0
|
|
|
|
|
0
|
$self->{error} = $@; |
|
133
|
0
|
|
|
|
|
0
|
return; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
5
|
|
|
|
|
126
|
$self->{content} = $mech->content; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub _parse { |
|
140
|
5
|
|
|
5
|
|
10
|
my $self = shift; |
|
141
|
5
|
|
|
|
|
9
|
my $data; |
|
142
|
5
|
|
|
|
|
13
|
eval { $data = decode_json($self->{content}) }; |
|
|
5
|
|
|
|
|
33343
|
|
|
143
|
5
|
50
|
33
|
|
|
69
|
return $data unless($@ || !$data); |
|
144
|
|
|
|
|
|
|
|
|
145
|
0
|
|
0
|
|
|
0
|
$self->{error} = $@ || 'no data returned'; |
|
146
|
0
|
|
|
|
|
0
|
return; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub error { |
|
150
|
9
|
|
|
9
|
1
|
42
|
my $self = shift; |
|
151
|
9
|
|
|
|
|
56
|
return $self->{error}; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
q("With thanks to the 2012 QA Hackathon"); |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
__END__ |