File Coverage

blib/lib/CPAN/Testers/Schema/ResultSet/Upload.pm
Criterion Covered Total %
statement 30 30 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 4 4 100.0
total 41 41 100.0


line stmt bran cond sub pod time code
1 13     13   12903 use utf8;
  13         30  
  13         63  
2             package CPAN::Testers::Schema::ResultSet::Upload;
3             our $VERSION = '0.025';
4             # ABSTRACT: Query the CPAN uploads data
5              
6             #pod =head1 SYNOPSIS
7             #pod
8             #pod my $rs = $schema->resultset( 'Upload' );
9             #pod $rs->by_dist( 'My-Dist' );
10             #pod $rs->by_author( 'PREACTION' );
11             #pod $rs->since( '2016-01-01T00:00:00' );
12             #pod
13             #pod =head1 DESCRIPTION
14             #pod
15             #pod This object helps to query the CPAN uploads table. This table tracks
16             #pod uploads to CPAN by distribution, version, and author, and also flags
17             #pod distributions that have been deleted from CPAN (and are thus only
18             #pod available on BackPAN).
19             #pod
20             #pod =head1 SEE ALSO
21             #pod
22             #pod L<CPAN::Testers::Schema::Result::Upload>, L<DBIx::Class::ResultSet>,
23             #pod L<CPAN::Testers::Schema>
24             #pod
25             #pod =cut
26              
27 13     13   700 use CPAN::Testers::Schema::Base 'ResultSet';
  13         25  
  13         72  
28 13     13   390 use DateTime::Format::ISO8601;
  13         24  
  13         2779  
29              
30             #pod =method by_dist
31             #pod
32             #pod $rs = $rs->by_dist( 'My-Dist' );
33             #pod
34             #pod Add a dist constraint to the query, replacing any previous dist
35             #pod constraints.
36             #pod
37             #pod =cut
38              
39 2     2 1 634474 sub by_dist( $self, $dist ) {
  2         5  
  2         5  
  2         2  
40 2         11 return $self->search( { 'me.dist' => $dist } );
41             }
42              
43             #pod =method by_author
44             #pod
45             #pod $rs = $rs->by_author( 'PREACTION' );
46             #pod
47             #pod Add an author constraint to the query, replacing any previous author
48             #pod constraints.
49             #pod
50             #pod =cut
51              
52 2     2 1 11643 sub by_author( $self, $author ) {
  2         5  
  2         4  
  2         4  
53 2         8 return $self->search( { 'me.author' => $author } );
54             }
55              
56             #pod =method since
57             #pod
58             #pod $rs = $rs->since( '2016-01-01T00:00:00' );
59             #pod
60             #pod Restrict results to only those that have been updated since the given
61             #pod ISO8601 date.
62             #pod
63             #pod =cut
64              
65 3     3 1 7794 sub since( $self, $date ) {
  3         8  
  3         4  
  3         6  
66 3         18 my $dt = DateTime::Format::ISO8601->parse_datetime( $date );
67 3         1463 return $self->search( { released => { '>=' => $dt->epoch } } );
68             }
69              
70             #pod =method recent
71             #pod
72             #pod # 20 most recent
73             #pod $rs = $rs->recent( 20 );
74             #pod
75             #pod # Just the most recent
76             #pod $rs = $rs->recent( 1 );
77             #pod
78             #pod Return the most-recently released distributions sorted by their release
79             #pod date/time, descending. Defaults to returning up to 20 results.
80             #pod
81             #pod =cut
82              
83 2     2 1 8468 sub recent( $self, $count = 20 ) {
  2         4  
  2         3  
  2         3  
84 2         11 return $self->search( { }, {
85             order_by => { -desc => 'released' },
86             rows => $count,
87             page => 1,
88             } );
89             }
90              
91             1;
92              
93             __END__
94              
95             =pod
96              
97             =head1 NAME
98              
99             CPAN::Testers::Schema::ResultSet::Upload - Query the CPAN uploads data
100              
101             =head1 VERSION
102              
103             version 0.025
104              
105             =head1 SYNOPSIS
106              
107             my $rs = $schema->resultset( 'Upload' );
108             $rs->by_dist( 'My-Dist' );
109             $rs->by_author( 'PREACTION' );
110             $rs->since( '2016-01-01T00:00:00' );
111              
112             =head1 DESCRIPTION
113              
114             This object helps to query the CPAN uploads table. This table tracks
115             uploads to CPAN by distribution, version, and author, and also flags
116             distributions that have been deleted from CPAN (and are thus only
117             available on BackPAN).
118              
119             =head1 METHODS
120              
121             =head2 by_dist
122              
123             $rs = $rs->by_dist( 'My-Dist' );
124              
125             Add a dist constraint to the query, replacing any previous dist
126             constraints.
127              
128             =head2 by_author
129              
130             $rs = $rs->by_author( 'PREACTION' );
131              
132             Add an author constraint to the query, replacing any previous author
133             constraints.
134              
135             =head2 since
136              
137             $rs = $rs->since( '2016-01-01T00:00:00' );
138              
139             Restrict results to only those that have been updated since the given
140             ISO8601 date.
141              
142             =head2 recent
143              
144             # 20 most recent
145             $rs = $rs->recent( 20 );
146              
147             # Just the most recent
148             $rs = $rs->recent( 1 );
149              
150             Return the most-recently released distributions sorted by their release
151             date/time, descending. Defaults to returning up to 20 results.
152              
153             =head1 SEE ALSO
154              
155             L<CPAN::Testers::Schema::Result::Upload>, L<DBIx::Class::ResultSet>,
156             L<CPAN::Testers::Schema>
157              
158             =head1 AUTHORS
159              
160             =over 4
161              
162             =item *
163              
164             Oriol Soriano <oriolsoriano@gmail.com>
165              
166             =item *
167              
168             Doug Bell <preaction@cpan.org>
169              
170             =back
171              
172             =head1 COPYRIGHT AND LICENSE
173              
174             This software is copyright (c) 2018 by Oriol Soriano, Doug Bell.
175              
176             This is free software; you can redistribute it and/or modify it under
177             the same terms as the Perl 5 programming language system itself.
178              
179             =cut