File Coverage

blib/lib/CPAN/Testers/Schema/Result/Upload.pm
Criterion Covered Total %
statement 15 18 83.3
branch 3 6 50.0
condition n/a
subroutine 3 3 100.0
pod n/a
total 21 27 77.7


line stmt bran cond sub pod time code
1 13     13   14630 use utf8;
  13         31  
  13         101  
2             package CPAN::Testers::Schema::Result::Upload;
3             our $VERSION = '0.025';
4             # ABSTRACT: Information about uploads to CPAN
5              
6             #pod =head1 SYNOPSIS
7             #pod
8             #pod my $upload = $schema->resultset( 'Upload' )
9             #pod ->search( dist => 'My-Dist', version => '0.01' )->first;
10             #pod
11             #pod say $row->author . " released as " . $row->filename;
12             #pod say scalar localtime $row->released;
13             #pod if ( $row->type eq 'backpan' ) {
14             #pod say "Deleted from CPAN";
15             #pod }
16             #pod
17             #pod my $new_upload = $schema->resultset( 'Upload' )->create({
18             #pod type => 'cpan',
19             #pod dist => 'My-Dist',
20             #pod version => '1.001',
21             #pod author => 'PREACTION',
22             #pod filename => 'My-Dist-1.001.tar.gz',
23             #pod released => 1366237867,
24             #pod });
25             #pod
26             #pod =head1 DESCRIPTION
27             #pod
28             #pod This table contains information about uploads to CPAN, including who
29             #pod uploaded it, when it was uploaded, and when it was deleted (and thus
30             #pod only available to BackPAN).
31             #pod
32             #pod B<NOTE>: Since files can be deleted from PAUSE, and new files uploaded
33             #pod with the same name, distribution, and version, there may be duplicate
34             #pod C<< dist => version >> pairs in this table. This table does not
35             #pod determine which packages were authorized and indexed by PAUSE for
36             #pod installation by CPAN clients.
37             #pod
38             #pod This data is read directly from the local CPAN mirror by
39             #pod L<CPAN::Testers::Data::Uploads> and written to this table.
40             #pod
41             #pod =head1 SEE ALSO
42             #pod
43             #pod L<DBIx::Class::Row>, L<CPAN::Testers::Schema>
44             #pod
45             #pod =cut
46              
47 13     13   761 use CPAN::Testers::Schema::Base 'Result';
  13         29  
  13         84  
