File Coverage

blib/lib/CPAN/Testers/Schema/Result/TestReport.pm
Criterion Covered Total %
statement 56 56 100.0
branch n/a
condition 7 12 58.3
subroutine 14 14 100.0
pod 9 9 100.0
total 86 91 94.5


line stmt bran cond sub pod time code
1             package CPAN::Testers::Schema::Result::TestReport;
2             our $VERSION = '0.025';
3             # ABSTRACT: Raw reports as JSON documents
4              
5             #pod =head1 SYNOPSIS
6             #pod
7             #pod my $schema = CPAN::Testers::Schema->connect( $dsn, $user, $pass );
8             #pod
9             #pod # Retrieve a row
10             #pod my $row = $schema->resultset( 'TestReport' )->first;
11             #pod
12             #pod =head1 DESCRIPTION
13             #pod
14             #pod This table contains the raw reports as submitted by the tester. From this,
15             #pod the L<statistics table|CPAN::Testers::Schema::Result::Stats> is generated
16             #pod by L<CPAN::Testers::Backend::ProcessReports>.
17             #pod
18             #pod =head1 SEE ALSO
19             #pod
20             #pod L<DBIx::Class::Row>, L<CPAN::Testers::Schema>
21             #pod
22             #pod =cut
23              
24 13     13   39501 use CPAN::Testers::Schema::Base 'Result';
  13         31  
  13         118  
25 13     13   5771 use Data::UUID;
  13         7482  
  13         670  
26 13     13   85 use DateTime;
  13         26  
  13         277  
27 13     13   4999 use JSON::MaybeXS;
  13         13555  
  13         682  
28 13     13   83 use Mojo::Util qw( html_unescape );
  13         27  
  13         9761  
