File Coverage

blib/lib/CPAN/Testers/Schema/Result/Stats.pm
Criterion Covered Total %
statement 31 32 96.8
branch 2 2 100.0
condition n/a
subroutine 8 8 100.0
pod 5 5 100.0
total 46 47 97.8


line stmt bran cond sub pod time code
1 13     13   6492 use utf8;
  13         25  
  13         69  
2             package CPAN::Testers::Schema::Result::Stats;
3             our $VERSION = '0.025';
4             # ABSTRACT: The basic statistics information extracted from test reports
5              
6             #pod =head1 SYNOPSIS
7             #pod
8             #pod my $schema = CPAN::Testers::Schema->connect( $dsn, $user, $pass );
9             #pod
10             #pod # Retrieve a row
11             #pod my $row = $schema->resultset( 'Stats' )->first;
12             #pod # pass from doug@example.com (Doug Bell) using Perl 5.20.1 on darwin
13             #pod say sprintf "%s from %s using Perl %s on %s",
14             #pod $row->state,
15             #pod $row->tester,
16             #pod $row->perl,
17             #pod $row->osname;
18             #pod
19             #pod # Create a new row
20             #pod my %new_row_data = (
21             #pod state => 'fail',
22             #pod guid => '00000000-0000-0000-0000-000000000000',
23             #pod tester => 'doug@example.com (Doug Bell)',
24             #pod postdate => '201608',
25             #pod dist => 'My-Dist',
26             #pod version => '0.001',
27             #pod platform => 'darwin-2level',
28             #pod perl => '5.22.0',
29             #pod osname => 'darwin',
30             #pod osvers => '10.8.0',
31             #pod fulldate => '201608120401',
32             #pod type => 2,
33             #pod uploadid => 287102,
34             #pod );
35             #pod my $new_row = $schema->resultset( 'Stats' )->insert( \%new_row_data );
36             #pod
37             #pod =head1 DESCRIPTION
38             #pod
39             #pod This table (C<cpanstats> in the database) hold the basic, vital statistics
40             #pod extracted from test reports. This data is used to generate reports for the
41             #pod web application and web APIs.
42             #pod
43             #pod See C<ATTRIBUTES> below for the full list of attributes.
44             #pod
45             #pod This data is built from the Metabase by the L<CPAN::Testers::Data::Generator>.
46             #pod
47             #pod =head1 SEE ALSO
48             #pod
49             #pod L<DBIx::Class::Row>, L<CPAN::Testers::Schema>
50             #pod
51             #pod =cut
52              
53 13     13   774 use CPAN::Testers::Schema::Base 'Result';
  13         25  
  13         96  
54 13     13   444 use Mojo::Util qw( html_unescape );
  13         40  
  13         7542  
