blib/lib/CPAN/Testers/Schema/Result/TestReport.pm

filter: Statementstmt 97.6% 42 / 43 Branchbran n/a Conditioncond 63.6% 7 / 11 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 100% 16 / 16 Podpod 100% 9 / 9 totaltotal 87.2% 75 / 86 SCAR 16.1
CC
5
Cov
91%
new
4.1
text
2.5
__ANON__
1.0
CRAP 5.0
« blib/lib/CPAN/Testers/Schema/Result/Upload.pm ↑ Summary blib/lib/CPAN/Testers/Schema/ResultSet/PerlVersion.pm »
1 package CPAN::Testers::Schema::Result::TestReport;
2 15 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 15 ▶use CPAN::Testers::Schema::Base 'Result';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 15 ▶use Data::UUID;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 15 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 15 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 15 ▶use Mojo::Util qw( html_unescape );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 15 table 'test_report';
30  
31 15 __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 15 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 15 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 15 column 'report', {
75 data_type => 'JSON',
76 is_nullable => 0,
77 };
78  
79 15 my %JSON_OPT = (
80 allow_blessed => 1,
81 convert_blessed => 1,
82 ascii => 1,
83 );
84 __PACKAGE__->inflate_column( report => {
85 deflate => sub {
86 10 ▶ my ( $ref, $row ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
87 10 JSON::MaybeXS->new( %JSON_OPT )->encode( $ref );
88 },
89 inflate => sub {
90 1 ▶ my ( $raw, $row ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.4
91 1 JSON::MaybeXS->new( %JSON_OPT )->decode(
92 0 $raw =~ s/([\x{0000}-\x{001f}])/sprintf "\\u%v04x", $1/reg
93 );
94 },
95 15 } );
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 ▶sub new( $class, $attrs ) {
Subroutine new: called CC=4 SCAR=14.0
Pod documented
112 8 ▶ $attrs->{report}{id} = $attrs->{id} ||= Data::UUID->new->create_str;
Condition66%2/3
$attrs->{"id"} ||= "Data::UUID"->new->create_str
l!l&&r!l&&!r
530
MC/DC0%0/2
$attrs->{"id"} ||= "Data::UUID"->new->create_str
$attrs->{"id"} "Data::UUID"->new->create_str
Truth table66%2/3
A ||= B
A= $attrs->{"id"}B= "Data::UUID"->new->create_str
ABresult
1X1
011
000
113 8 ▶ $attrs->{created} ||= DateTime->now( time_zone => 'UTC' );
Condition66%2/3
$attrs->{"created"} ||= "DateTime"->now("time_zone", "UTC")
l!l&&r!l&&!r
260
MC/DC0%0/2
$attrs->{"created"} ||= "DateTime"->now("time_zone", "UTC")
$attrs->{"created"} "DateTime"->now("time_zone", "UTC")
Truth table66%2/3
A ||= B
A= $attrs->{"created"}B= "DateTime"->now("time_zone", "UTC")
ABresult
1X1
011
000
114 8 ▶ $attrs->{report}{created} ||= $attrs->{created}->datetime . 'Z';
Condition100%2/2
$attrs->{"report"}{"created"} ||= $attrs->{"created"}->datetime . 'Z'
l!l
17
MC/DC100%1/1
$attrs->{"report"}{"created"} ||= $attrs->{"created"}->datetime . 'Z'
$attrs->{"report"}{"created"}
Truth table100%2/2
A
A= $attrs->{"report"}{"created"}
Aresult
11
00
115 8 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 ▶sub upload( $self ) {
Subroutine upload: called CC=1 SCAR=0.0
Pod documented
128 1 my ( $dist, $vers ) = $self->report->{distribution}->@{qw( name version )};
129 1 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 ▶sub dist_name( $self ) {
Subroutine dist_name: called CC=1 SCAR=0.0
Pod documented
140 1 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 ▶sub dist_version( $self ) {
Subroutine dist_version: called CC=1 SCAR=0.0
Pod documented
150 1 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 ▶sub lang_version( $self ) {
Subroutine lang_version: called CC=1 SCAR=0.0
Pod documented
160 return sprintf '%s v%s',
161 1 $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 ▶sub platform( $self ) {
Subroutine platform: called CC=1 SCAR=0.0
Pod documented
171 1 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 ▶sub grade( $self ) {
Subroutine grade: called CC=1 SCAR=0.0
Pod documented
181 1 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 15 my @output_phases = qw( configure build test install );
192 ▶sub text( $self ) {
Subroutine text: called CC=2 SCAR=9.2
Pod documented
193 return $self->report->{result}{output}{uncategorized}
194 1 ▶ || join "\n\n", grep defined, $self->report->{result}{output}->@{ @output_phases };
Condition33%1/3
$self->report->{'result'}{'output'}{'uncategorized'} || join("\n\n", grep(defined($_), @$self->report->{'result'}{'output'}{@output_phases}))
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->report->{'result'}{'output'}{'uncategorized'} || join("\n\n", grep(defined($_), @$self->report->{'result'}{'output'}{@output_phases}))
$self->report->{'result'}{'output'}{'uncategorized'} join("\n\n", grep(defined($_), @$self->report->{'result'}{'output'}{@output_phases}))
Truth table33%1/3
A || B
A= $self->report->{'result'}{'output'}{'uncategorized'}B= join("\n\n", grep(defined($_), @$self->report->{'result'}{'output'}{@output_phases}))
ABresult
1X1
011
000
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 ▶sub tester_name( $self ) {
Subroutine tester_name: called CC=1 SCAR=0.0
Pod documented
204 1 return html_unescape $self->report->{reporter}{name};
205 }
206  
207 15 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
« blib/lib/CPAN/Testers/Schema/Result/Upload.pm ↑ Summary blib/lib/CPAN/Testers/Schema/ResultSet/PerlVersion.pm »