File Coverage

blib/lib/CPAN/Testers/Reports/Counts.pm
Criterion Covered Total %
statement 47 47 100.0
branch 4 6 66.6
condition n/a
subroutine 10 10 100.0
pod 2 2 100.0
total 63 65 96.9


line stmt bran cond sub pod time code
1             package CPAN::Testers::Reports::Counts;
2             $CPAN::Testers::Reports::Counts::VERSION = '0.04';
3             # ABSTRACT: counts of CPAN Testers reports by month or year
4 3     3   71397 use strict;
  3         5  
  3         98  
5 3     3   15 use warnings;
  3         5  
  3         79  
6 3     3   70 use 5.008;
  3         9  
  3         196  
7              
8 3     3   2410 use parent 'Exporter';
  3         921  
  3         14  
9 3     3   1218 use Net::HTTP::Tiny qw(http_get);
  3         9176  
  3         2223  
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   4 $reports_by_month = {};
19 2         6 $reports_by_year = {};
20 2         8 _load_counts('http://stats.cpantesters.org/stats/stats1.txt');
21 2         10 _load_counts('http://stats.cpantesters.org/stats/stats3.txt');
22 2         9 _lock_data($reports_by_month);
23 2         9 _lock_data($reports_by_year);
24             }
25              
26             sub _load_counts
27             {
28 4     4   9 my $url = shift;
29 4         24 my $content = http_get($url);
30 4         122655 my @lines = split(/[\r\n]+/, $content);
31 4         53 my @header = split(/,/, shift @lines);
32 4         11 my $year;
33              
34 4         17 foreach my $line (@lines) {
35 724         3655 my ($month, @fields) = split(/,/, $line);
36 724         9413 ($year = $month) =~ s/..$//;
37 724         3973 $month =~ s/(..)$/-$1/;
38              
39             FIELD:
40 724         2090 for (my $i = 0; $i < @fields; $i++) {
41 2534         4929 my $key = $header[$i+1];
42              
43             # Don't double-count FAIL: column appears in both files
44 2534 100       9240 next FIELD if exists($reports_by_month->{$month}->{$key});
45              
46 2172         6033 $reports_by_month->{$month}->{$key} = $fields[$i];
47 2172         11004 $reports_by_year->{$year}->{$key} += $fields[$i];
48             }
49             }
50             }
51              
52             sub _lock_data
53             {
54 4     4   8 my $ref = shift;
55              
56 4         77 foreach my $period (keys %$ref) {
57 394         6722 foreach my $key (keys %{ $ref->{$period} }) {
  394         1684  
58 2364         4706 Internals::SvREADONLY($ref->{$period}->{$key}, 1);
59             }
60 394         712 Internals::SvREADONLY(%{ $ref->{$period} }, 1);
  394         949  
61             }
62 4         32 Internals::SvREADONLY(%$ref, 1);
63             }
64              
65             sub reports_counts_by_month
66             {
67 1 50   1 1 11 _initialise() if not defined($reports_by_month);
68 1         7 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         6 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