File Coverage

blib/lib/CPAN/Testers/Schema/Result/PerlVersion.pm
Criterion Covered Total %
statement 18 18 100.0
branch 7 10 70.0
condition 3 3 100.0
subroutine 3 3 100.0
pod 1 1 100.0
total 32 35 91.4


line stmt bran cond sub pod time code
1 13     13   14621 use utf8;
  13         48  
  13         97  
2             package CPAN::Testers::Schema::Result::PerlVersion;
3             our $VERSION = '0.024';
4             # ABSTRACT: Metadata about Perl versions
5              
6             #pod =head1 SYNOPSIS
7             #pod
8             #pod my $perl = $schema->resultset( 'PerlVersion' )->find( '5.26.0' );
9             #pod say "Stable" unless $perl->devel;
10             #pod
11             #pod $schema->resultset( 'PerlVersion' )->find_or_create({
12             #pod version => '5.30.0', # Version reported by Perl
13             #pod perl => '5.30.0', # Parsed Perl version string
14             #pod patch => 0, # Has patches applied
15             #pod devel => 0, # Is development version (odd minor version)
16             #pod });
17             #pod
18             #pod # Fill in metadata automatically
19             #pod $schema->resultset( 'PerlVersion' )->find_or_create({
20             #pod version => '5.31.0 patch 1231',
21             #pod # devel will be set to 1
22             #pod # patch will be set to 1
23             #pod # perl will be set to 5.31.0
24             #pod });
25             #pod
26             #pod =head1 DESCRIPTION
27             #pod
28             #pod This table holds metadata about known Perl versions. Through this table we can
29             #pod quickly list which Perl versions are stable/development.
30             #pod
31             #pod =head1 SEE ALSO
32             #pod
33             #pod L<DBIx::Class::Row>, L<CPAN::Testers::Schema>
34             #pod
35             #pod =cut
36              
37 13     13   909 use CPAN::Testers::Schema::Base 'Result';
  13         32  
  13         93  