55             table 'cpanstats';
56              
57             #pod =attr id
58             #pod
59             #pod The ID of the row. Auto-generated.
60             #pod
61             #pod =cut
62              
63             primary_column 'id', {
64             data_type => 'int',
65             extra => { unsigned => 1 },
66             is_auto_increment => 1,
67             is_nullable => 0,
68             };
69              
70             #pod =attr guid
71             #pod
72             #pod The UUID of this report from the Metabase, stored in standard hex string
73             #pod representation.
74             #pod
75             #pod =cut
76              
77             # Must be unique for foreign keys to work
78             column 'guid', {
79             data_type => 'char',
80             is_nullable => 0,
81             size => 36,
82             };
83             unique_constraint guid => [qw( guid )];
84              
85             #pod =attr state
86             #pod
87             #pod The state of the report. One of:
88             #pod
89             #pod =over 4
90             #pod
91             #pod =item C<pass>
92             #pod
93             #pod The tests passed and everything went well.
94             #pod
95             #pod =item C<fail>
96             #pod
97             #pod The tests ran but failed.
98             #pod
99             #pod =item C<na>
100             #pod
101             #pod This dist is incompatible with the tester's Perl or OS.
102             #pod
103             #pod =item C<unknown>
104             #pod
105             #pod The state could not be determined.
106             #pod
107             #pod =back
108             #pod
109             #pod C<invalid> reports, which are marked that way by dist authors when the
110             #pod problem is on the tester's machine, are handled by the L</type> field.
111             #pod
112             #pod =cut
113              
114             column 'state', {
115             data_type => 'enum',
116             extra => { list => ['pass', 'fail', 'unknown', 'na'] },
117             is_nullable => 0,
118             };
119              
120             #pod =attr postdate
121             #pod
122             #pod A truncated date, consisting only of the year and month in C<YYYYMM>
123             #pod format.
124             #pod
125             #pod =cut
126              
127             column 'postdate', {
128             data_type => 'mediumint',
129             extra => { unsigned => 1 },
130             is_nullable => 0,
131             };
132              
133             #pod =attr tester
134             #pod
135             #pod The e-mail address of the tester who sent this report, optionally with
136             #pod the tester's name as a comment (C<doug@example.com (Doug Bell)>).
137             #pod
138             #pod =cut
139              
140             column 'tester', {
141             data_type => 'varchar',
142             is_nullable => 0,
143             size => 255,
144             };
145              
146             #pod =attr dist
147             #pod
148             #pod The distribution that was tested.
149             #pod
150             #pod =cut
151              
152             column 'dist', {
153             data_type => 'varchar',
154             is_nullable => 0,
155             size => 255,
156             };
157              
158             #pod =attr version
159             #pod
160             #pod The version of the distribution.
161             #pod
162             #pod =cut
163              
164             column 'version', {
165             data_type => 'varchar',
166             is_nullable => 0,
167             size => 255,
168             };
169              
170             #pod =attr platform
171             #pod
172             #pod The Perl C<platform> string (from C<$Config{archname}>).
173             #pod
174             #pod =cut
175              
176             column 'platform', {
177             data_type => 'varchar',
178             is_nullable => 0,
179             size => 255,
180             };
181              
182             #pod =attr perl
183             #pod
184             #pod The version of Perl that was used to run the tests (from
185             #pod C<$Config{version}>).
186             #pod
187             #pod =cut
188              
189             column 'perl', {
190             data_type => 'varchar',
191             is_nullable => 0,
192             size => 255,
193             };
194              
195             #pod =attr osname
196             #pod
197             #pod The name of the operating system (from C<$Config{osname}>).
198             #pod
199             #pod =cut
200              
201             column 'osname', {
202             data_type => 'varchar',
203             is_nullable => 0,
204             size => 255,
205             };
206              
207             #pod =attr osvers
208             #pod
209             #pod The version of the operating system (from C<$Config{osvers}>).
210             #pod
211             #pod =cut
212              
213             column 'osvers', {
214             data_type => 'varchar',
215             is_nullable => 0,
216             size => 255,
217             };
218              
219             #pod =attr fulldate
220             #pod
221             #pod The full date of the report, with hours and minutes, in C<YYYYMMDDHHNN>
222             #pod format.
223             #pod
224             #pod =cut
225              
226             column 'fulldate', {
227             data_type => 'varchar',
228             is_nullable => 0,
229             size => 32,
230             };
231              
232             #pod =attr type
233             #pod
234             #pod A field that declares the status of this row. The only current
235             #pod possibilities are:
236             #pod
237             #pod =over 4
238             #pod
239             #pod =item 2 - This is a valid Perl 5 test report
240             #pod
241             #pod =item 3 - This report was marked invalid by a user
242             #pod
243             #pod =back
244             #pod
245             #pod =cut
246              
247             column 'type', {
248             data_type => 'tinyint',
249             extra => { unsigned => 1 },
250             is_nullable => 0,
251             };
252              
253             #pod =attr uploadid
254             #pod
255             #pod The ID of the upload that created this dist. Related to the C<uploadid>
256             #pod field in the C<uploads> table (see
257             #pod L<CPAN::Testers::Schema::Result::Uploads>).
258             #pod
259             #pod =cut
260              
261             column 'uploadid', {
262             data_type => 'int',
263             extra => { unsigned => 1 },
264             is_nullable => 0,
265             };
266              
267             #pod =method upload
268             #pod
269             #pod Get the related row in the `uploads` table. See L<CPAN::Testers::Schema::Result::Upload>.
270             #pod
271             #pod =cut
272              
273             belongs_to upload => 'CPAN::Testers::Schema::Result::Upload' => 'uploadid';
274              
275             #pod =method perl_version
276             #pod
277             #pod Get the related metadata about the Perl version this report is for. See
278             #pod L<CPAN::Testers::Schema::Result::PerlVersion>.
279             #pod
280             #pod =cut
281              
282             might_have perl_version => 'CPAN::Testers::Schema::Result::PerlVersion' =>
283             { 'foreign.version' => 'self.perl' };
284              
285             #pod =method dist_name
286             #pod
287             #pod The name of the distribution that was tested.
288             #pod
289             #pod =cut
290              
291 1     1 1 6346 sub dist_name( $self ) {
  1         2  
  1         2  
292 1         25 return $self->dist;
293             }
294              
295             #pod =method dist_version
296             #pod
297             #pod The version of the distribution that was tested.
298             #pod
299             #pod =cut
300              
301 1     1 1 745 sub dist_version( $self ) {
  1         2  
  1         2  
302 1         25 return $self->version;
303             }
304              
305             #pod =method lang_version
306             #pod
307             #pod The language and version the test was executed with
308             #pod
309             #pod =cut
310              
311 1     1 1 569 sub lang_version( $self ) {
  1         3  
  1         2  
312 1         24 return sprintf '%s v%s', 'Perl 5', $self->perl;
313             }
314              
315             #pod =method platform
316             #pod
317             #pod The platform the test was run on
318             #pod
319             #pod =cut
320              
321             sub platform( $self ) {
322             return $self->get_inflated_column( 'platform' );
323             }
324              
325             #pod =method grade
326             #pod
327             #pod The report grade. One of 'pass', 'fail', 'na', 'unknown'.
328             #pod
329             #pod =cut
330              
331 1     1 1 1315 sub grade( $self ) {
  1         2  
  1         2  
332 1         25 return $self->state;
333             }
334              
335             #pod =method tester_name
336             #pod
337             #pod The name of the tester who sent the report
338             #pod
339             #pod =cut
340              
341 1     1 1 556 sub tester_name( $self ) {
  1         2  
  1         2  
342             # The name could either be in quotes before the e-mail, or in
343             # parentheses after.
344 1         6 for my $re ( qr{"([^"]+)"}, qr{\(([^)]+)\)} ) {
345 2 100       65 if ( $self->tester =~ $re ) {
346             # And it may have high-byte characters HTML-escaped
347 1         19 return html_unescape $1;
348             }
349             }
350             # Can't find just the name, so send it all for now...
351 0           return html_unescape $self->tester;
352             }
353              
354             1;
355              
356             __END__
357              
358             =pod
359              
360             =head1 NAME
361              
362             CPAN::Testers::Schema::Result::Stats - The basic statistics information extracted from test reports
363              
364             =head1 VERSION
365              
366             version 0.025
367              
368             =head1 SYNOPSIS
369              
370             my $schema = CPAN::Testers::Schema->connect( $dsn, $user, $pass );
371              
372             # Retrieve a row
373             my $row = $schema->resultset( 'Stats' )->first;
374             # pass from doug@example.com (Doug Bell) using Perl 5.20.1 on darwin
375             say sprintf "%s from %s using Perl %s on %s",
376             $row->state,
377             $row->tester,
378             $row->perl,
379             $row->osname;
380              
381             # Create a new row
382             my %new_row_data = (
383             state => 'fail',
384             guid => '00000000-0000-0000-0000-000000000000',
385             tester => 'doug@example.com (Doug Bell)',
386             postdate => '201608',
387             dist => 'My-Dist',
388             version => '0.001',
389             platform => 'darwin-2level',
390             perl => '5.22.0',
391             osname => 'darwin',
392             osvers => '10.8.0',
393             fulldate => '201608120401',
394             type => 2,
395             uploadid => 287102,
396             );
397             my $new_row = $schema->resultset( 'Stats' )->insert( \%new_row_data );
398              
399             =head1 DESCRIPTION
400              
401             This table (C<cpanstats> in the database) hold the basic, vital statistics
402             extracted from test reports. This data is used to generate reports for the
403             web application and web APIs.
404              
405             See C<ATTRIBUTES> below for the full list of attributes.
406              
407             This data is built from the Metabase by the L<CPAN::Testers::Data::Generator>.
408              
409             =head1 ATTRIBUTES
410              
411             =head2 id
412              
413             The ID of the row. Auto-generated.
414              
415             =head2 guid
416              
417             The UUID of this report from the Metabase, stored in standard hex string
418             representation.
419              
420             =head2 state
421              
422             The state of the report. One of:
423              
424             =over 4
425              
426             =item C<pass>
427              
428             The tests passed and everything went well.
429              
430             =item C<fail>
431              
432             The tests ran but failed.
433              
434             =item C<na>
435              
436             This dist is incompatible with the tester's Perl or OS.
437              
438             =item C<unknown>
439              
440             The state could not be determined.
441              
442             =back
443              
444             C<invalid> reports, which are marked that way by dist authors when the
445             problem is on the tester's machine, are handled by the L</type> field.
446              
447             =head2 postdate
448              
449             A truncated date, consisting only of the year and month in C<YYYYMM>
450             format.
451              
452             =head2 tester
453              
454             The e-mail address of the tester who sent this report, optionally with
455             the tester's name as a comment (C<doug@example.com (Doug Bell)>).
456              
457             =head2 dist
458              
459             The distribution that was tested.
460              
461             =head2 version
462              
463             The version of the distribution.
464              
465             =head2 platform
466              
467             The Perl C<platform> string (from C<$Config{archname}>).
468              
469             =head2 perl
470              
471             The version of Perl that was used to run the tests (from
472             C<$Config{version}>).
473              
474             =head2 osname
475              
476             The name of the operating system (from C<$Config{osname}>).
477              
478             =head2 osvers
479              
480             The version of the operating system (from C<$Config{osvers}>).
481              
482             =head2 fulldate
483              
484             The full date of the report, with hours and minutes, in C<YYYYMMDDHHNN>
485             format.
486              
487             =head2 type
488              
489             A field that declares the status of this row. The only current
490             possibilities are:
491              
492             =over 4
493              
494             =item 2 - This is a valid Perl 5 test report
495              
496             =item 3 - This report was marked invalid by a user
497              
498             =back
499              
500             =head2 uploadid
501              
502             The ID of the upload that created this dist. Related to the C<uploadid>
503             field in the C<uploads> table (see
504             L<CPAN::Testers::Schema::Result::Uploads>).
505              
506             =head1 METHODS
507              
508             =head2 upload
509              
510             Get the related row in the `uploads` table. See L<CPAN::Testers::Schema::Result::Upload>.
511              
512             =head2 perl_version
513              
514             Get the related metadata about the Perl version this report is for. See
515             L<CPAN::Testers::Schema::Result::PerlVersion>.
516              
517             =head2 dist_name
518              
519             The name of the distribution that was tested.
520              
521             =head2 dist_version
522              
523             The version of the distribution that was tested.
524              
525             =head2 lang_version
526              
527             The language and version the test was executed with
528              
529             =head2 platform
530              
531             The platform the test was run on
532              
533             =head2 grade
534              
535             The report grade. One of 'pass', 'fail', 'na', 'unknown'.
536              
537             =head2 tester_name
538              
539             The name of the tester who sent the report
540              
541             =head1 SEE ALSO
542              
543             L<DBIx::Class::Row>, L<CPAN::Testers::Schema>
544              
545             =head1 AUTHORS
546              
547             =over 4
548              
549             =item *
550              
551             Oriol Soriano <oriolsoriano@gmail.com>
552              
553             =item *
554              
555             Doug Bell <preaction@cpan.org>
556              
557             =back
558              
559             =head1 COPYRIGHT AND LICENSE
560              
561             This software is copyright (c) 2018 by Oriol Soriano, Doug Bell.
562              
563             This is free software; you can redistribute it and/or modify it under
564             the same terms as the Perl 5 programming language system itself.
565              
566             =cut