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   20014 use utf8;
  13         38  
  13         103  
2             package CPAN::Testers::Schema::Result::Upload;
3             our $VERSION = '0.024';
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   943 use CPAN::Testers::Schema::Base 'Result';
  13         30  
  13         104  
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             package
170             CPAN::Testers::Schema::DateTime::Formatter {
171 1     1   2170 sub format_datetime( $self, $dt ) {
  1         3  
  1         3  
  1         2  
172             # XXX Replace this with DateTime::Format::ISO8601 when
173             # https://github.com/jhoblitt/DateTime-Format-ISO8601/pull/2
174             # is merged
175 1 50       5 my $cldr = $dt->nanosecond % 1000000 ? 'yyyy-MM-ddTHH:mm:ss.SSSSSSSSS'
    50          
176             : $dt->nanosecond ? 'yyyy-MM-ddTHH:mm:ss.SSS'
177             : 'yyyy-MM-ddTHH:mm:ss';
178              
179 1         18 my $tz;
180 1 50       5 if ( $dt->time_zone->is_utc ) {
181 1         12 $tz = 'Z';
182             }
183             else {
184 0         0 my $offset = $dt->time_zone->offset_for_datetime( $dt );
185 0         0 $tz = DateTime::TimeZone->offset_as_string( $offset );
186 0         0 substr $tz, 3, 0, ':';
187             }
188              
189 1         5 return $dt->format_cldr( $cldr ) . $tz;
190             }
191             }
192              
193             1;
194              
195             __END__
196              
197             =pod
198              
199             =head1 NAME
200              
201             CPAN::Testers::Schema::Result::Upload - Information about uploads to CPAN
202              
203             =head1 VERSION
204              
205             version 0.024
206              
207             =head1 SYNOPSIS
208              
209             my $upload = $schema->resultset( 'Upload' )
210             ->search( dist => 'My-Dist', version => '0.01' )->first;
211              
212             say $row->author . " released as " . $row->filename;
213             say scalar localtime $row->released;
214             if ( $row->type eq 'backpan' ) {
215             say "Deleted from CPAN";
216             }
217              
218             my $new_upload = $schema->resultset( 'Upload' )->create({
219             type => 'cpan',
220             dist => 'My-Dist',
221             version => '1.001',
222             author => 'PREACTION',
223             filename => 'My-Dist-1.001.tar.gz',
224             released => 1366237867,
225             });
226              
227             =head1 DESCRIPTION
228              
229             This table contains information about uploads to CPAN, including who
230             uploaded it, when it was uploaded, and when it was deleted (and thus
231             only available to BackPAN).
232              
233             B<NOTE>: Since files can be deleted from PAUSE, and new files uploaded
234             with the same name, distribution, and version, there may be duplicate
235             C<< dist => version >> pairs in this table. This table does not
236             determine which packages were authorized and indexed by PAUSE for
237             installation by CPAN clients.
238              
239             This data is read directly from the local CPAN mirror by
240             L<CPAN::Testers::Data::Uploads> and written to this table.
241              
242             =head1 ATTRIBUTES
243              
244             =head2 uploadid
245              
246             The ID of this upload. Auto-generated.
247              
248             =head2 type
249              
250             This column indicates where the distribution is. It can be one of three values:
251              
252             =over 4
253              
254             =item cpan
255              
256             This distribution is on CPAN
257              
258             =item backpan
259              
260             This distribution has been deleted from CPAN and is only available on BackPAN
261              
262             =item upload
263              
264             This distribution has been reported via NNTP (nntp.perl.org group perl.cpan.uploads),
265             but has not yet been seen on CPAN itself.
266              
267             =back
268              
269             =head2 author
270              
271             The PAUSE ID of the user who uploaded this distribution.
272              
273             =head2 dist
274              
275             The distribution name, parsed from the uploaded file's name using
276             L<CPAN::DistnameInfo>.
277              
278             =head2 version
279              
280             The version of the distribution, parsed from the uploaded file's name
281             using L<CPAN::DistnameInfo>.
282              
283             =head2 filename
284              
285             The full file name uploaded to CPAN, without the author directory prefix.
286              
287             =head2 released
288              
289             The date/time of the dist release. Calculated from the file's modified
290             time, as synced by the CPAN mirror sync system, or from the upload
291             notification message time from the NNTP group.
292              
293             Inflated from a UNIX epoch into a L<DateTime> object.
294              
295             =head1 SEE ALSO
296              
297             L<DBIx::Class::Row>, L<CPAN::Testers::Schema>
298              
299             =head1 AUTHORS
300              
301             =over 4
302              
303             =item *
304              
305             Oriol Soriano <oriolsoriano@gmail.com>
306              
307             =item *
308              
309             Doug Bell <preaction@cpan.org>
310              
311             =back
312              
313             =head1 COPYRIGHT AND LICENSE
314              
315             This software is copyright (c) 2018 by Oriol Soriano, Doug Bell.
316              
317             This is free software; you can redistribute it and/or modify it under
318             the same terms as the Perl 5 programming language system itself.
319              
320             =cut