38              
39             table 'perl_version';
40              
41             #pod =attr version
42             #pod
43             #pod The Perl version reported by the tester. This is the primary key.
44             #pod
45             #pod =cut
46              
47             primary_column version => {
48             data_type => 'varchar',
49             size => 255,
50             is_nullable => 0,
51             };
52              
53             #pod =attr perl
54             #pod
55             #pod The parsed version of Perl in C<REVISION.VERSION.SUBVERSION> format.
56             #pod
57             #pod If not specified when creating a new row, the Perl version will be parsed
58             #pod and this field updated accordingly.
59             #pod
60             #pod =cut
61              
62             column perl => {
63             data_type => 'varchar',
64             size => 32,
65             is_nullable => 1,
66             };
67              
68             #pod =attr patch
69             #pod
70             #pod If true (C<1>), this Perl has patches applied. Defaults to false (C<0>).
71             #pod
72             #pod If not specified when creating a new row, the Perl version will be parsed
73             #pod and this field updated accordingly.
74             #pod
75             #pod =cut
76              
77             column patch => {
78             data_type => 'tinyint',
79             size => 1,
80             default_value => 0,
81             };
82              
83             #pod =attr devel
84             #pod
85             #pod If true (C<1>), this Perl is a development Perl version. Development Perl
86             #pod versions have an odd C<VERSION> field (the second number) like C<5.27.0>,
87             #pod C<5.29.0>, C<5.31.0>, etc... Release candidates (like C<5.28.0 RC0>) are
88             #pod also considered development versions.
89             #pod
90             #pod If not specified when creating a new row, the Perl version will be parsed
91             #pod and this field updated accordingly.
92             #pod
93             #pod =cut
94              
95             column devel => {
96             data_type => 'tinyint',
97             size => 1,
98             default_value => 0,
99             };
100              
101             #pod =method new
102             #pod
103             #pod The constructor will automatically fill in any missing information based
104             #pod on the supplied C<version> field.
105             #pod
106             #pod =cut
107              
108 16     16 1 2764577 sub new( $class, $attrs ) {
  16         33  
  16         31  
  16         28  
109 16 50       52 if ( !$attrs->{perl} ) {
110 16         105 ( $attrs->{perl} ) = $attrs->{version} =~ m{^v?(\d+\.\d+\.\d+)};
111             }
112 16 50       53 if ( !$attrs->{patch} ) {
113 16 100       66 $attrs->{patch} = ( $attrs->{version} =~ m{patch} ) ? 1 : 0;
114             }
115 16 50       47 if ( !$attrs->{devel} ) {
116 16         63 my ( $version ) = $attrs->{version} =~ m{^v?\d+\.(\d+)};
117             $attrs->{devel} =
118             (
119             ( $version >= 7 && $version % 2 ) ||
120 16 100 100     142 $attrs->{version} =~ m{^v?\d+\.\d+\.\d+ RC\d+}
121             ) ? 1 : 0;
122             }
123 16         71 return $class->next::method( $attrs );
124             }
125              
126             1;
127              
128             __END__
129              
130             =pod
131              
132             =head1 NAME
133              
134             CPAN::Testers::Schema::Result::PerlVersion - Metadata about Perl versions
135              
136             =head1 VERSION
137              
138             version 0.024
139              
140             =head1 SYNOPSIS
141              
142             my $perl = $schema->resultset( 'PerlVersion' )->find( '5.26.0' );
143             say "Stable" unless $perl->devel;
144              
145             $schema->resultset( 'PerlVersion' )->find_or_create({
146             version => '5.30.0', # Version reported by Perl
147             perl => '5.30.0', # Parsed Perl version string
148             patch => 0, # Has patches applied
149             devel => 0, # Is development version (odd minor version)
150             });
151              
152             # Fill in metadata automatically
153             $schema->resultset( 'PerlVersion' )->find_or_create({
154             version => '5.31.0 patch 1231',
155             # devel will be set to 1
156             # patch will be set to 1
157             # perl will be set to 5.31.0
158             });
159              
160             =head1 DESCRIPTION
161              
162             This table holds metadata about known Perl versions. Through this table we can
163             quickly list which Perl versions are stable/development.
164              
165             =head1 ATTRIBUTES
166              
167             =head2 version
168              
169             The Perl version reported by the tester. This is the primary key.
170              
171             =head2 perl
172              
173             The parsed version of Perl in C<REVISION.VERSION.SUBVERSION> format.
174              
175             If not specified when creating a new row, the Perl version will be parsed
176             and this field updated accordingly.
177              
178             =head2 patch
179              
180             If true (C<1>), this Perl has patches applied. Defaults to false (C<0>).
181              
182             If not specified when creating a new row, the Perl version will be parsed
183             and this field updated accordingly.
184              
185             =head2 devel
186              
187             If true (C<1>), this Perl is a development Perl version. Development Perl
188             versions have an odd C<VERSION> field (the second number) like C<5.27.0>,
189             C<5.29.0>, C<5.31.0>, etc... Release candidates (like C<5.28.0 RC0>) are
190             also considered development versions.
191              
192             If not specified when creating a new row, the Perl version will be parsed
193             and this field updated accordingly.
194              
195             =head1 METHODS
196              
197             =head2 new
198              
199             The constructor will automatically fill in any missing information based
200             on the supplied C<version> field.
201              
202             =head1 SEE ALSO
203              
204             L<DBIx::Class::Row>, L<CPAN::Testers::Schema>
205              
206             =head1 AUTHORS
207              
208             =over 4
209              
210             =item *
211              
212             Oriol Soriano <oriolsoriano@gmail.com>
213              
214             =item *
215              
216             Doug Bell <preaction@cpan.org>
217              
218             =back
219              
220             =head1 COPYRIGHT AND LICENSE
221              
222             This software is copyright (c) 2018 by Oriol Soriano, Doug Bell.
223              
224             This is free software; you can redistribute it and/or modify it under
225             the same terms as the Perl 5 programming language system itself.
226              
227             =cut