File Coverage

blib/lib/CPAN/Testers/Reports/Counts.pm
Criterion Covered Total %
statement 46 46 100.0
branch 4 6 66.6
condition n/a
subroutine 10 10 100.0
pod 2 2 100.0
total 62 64 96.8


line stmt bran cond sub pod time code
1             package CPAN::Testers::Reports::Counts;
2             $CPAN::Testers::Reports::Counts::VERSION = '0.05';
3             # ABSTRACT: counts of CPAN Testers reports by month or year
4 3     3   70010 use strict;
  3         6  
  3         79  
5 3     3   15 use warnings;
  3         6  
  3         81  
6 3     3   67 use 5.008;
  3         9  
7              
8 3     3   2135 use parent 'Exporter';
  3         936  
  3         16  
9 3     3   939 use Net::HTTP::Tiny qw(http_get);
  3         6837  
  3         1796  
10              
11             our @EXPORT_OK = qw(reports_counts_by_month reports_counts_by_year);
12             our %EXPORT_TAGS = ( all => [@EXPORT_OK] );
13             my $reports_by_month;
14             my $reports_by_year;
15              
16             sub _initialise
17             {
18 2     2   5 $reports_by_month = {};
19 2         4 $reports_by_year = {};
20 2         7 _load_counts('http://stats.cpantesters.org/stats/stats1.txt');
21 2         8 _load_counts('http://stats.cpantesters.org/stats/stats3.txt');
22 2         9 _lock_data($reports_by_month);
23 2         7 _lock_data($reports_by_year);
24             }
25              
26             sub _load_counts
27             {
28 4     4   8 my $url = shift;
29 4         21 my $content = http_get($url);
30 4         144864 my @lines = split(/[\r\n]+/, $content);
31 4         24 my @header = split(/,/, shift @lines);
32 4         12 my $year;
33              
34 4         16 foreach my $line (@lines) {
35 776         3694 my ($month, @fields) = split(/,/, $line);
36 776         2874 ($year = $month) =~ s/..$//;
37 776         3149 $month =~ s/(..)$/-$1/;
38              
39             FIELD:
40 776         2346 for (my $i = 0; $i < @fields; $i++) {
41 2716         4208 my $key = $header[$i+1];
42              
43             # Don't double-count FAIL: column appears in both files
44 2716 100       8446 next FIELD if exists($reports_by_month->{$month}->{$key});
45              
46 2328         5497 $reports_by_month->{$month}->{$key} = $fields[$i];
47 2328         9809 $reports_by_year->{$year}->{$key} += $fields[$i];
48             }
49             }
50             }
51              
52             sub _lock_data
53             {
54 4     4   9 my $ref = shift;
55              
56 4         72 foreach my $period (keys %$ref) {
57 422         518 foreach my $key (keys %{ $ref->{$period} }) {
  422         1120  
58 2532         4952 Internals::SvREADONLY($ref->{$period}->{$key}, 1);
59             }
60 422         634 Internals::SvREADONLY(%{ $ref->{$period} }, 1);
  422         942  
61             }
62 4         33 Internals::SvREADONLY(%$ref, 1);
63             }
64              
65             sub reports_counts_by_month
66             {
67 1 50   1 1 12 _initialise() if not defined($reports_by_month);
68 1         4 return $reports_by_month;
69             }
70              
71             sub reports_counts_by_year
72             {
73 1 50   1 1 12 _initialise() if not defined($reports_by_year);
74 1         5 return $reports_by_year;
75             }
76              
77             1;
78              
79             =head1 NAME
80              
81             CPAN::Testers::Reports::Count - counts of CPAN Testers reports by month or year
82              
83             =head1 SYNOPSIS
84              
85             use CPAN::Testers::Reports::Counts ':all';
86              
87             $counts = reports_counts_by_year();
88              
89             foreach my $year (sort keys %$counts) {
90             print "$year:\n";
91             foreach my $category (qw(REPORTS PASS FAIL NA UNKNOWN)) {
92             print " $category = $counts->{$year}->{$category}\n";
93             }
94             }
95              
96             =head1 DESCRIPTION
97              
98             This module gives you the number of CPAN Testers reports that
99             were submitted in every month or year that CPAN Testers has been running.
100             The data is returned as a hash reference, with the keys identifying
101             either years or year/month pairs. For each month or year there are five
102             numbers available:
103              
104             =over 4
105              
106             =item * B: the total number of reports submitted.
107              
108             =item * B: the number of successful test reports.
109              
110             =item * B: the number of failing test reports.
111              
112             =item * B: the number of "Not Applicable" results. Eg the version of Perl wasn't supported.
113              
114             =item * B: the number of Unknown tests. Eg the dist doesn't have any tests.
115              
116             =back
117              
118             More detailed definitions of these can be found on the
119             L.
120              
121             The data is grabbed from the L
122             web site, so you must have a working internet connection when you use this module.
123              
124             There are two functions, used to get the reports counts either by year or by month.
125              
126             =head2 reports_counts_by_year
127              
128             This function returns a hashref which is keyed off the years for which reports
129             have been submitted:
130              
131             use CPAN::Testers::Reports::Counts 'reports_counts_by_year';
132             $counts = reports_counts_by_year();
133             print "total = $counts->{2013}->{REPORTS}\n";
134              
135             The value in the hash for each year is another hashref, which is keyed off
136             the report grades listed above.
137              
138             =head2 reports_counts_by_month
139              
140             This function returns a hashref which is keyed off the months for which reports
141             have been submitted. The months are in the format 'YYYY-MM'.
142              
143             use CPAN::Testers::Reports::Counts 'reports_counts_by_month';
144             $counts = reports_counts_by_month();
145             print "Dec 2013 = $counts->{'2013-12'}->{REPORTS}\n";
146              
147             =head1 SEE ALSO
148              
149             L,
150             L.
151             L - a module used to download and summarize CPAN Testers data.
152              
153             =head1 REPOSITORY
154              
155             L
156              
157             =head1 AUTHOR
158              
159             Neil Bowers Eneilb@cpan.orgE
160              
161             =head1 COPYRIGHT AND LICENSE
162              
163             This software is copyright (c) 2014 by Neil Bowers .
164              
165             This is free software; you can redistribute it and/or modify it under
166             the same terms as the Perl 5 programming language system itself.
167              
168             =cut
169