29             table 'test_report';
30              
31             __PACKAGE__->load_components('InflateColumn::DateTime', 'Core');
32              
33             #pod =attr id
34             #pod
35             #pod The UUID of this report stored in standard hex string representation.
36             #pod
37             #pod =cut
38              
39             primary_column 'id', {
40             data_type => 'char',
41             size => 36,
42             is_nullable => 0,
43             };
44              
45             #pod =attr created
46             #pod
47             #pod The ISO8601 date/time of when the report was inserted into the database.
48             #pod Will default to the current time.
49             #pod
50             #pod The JSON report also contains a C<created> field. This is the date/time
51             #pod that the report was created on the reporter's machine.
52             #pod
53             #pod =cut
54              
55             column created => {
56             data_type => 'datetime',
57             is_nullable => 0,
58             format_datetime => 1,
59             };
60              
61             #pod =attr report
62             #pod
63             #pod The full JSON report.
64             #pod
65             #pod XXX: Describe the format a little and link to the main schema OpenAPI
66             #pod format on http://api.cpantesters.org
67             #pod
68             #pod The serializer for this column will convert UTF-8 characters into their
69             #pod corresponding C<\u####> escape sequence, so this column is safe for
70             #pod tables with Latin1 encoding.
71             #pod
72             #pod =cut
73              
74             column 'report', {
75             data_type => 'JSON',
76             is_nullable => 0,
77             };
78              
79             my %JSON_OPT = (
80             allow_blessed => 1,
81             convert_blessed => 1,
82             ascii => 1,
83             );
84             __PACKAGE__->inflate_column( report => {
85             deflate => sub {
86             my ( $ref, $row ) = @_;
87             JSON::MaybeXS->new( %JSON_OPT )->encode( $ref );
88             },
89             inflate => sub {
90             my ( $raw, $row ) = @_;
91             JSON::MaybeXS->new( %JSON_OPT )->decode(
92             $raw =~ s/([\x{0000}-\x{001f}])/sprintf "\\u%v04x", $1/reg
93             );
94             },
95             } );
96              
97             #pod =method new
98             #pod
99             #pod Create a new object. This is called automatically by the ResultSet
100             #pod object and should not be called directly.
101             #pod
102             #pod This is overridden to provide sane defaults for the C<id> and C<created>
103             #pod fields.
104             #pod
105             #pod B<NOTE:> You should not supply a C<created> unless you are creating
106             #pod reports in the past. Reports created in the past will be hidden from
107             #pod many feeds, and may cause failures to not be reported to authors.
108             #pod
109             #pod =cut
110              
111 8     8 1 1448112 sub new( $class, $attrs ) {
  8         27  
  8         33  
  8         16  
112 8   66     2425 $attrs->{report}{id} = $attrs->{id} ||= Data::UUID->new->create_str;
113 8   66     2164 $attrs->{created} ||= DateTime->now( time_zone => 'UTC' );
114 8   66     4127 $attrs->{report}{created} ||= $attrs->{created}->datetime . 'Z';
115 8         261 return $class->next::method( $attrs );
116             };
117              
118             #pod =method upload
119             #pod
120             #pod my $upload = $row->upload;
121             #pod
122             #pod Get the associated L<CPAN::Testers::Schema::Result::Upload> object for
123             #pod the distribution tested by this test report.
124             #pod
125             #pod =cut
126              
127 1     1 1 875 sub upload( $self ) {
  1         2  
  1         3  
128 1         24 my ( $dist, $vers ) = $self->report->{distribution}->@{qw( name version )};
129 1         26 return $self->result_source->schema->resultset( 'Upload' )
130             ->search({ dist => $dist, version => $vers })->single;
131             }
132              
133             #pod =method dist_name
134             #pod
135             #pod The name of the distribution that was tested.
136             #pod
137             #pod =cut
138              
139 1     1 1 934 sub dist_name( $self ) {
  1         2  
  1         2  
140 1         25 return $self->report->{distribution}{name};
141             }
142              
143             #pod =method dist_version
144             #pod
145             #pod The version of the distribution that was tested.
146             #pod
147             #pod =cut
148              
149 1     1 1 596 sub dist_version( $self ) {
  1         3  
  1         2  
150 1         23 return $self->report->{distribution}{version};
151             }
152              
153             #pod =method lang_version
154             #pod
155             #pod The language and version the test was executed with
156             #pod
157             #pod =cut
158              
159 1     1 1 570 sub lang_version( $self ) {
  1         2  
  1         3  
160             return sprintf '%s v%s',
161 1         23 $self->report->{environment}{language}->@{qw( name version )};
162             }
163              
164             #pod =method platform
165             #pod
166             #pod The platform the test was run on
167             #pod
168             #pod =cut
169              
170 1     1 1 565 sub platform( $self ) {
  1         3  
  1         2  
171 1         24 return join ' ', $self->report->{environment}{language}{archname};
172             }
173              
174             #pod =method grade
175             #pod
176             #pod The report grade. One of 'pass', 'fail', 'na', 'unknown'.
177             #pod
178             #pod =cut
179              
180 1     1 1 564 sub grade( $self ) {
  1         2  
  1         2  
181 1         23 return $self->report->{result}{grade};
182             }
183              
184             #pod =method text
185             #pod
186             #pod The full text of the report, either from the phased sections or the
187             #pod "uncategorized" section.
188             #pod
189             #pod =cut
190              
191             my @output_phases = qw( configure build test install );
192 1     1 1 585 sub text( $self ) {
  1         3  
  1         1  
193             return $self->report->{result}{output}{uncategorized}
194 1   33     23 || join "\n\n", grep defined, $self->report->{result}{output}->@{ @output_phases };
195             }
196              
197             #pod =method tester_name
198             #pod
199             #pod The name of the tester who sent the report
200             #pod
201             #pod =cut
202              
203 1     1 1 2 sub tester_name( $self ) {
  1         3  
  1         2  
204 1         23 return html_unescape $self->report->{reporter}{name};
205             }
206              
207             1;
208              
209             __END__
210              
211             =pod
212              
213             =head1 NAME
214              
215             CPAN::Testers::Schema::Result::TestReport - Raw reports as JSON documents
216              
217             =head1 VERSION
218              
219             version 0.025
220              
221             =head1 SYNOPSIS
222              
223             my $schema = CPAN::Testers::Schema->connect( $dsn, $user, $pass );
224              
225             # Retrieve a row
226             my $row = $schema->resultset( 'TestReport' )->first;
227              
228             =head1 DESCRIPTION
229              
230             This table contains the raw reports as submitted by the tester. From this,
231             the L<statistics table|CPAN::Testers::Schema::Result::Stats> is generated
232             by L<CPAN::Testers::Backend::ProcessReports>.
233              
234             =head1 ATTRIBUTES
235              
236             =head2 id
237              
238             The UUID of this report stored in standard hex string representation.
239              
240             =head2 created
241              
242             The ISO8601 date/time of when the report was inserted into the database.
243             Will default to the current time.
244              
245             The JSON report also contains a C<created> field. This is the date/time
246             that the report was created on the reporter's machine.
247              
248             =head2 report
249              
250             The full JSON report.
251              
252             XXX: Describe the format a little and link to the main schema OpenAPI
253             format on http://api.cpantesters.org
254              
255             The serializer for this column will convert UTF-8 characters into their
256             corresponding C<\u####> escape sequence, so this column is safe for
257             tables with Latin1 encoding.
258              
259             =head1 METHODS
260              
261             =head2 new
262              
263             Create a new object. This is called automatically by the ResultSet
264             object and should not be called directly.
265              
266             This is overridden to provide sane defaults for the C<id> and C<created>
267             fields.
268              
269             B<NOTE:> You should not supply a C<created> unless you are creating
270             reports in the past. Reports created in the past will be hidden from
271             many feeds, and may cause failures to not be reported to authors.
272              
273             =head2 upload
274              
275             my $upload = $row->upload;
276              
277             Get the associated L<CPAN::Testers::Schema::Result::Upload> object for
278             the distribution tested by this test report.
279              
280             =head2 dist_name
281              
282             The name of the distribution that was tested.
283              
284             =head2 dist_version
285              
286             The version of the distribution that was tested.
287              
288             =head2 lang_version
289              
290             The language and version the test was executed with
291              
292             =head2 platform
293              
294             The platform the test was run on
295              
296             =head2 grade
297              
298             The report grade. One of 'pass', 'fail', 'na', 'unknown'.
299              
300             =head2 text
301              
302             The full text of the report, either from the phased sections or the
303             "uncategorized" section.
304              
305             =head2 tester_name
306              
307             The name of the tester who sent the report
308              
309             =head1 SEE ALSO
310              
311             L<DBIx::Class::Row>, L<CPAN::Testers::Schema>
312              
313             =head1 AUTHORS
314              
315             =over 4
316              
317             =item *
318              
319             Oriol Soriano <oriolsoriano@gmail.com>
320              
321             =item *
322              
323             Doug Bell <preaction@cpan.org>
324              
325             =back
326              
327             =head1 COPYRIGHT AND LICENSE
328              
329             This software is copyright (c) 2018 by Oriol Soriano, Doug Bell.
330              
331             This is free software; you can redistribute it and/or modify it under
332             the same terms as the Perl 5 programming language system itself.
333              
334             =cut