|
| 1 | +use utf8; |
| 2 | +package CPAN::Testers::Schema::Result::PerlVersion; |
| 3 | +our $VERSION = '0.023'; |
| 4 | +# ABSTRACT: Metadata about Perl versions |
| 5 | + |
| 6 | +=head1 SYNOPSIS |
| 7 | +
|
| 8 | + my $perl = $schema->resultset( 'PerlVersion' )->find( '5.26.0' ); |
| 9 | + say "Stable" unless $perl->devel; |
| 10 | +
|
| 11 | + $schema->resultset( 'PerlVersion' )->find_or_create({ |
| 12 | + version => '5.30.0', # Version reported by Perl |
| 13 | + perl => '5.30.0', # Parsed Perl version string |
| 14 | + patch => 0, # Has patches applied |
| 15 | + devel => 0, # Is development version (odd minor version) |
| 16 | + }); |
| 17 | +
|
| 18 | + # Fill in metadata automatically |
| 19 | + $schema->resultset( 'PerlVersion' )->find_or_create({ |
| 20 | + version => '5.31.0 patch 1231', |
| 21 | + # devel will be set to 1 |
| 22 | + # patch will be set to 1 |
| 23 | + # perl will be set to 5.31.0 |
| 24 | + }); |
| 25 | +
|
| 26 | +=head1 DESCRIPTION |
| 27 | +
|
| 28 | +This table holds metadata about known Perl versions. Through this table we can |
| 29 | +quickly list which Perl versions are stable/development. |
| 30 | +
|
| 31 | +=head1 SEE ALSO |
| 32 | +
|
| 33 | +L<DBIx::Class::Row>, L<CPAN::Testers::Schema> |
| 34 | +
|
| 35 | +=cut |
| 36 | + |
| 37 | +use CPAN::Testers::Schema::Base 'Result'; |
| 38 | + |
| 39 | +table 'perl_version'; |
| 40 | + |
| 41 | +=attr version |
| 42 | +
|
| 43 | +The Perl version reported by the tester. This is the primary key. |
| 44 | +
|
| 45 | +=cut |
| 46 | + |
| 47 | +primary_column version => { |
| 48 | + data_type => 'varchar', |
| 49 | + size => 255, |
| 50 | + is_nullable => 0, |
| 51 | +}; |
| 52 | + |
| 53 | +=attr perl |
| 54 | +
|
| 55 | +The parsed version of Perl in C<REVISION.VERSION.SUBVERSION> format. |
| 56 | +
|
| 57 | +If not specified when creating a new row, the Perl version will be parsed |
| 58 | +and this field updated accordingly. |
| 59 | +
|
| 60 | +=cut |
| 61 | + |
| 62 | +column perl => { |
| 63 | + data_type => 'varchar', |
| 64 | + size => 32, |
| 65 | + is_nullable => 1, |
| 66 | +}; |
| 67 | + |
| 68 | +=attr patch |
| 69 | +
|
| 70 | +If true (C<1>), this Perl has patches applied. Defaults to false (C<0>). |
| 71 | +
|
| 72 | +If not specified when creating a new row, the Perl version will be parsed |
| 73 | +and this field updated accordingly. |
| 74 | +
|
| 75 | +=cut |
| 76 | + |
| 77 | +column patch => { |
| 78 | + data_type => 'tinyint', |
| 79 | + size => 1, |
| 80 | + default_value => 0, |
| 81 | +}; |
| 82 | + |
| 83 | +=attr devel |
| 84 | +
|
| 85 | +If true (C<1>), this Perl is a development Perl version. Development Perl |
| 86 | +versions have an odd C<VERSION> field (the second number) like C<5.27.0>, |
| 87 | +C<5.29.0>, C<5.31.0>, etc... Release candidates (like C<5.28.0 RC0>) are |
| 88 | +also considered development versions. |
| 89 | +
|
| 90 | +If not specified when creating a new row, the Perl version will be parsed |
| 91 | +and this field updated accordingly. |
| 92 | +
|
| 93 | +=cut |
| 94 | + |
| 95 | +column devel => { |
| 96 | + data_type => 'tinyint', |
| 97 | + size => 1, |
| 98 | + default_value => 0, |
| 99 | +}; |
| 100 | + |
| 101 | +=method new |
| 102 | +
|
| 103 | +The constructor will automatically fill in any missing information based |
| 104 | +on the supplied C<version> field. |
| 105 | +
|
| 106 | +=cut |
| 107 | + |
| 108 | +sub new( $class, $attrs ) { |
| 109 | + if ( !$attrs->{perl} ) { |
| 110 | + ( $attrs->{perl} ) = $attrs->{version} =~ m{^v?(\d+\.\d+\.\d+)}; |
| 111 | + } |
| 112 | + if ( !$attrs->{patch} ) { |
| 113 | + $attrs->{patch} = ( $attrs->{version} =~ m{patch} ) ? 1 : 0; |
| 114 | + } |
| 115 | + if ( !$attrs->{devel} ) { |
| 116 | + my ( $version ) = $attrs->{version} =~ m{^v?\d+\.(\d+)}; |
| 117 | + $attrs->{devel} = |
| 118 | + ( |
| 119 | + ( $version >= 7 && $version % 2 ) || |
| 120 | + $attrs->{version} =~ m{^v?\d+\.\d+\.\d+ RC\d+} |
| 121 | + ) ? 1 : 0; |
| 122 | + } |
| 123 | + return $class->next::method( $attrs ); |
| 124 | +} |
| 125 | + |
| 126 | +1; |
0 commit comments