48             __PACKAGE__->load_components( 'InflateColumn' );
49             table 'uploads';
50              
51             #pod =attr uploadid
52             #pod
53             #pod The ID of this upload. Auto-generated.
54             #pod
55             #pod =cut
56              
57             primary_column uploadid => {
58             data_type => 'int',
59             extra => { unsigned => 1 },
60             is_auto_increment => 1,
61             is_nullable => 0,
62             };
63              
64             #pod =attr type
65             #pod
66             #pod This column indicates where the distribution is. It can be one of three values:
67             #pod
68             #pod =over 4
69             #pod
70             #pod =item cpan
71             #pod
72             #pod This distribution is on CPAN
73             #pod
74             #pod =item backpan
75             #pod
76             #pod This distribution has been deleted from CPAN and is only available on BackPAN
77             #pod
78             #pod =item upload
79             #pod
80             #pod This distribution has been reported via NNTP (nntp.perl.org group perl.cpan.uploads),
81             #pod but has not yet been seen on CPAN itself.
82             #pod
83             #pod =back
84             #pod
85             #pod =cut
86              
87             column type => {
88             data_type => 'varchar',
89             is_nullable => 0,
90             };
91              
92             #pod =attr author
93             #pod
94             #pod The PAUSE ID of the user who uploaded this distribution.
95             #pod
96             #pod =cut
97              
98             column author => {
99             data_type => 'varchar',
100             is_nullable => 0,
101             };
102              
103             #pod =attr dist
104             #pod
105             #pod The distribution name, parsed from the uploaded file's name using
106             #pod L<CPAN::DistnameInfo>.
107             #pod
108             #pod =cut
109              
110             column dist => {
111             data_type => 'varchar',
112             is_nullable => 0,
113             };
114              
115             #pod =attr version
116             #pod
117             #pod The version of the distribution, parsed from the uploaded file's name
118             #pod using L<CPAN::DistnameInfo>.
119             #pod
120             #pod =cut
121              
122             column version => {
123             data_type => 'varchar',
124             is_nullable => 0,
125             };
126              
127             #pod =attr filename
128             #pod
129             #pod The full file name uploaded to CPAN, without the author directory prefix.
130             #pod
131             #pod =cut
132              
133             column filename => {
134             data_type => 'varchar',
135             is_nullable => 0,
136             };
137              
138             #pod =attr released
139             #pod
140             #pod The date/time of the dist release. Calculated from the file's modified
141             #pod time, as synced by the CPAN mirror sync system, or from the upload
142             #pod notification message time from the NNTP group.
143             #pod
144             #pod Inflated from a UNIX epoch into a L<DateTime> object.
145             #pod
146             #pod =cut
147              
148             column released => {
149             data_type => 'bigint',
150             is_nullable => 0,
151             inflate_datetime => 1,
152             };
153              
154             __PACKAGE__->inflate_column(
155             released => {
156             deflate => sub( $value, $event ) {
157             ref $value ? $value->epoch : $value
158             },
159             inflate => sub( $value, $event ) {
160             DateTime->from_epoch(
161             epoch => $value,
162             time_zone => 'UTC',
163             formatter => 'CPAN::Testers::Schema::DateTime::Formatter',
164             );
165             },
166             },
167             );
168              
169             #pod =method report_metrics
170             #pod
171             #pod The linked report metrics rows for this distribution, a L<CPAN::Testers::Schema::ResultSet::Release>
172             #pod object.
173             #pod
174             #pod =cut
175              
176             has_many report_metrics => 'CPAN::Testers::Schema::Result::Release',
177             {
178             'foreign.dist' => 'self.dist',
179             'foreign.version' => 'self.version',
180             };
181              
182             package
183             CPAN::Testers::Schema::DateTime::Formatter {
184 1     1   1773 sub format_datetime( $self, $dt ) {
  1         3  
  1         1  
  1         3  
185             # XXX Replace this with DateTime::Format::ISO8601 when
186             # https://github.com/jhoblitt/DateTime-Format-ISO8601/pull/2
187             # is merged
188 1 50       3 my $cldr = $dt->nanosecond % 1000000 ? 'yyyy-MM-ddTHH:mm:ss.SSSSSSSSS'
    50          
189             : $dt->nanosecond ? 'yyyy-MM-ddTHH:mm:ss.SSS'
190             : 'yyyy-MM-ddTHH:mm:ss';
191              
192 1         13 my $tz;
193 1 50       4 if ( $dt->time_zone->is_utc ) {
194 1         10 $tz = 'Z';
195             }
196             else {
197 0         0 my $offset = $dt->time_zone->offset_for_datetime( $dt );
198 0         0 $tz = DateTime::TimeZone->offset_as_string( $offset );
199 0         0 substr $tz, 3, 0, ':';
200             }
201              
202 1         5 return $dt->format_cldr( $cldr ) . $tz;
203             }
204             }
205              
206             1;
207              
208             __END__
209              
210             =pod
211              
212             =head1 NAME
213              
214             CPAN::Testers::Schema::Result::Upload - Information about uploads to CPAN
215              
216             =head1 VERSION
217              
218             version 0.025
219              
220             =head1 SYNOPSIS
221              
222             my $upload = $schema->resultset( 'Upload' )
223             ->search( dist => 'My-Dist', version => '0.01' )->first;
224              
225             say $row->author . " released as " . $row->filename;
226             say scalar localtime $row->released;
227             if ( $row->type eq 'backpan' ) {
228             say "Deleted from CPAN";
229             }
230              
231             my $new_upload = $schema->resultset( 'Upload' )->create({
232             type => 'cpan',
233             dist => 'My-Dist',
234             version => '1.001',
235             author => 'PREACTION',
236             filename => 'My-Dist-1.001.tar.gz',
237             released => 1366237867,
238             });
239              
240             =head1 DESCRIPTION
241              
242             This table contains information about uploads to CPAN, including who
243             uploaded it, when it was uploaded, and when it was deleted (and thus
244             only available to BackPAN).
245              
246             B<NOTE>: Since files can be deleted from PAUSE, and new files uploaded
247             with the same name, distribution, and version, there may be duplicate
248             C<< dist => version >> pairs in this table. This table does not
249             determine which packages were authorized and indexed by PAUSE for
250             installation by CPAN clients.
251              
252             This data is read directly from the local CPAN mirror by
253             L<CPAN::Testers::Data::Uploads> and written to this table.
254              
255             =head1 ATTRIBUTES
256              
257             =head2 uploadid
258              
259             The ID of this upload. Auto-generated.
260              
261             =head2 type
262              
263             This column indicates where the distribution is. It can be one of three values:
264              
265             =over 4
266              
267             =item cpan
268              
269             This distribution is on CPAN
270              
271             =item backpan
272              
273             This distribution has been deleted from CPAN and is only available on BackPAN
274              
275             =item upload
276              
277             This distribution has been reported via NNTP (nntp.perl.org group perl.cpan.uploads),
278             but has not yet been seen on CPAN itself.
279              
280             =back
281              
282             =head2 author
283              
284             The PAUSE ID of the user who uploaded this distribution.
285              
286             =head2 dist
287              
288             The distribution name, parsed from the uploaded file's name using
289             L<CPAN::DistnameInfo>.
290              
291             =head2 version
292              
293             The version of the distribution, parsed from the uploaded file's name
294             using L<CPAN::DistnameInfo>.
295              
296             =head2 filename
297              
298             The full file name uploaded to CPAN, without the author directory prefix.
299              
300             =head2 released
301              
302             The date/time of the dist release. Calculated from the file's modified
303             time, as synced by the CPAN mirror sync system, or from the upload
304             notification message time from the NNTP group.
305              
306             Inflated from a UNIX epoch into a L<DateTime> object.
307              
308             =head1 METHODS
309              
310             =head2 report_metrics
311              
312             The linked report metrics rows for this distribution, a L<CPAN::Testers::Schema::ResultSet::Release>
313             object.
314              
315             =head1 SEE ALSO
316              
317             L<DBIx::Class::Row>, L<CPAN::Testers::Schema>
318              
319             =head1 AUTHORS
320              
321             =over 4
322              
323             =item *
324              
325             Oriol Soriano <oriolsoriano@gmail.com>
326              
327             =item *
328              
329             Doug Bell <preaction@cpan.org>
330              
331             =back
332              
333             =head1 COPYRIGHT AND LICENSE
334              
335             This software is copyright (c) 2018 by Oriol Soriano, Doug Bell.
336              
337             This is free software; you can redistribute it and/or modify it under
338             the same terms as the Perl 5 programming language system itself.
339              
340             =cut