| 1 | # ---------------------------------------------------------------------- copyright and license --- | ||||||||||||||
| 2 | # | ||||||||||||||
| 3 | # file: lib/Dist/Zilla/Plugin/Author/VDB/Version/Read.pm | ||||||||||||||
| 4 | # | ||||||||||||||
| 5 | # Copyright © 2015 Van de Bugger | ||||||||||||||
| 6 | # | ||||||||||||||
| 7 | # This file is part of perl-Dist-Zilla-PluginBundle-Author-VDB. | ||||||||||||||
| 8 | # | ||||||||||||||
| 9 | # perl-Dist-Zilla-PluginBundle-Author-VDB is free software: you can redistribute it and/or modify | ||||||||||||||
| 10 | # it under the terms of the GNU General Public License as published by the Free Software | ||||||||||||||
| 11 | # Foundation, either version 3 of the License, or (at your option) any later version. | ||||||||||||||
| 12 | # | ||||||||||||||
| 13 | # perl-Dist-Zilla-PluginBundle-Author-VDB is distributed in the hope that it will be useful, but | ||||||||||||||
| 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||||||||||||||
| 15 | # PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||||||||||||
| 16 | # | ||||||||||||||
| 17 | # You should have received a copy of the GNU General Public License along with | ||||||||||||||
| 18 | # perl-Dist-Zilla-PluginBundle-Author-VDB. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||
| 19 | # | ||||||||||||||
| 20 | # ---------------------------------------------------------------------- copyright and license --- | ||||||||||||||
| 21 | |||||||||||||||
| 22 | #pod =for test_synopsis BEGIN { die "SKIP: not a Perl code"; } | ||||||||||||||
| 23 | #pod | ||||||||||||||
| 24 | #pod =head1 SYNOPSIS | ||||||||||||||
| 25 | #pod | ||||||||||||||
| 26 | #pod F<dist.in> file: | ||||||||||||||
| 27 | #pod | ||||||||||||||
| 28 | #pod ; version = v0.3.1 ; *Should **not** be used.* | ||||||||||||||
| 29 | #pod ... | ||||||||||||||
| 30 | #pod [Author::VDB::Version::Read] | ||||||||||||||
| 31 | #pod file = VERSION | ||||||||||||||
| 32 | #pod | ||||||||||||||
| 33 | #pod F<VERSION> file: | ||||||||||||||
| 34 | #pod | ||||||||||||||
| 35 | #pod v0.3.1 | ||||||||||||||
| 36 | #pod | ||||||||||||||
| 37 | #pod =head1 DESCRIPTION | ||||||||||||||
| 38 | #pod | ||||||||||||||
| 39 | #pod This plugin does C<VersionProvider> and C<ReleaseStatusProvider> roles. It reads version from | ||||||||||||||
| 40 | #pod specified file. Trailing whitespaces (including newlines) in a file is allowed and ignored. | ||||||||||||||
| 41 | #pod | ||||||||||||||
| 42 | #pod =cut | ||||||||||||||
| 43 | |||||||||||||||
| 44 | # -------------------------------------------------------------------------------------------------- | ||||||||||||||
| 45 | |||||||||||||||
| 46 | package Dist::Zilla::Plugin::Author::VDB::Version::Read; | ||||||||||||||
| 47 | |||||||||||||||
| 48 | 3 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 49 | 3 | ▶ | use namespace::autoclean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 50 | 3 | ▶ | use version 0.77; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 51 | |||||||||||||||
| 52 | # ABSTRACT: Read version from a file | ||||||||||||||
| 53 | 3 | our $VERSION = 'v0.11.3.1'; # TRIAL VERSION | |||||||||||||
| 54 | |||||||||||||||
| 55 | 3 | with 'Dist::Zilla::Role::VersionProvider'; | |||||||||||||
| 56 | 3 | with 'Dist::Zilla::Role::ReleaseStatusProvider'; | |||||||||||||
| 57 | 3 | with 'Dist::Zilla::Role::ErrorLogger' => { -version => 'v0.9.0' }; | |||||||||||||
| 58 | # ^ We need `ErrorLogger` to throw an exception, not plain string. | ||||||||||||||
| 59 | |||||||||||||||
| 60 | 3 | ▶ | use Path::Tiny; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 61 | 3 | ▶ | use Try::Tiny; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 62 | 3 | ▶ | use Version::Dotted::Semantic; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 63 | |||||||||||||||
| 64 | # -------------------------------------------------------------------------------------------------- | ||||||||||||||
| 65 | |||||||||||||||
| 66 | #pod =option file | ||||||||||||||
| 67 | #pod | ||||||||||||||
| 68 | #pod Name of file to read version from. Default value is C<VERSION>. Specifying an empty file disables | ||||||||||||||
| 69 | #pod the plugin. | ||||||||||||||
| 70 | #pod | ||||||||||||||
| 71 | #pod =cut | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 3 | has file => ( | |||||||||||||
| 74 | isa => 'Str', | ||||||||||||||
| 75 | is => 'ro', | ||||||||||||||
| 76 | default => 'VERSION', | ||||||||||||||
| 77 | ); | ||||||||||||||
| 78 | |||||||||||||||
| 79 | has _file => ( | ||||||||||||||
| 80 | isa => 'Path::Tiny', | ||||||||||||||
| 81 | is => 'ro', | ||||||||||||||
| 82 | init_arg => undef, | ||||||||||||||
| 83 | lazy => 1, | ||||||||||||||
| 84 | 15 | ▶ | default => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||
| 85 | 15 | my ( $self ) = @_; | |||||||||||||
| 86 | 15 | my $path = path( $self->file ); | |||||||||||||
| 87 | 15 | ▶ | if ( $path->is_absolute ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 88 | 1 | $self->abort( [ "Bad version file '%s': absolute path is not allowed", $self->file ] ); | |||||||||||||
| 89 | }; | ||||||||||||||
| 90 | 14 | return $path->absolute( $self->zilla->root ); | |||||||||||||
| 91 | }, | ||||||||||||||
| 92 | 3 | ); | |||||||||||||
| 93 | |||||||||||||||
| 94 | # -------------------------------------------------------------------------------------------------- | ||||||||||||||
| 95 | |||||||||||||||
| 96 | #pod =for Pod::Coverage provide_version | ||||||||||||||
| 97 | #pod | ||||||||||||||
| 98 | #pod =cut | ||||||||||||||
| 99 | |||||||||||||||
| 100 | 16 | ▶ | sub provide_version { | ||||||||||||
|
Subroutine
provide_version: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||
| 101 | 16 | my ( $self ) = @_; | |||||||||||||
| 102 | 16 | my $version; | |||||||||||||
| 103 | 16 | ▶ | if ( $self->file ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 104 | 15 | ▶ | try { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 105 | 15 | $version = $self->_file->slurp; | |||||||||||||
| 106 | 2 | ▶ | } catch { | ||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.2
| |||||||||||||||
| 107 | 2 | my $ex = $_; | |||||||||||||
| 108 | 2 | ▶ | my $class = blessed( $ex ) || ''; | ||||||||||||
|
Condition50%1/2
builtin::blessed($ex) || ''
MC/DC0%0/1
builtin::blessed($ex) || ''
builtin::blessed($ex)
Truth table50%1/2
A
A= builtin::blessed($ex)
| |||||||||||||||
| 109 | 2 | ▶ | if ( 0 ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 110 | } elsif ( $class eq 'Dist::Zilla::Role::ErrorLogger::Exception::Abort' ) { | ||||||||||||||
| 111 | # All the messages are aready logged, just rethrow the exception. | ||||||||||||||
| 112 | 1 | die $ex; ## no critic ( RequireCarping ) | |||||||||||||
| 113 | } elsif ( $class eq 'Path::Tiny::Error' ) { | ||||||||||||||
| 114 | 1 | chomp( my $em = "$ex" ); | |||||||||||||
| 115 | 1 | $self->log_debug( "$em" ); | |||||||||||||
| 116 | 1 | $self->abort( [ "Can't read version file '%s': %s", $self->file, $ex->{ err } ] ); | |||||||||||||
| 117 | } else { | ||||||||||||||
| 118 | 0 | $self->abort( $ex ); | |||||||||||||
| 119 | }; | ||||||||||||||
| 120 | 15 | }; | |||||||||||||
| 121 | 13 | $version =~ s{ \s+ \z }{}x; # Strip trailing whitespace (including newlines). | |||||||||||||
| 122 | 13 | ▶ | if ( not version::is_strict( $version ) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 123 | 1 | $self->abort( [ "Invalid version string '%s' at %s line 1", $version, $self->file ] ); | |||||||||||||
| 124 | }; | ||||||||||||||
| 125 | 12 | ▶ | if ( $version !~ m{ ^ v \d+ (?: \. \d+ )* $ }x ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 126 | 1 | $self->abort( [ | |||||||||||||
| 127 | "Not a dotted version string '%s' at %s line 1", $version, $self->file | ||||||||||||||
| 128 | ] ); | ||||||||||||||
| 129 | }; | ||||||||||||||
| 130 | } else { | ||||||||||||||
| 131 | 1 | $self->log_debug( 'no version file specified' ); | |||||||||||||
| 132 | }; | ||||||||||||||
| 133 | 12 | return $version; | |||||||||||||
| 134 | }; | ||||||||||||||
| 135 | |||||||||||||||
| 136 | # -------------------------------------------------------------------------------------------------- | ||||||||||||||
| 137 | |||||||||||||||
| 138 | #pod =for Pod::Coverage provide_release_status | ||||||||||||||
| 139 | #pod | ||||||||||||||
| 140 | #pod =cut | ||||||||||||||
| 141 | |||||||||||||||
| 142 | 4 | ▶ | sub provide_release_status { | ||||||||||||
|
Subroutine
provide_release_status: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 143 | 4 | my ( $self ) = @_; | |||||||||||||
| 144 | 4 | my $v = Version::Dotted::Semantic->new( $self->zilla->version ); | |||||||||||||
| 145 | 4 | ▶ | return $v->is_trial ? "testing" : "stable"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 146 | }; | ||||||||||||||
| 147 | |||||||||||||||
| 148 | # -------------------------------------------------------------------------------------------------- | ||||||||||||||
| 149 | |||||||||||||||
| 150 | 3 | __PACKAGE__->meta->make_immutable(); | |||||||||||||
| 151 | |||||||||||||||
| 152 | 3 | 1; | |||||||||||||
| 153 | |||||||||||||||
| 154 | #pod =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 155 | #pod | ||||||||||||||
| 156 | #pod Copyright (C) 2015 Van de Bugger | ||||||||||||||
| 157 | #pod | ||||||||||||||
| 158 | #pod License GPLv3+: The GNU General Public License version 3 or later | ||||||||||||||
| 159 | #pod <http://www.gnu.org/licenses/gpl-3.0.txt>. | ||||||||||||||
| 160 | #pod | ||||||||||||||
| 161 | #pod This is free software: you are free to change and redistribute it. There is | ||||||||||||||
| 162 | #pod NO WARRANTY, to the extent permitted by law. | ||||||||||||||
| 163 | #pod | ||||||||||||||
| 164 | #pod | ||||||||||||||
| 165 | #pod =cut | ||||||||||||||
| 166 | |||||||||||||||
| 167 | # end of file # | ||||||||||||||
| 168 | |||||||||||||||
| 169 | __END__ | ||||||||||||||