| 1 | package Module::BumpVersion; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 0 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 7 | 0 | my ($class, $name) = @_; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 0 | my $lines; | |||||||||||||||||||||||||||
| 10 | 0 | ▶ | my $is_perl = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | return 1 if $name =~ m{ [.] (?i: pl | pm | t ) $ }x; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 12 | 0 | $lines = $class->read_file($name); | |||||||||||||||||||||||||||
| 13 | 0 | ▶ | return 1 if @$lines && $lines->[0] =~ m{ ^ \#\! .* perl }ix; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$lines and $lines->[0] =~ / ^ \#\! .* perl /xi
MC/DC0%0/2
@$lines and $lines->[0] =~ / ^ \#\! .* perl /xi
@$lines
$lines->[0] =~ / ^ \#\! .* perl /xi
Truth table0%0/3
A and B
A= @$linesB= $lines->[0] =~ / ^ \#\! .* perl /xi
| |||||||||||||||||||||||||||||
| 14 | 0 | return; | |||||||||||||||||||||||||||
| 15 | 0 | }->(); | |||||||||||||||||||||||||||
| 16 | 0 | ▶ | $lines ||= $class->read_file($name); | ||||||||||||||||||||||||||
|
Condition0%0/3
$lines ||= $class->read_file($name)
MC/DC0%0/2
$lines ||= $class->read_file($name)
$lines
$class->read_file($name)
Truth table0%0/3
A ||= B
A= $linesB= $class->read_file($name)
| |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | return unless $is_perl; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | return unless $lines; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | bless {lines => $lines, name => $name}, $class; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub read_file { | ||||||||||||||||||||||||||
|
Subroutine
read_file: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 0 | my ($class, $name) = @_; | |||||||||||||||||||||||||||
| 25 | 0 | ▶ | open my $fh, '<:raw', $name | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | or die "Cannot open '$name' for readding: $!"; | ||||||||||||||||||||||||||||
| 27 | 0 | my @ret = <$fh>; | |||||||||||||||||||||||||||
| 28 | 0 | close $fh; | |||||||||||||||||||||||||||
| 29 | 0 | return \@ret; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub set_version { | ||||||||||||||||||||||||||
|
Subroutine
set_version: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 0 | my ($self, $new_version) = @_; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | my $versions = $self->versions; | |||||||||||||||||||||||||||
| 36 | 0 | my @lines = @{$self->{lines}}; | |||||||||||||||||||||||||||
| 37 | 0 | my $dirty; | |||||||||||||||||||||||||||
| 38 | 0 | for my $edits ( values %$versions ) { | |||||||||||||||||||||||||||
| 39 | 0 | for my $edit (@$edits) { | |||||||||||||||||||||||||||
| 40 | $lines[ $edit->{line} ] = | ||||||||||||||||||||||||||||
| 41 | 0 | $edit->{pre} . $new_version . $edit->{post} . "\n"; | |||||||||||||||||||||||||||
| 42 | 0 | $dirty++; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | return unless $dirty; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | open my $fh, '>:raw', $self->{name} | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | or die "Cannot open '$self->{name}' for writing: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | print {$fh} $_ for @lines; | |||||||||||||||||||||||||||
| 50 | 0 | close $fh; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub find_version { | ||||||||||||||||||||||||||
|
Subroutine
find_version: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 55 | 0 | my ($version) = keys %{$self->versions}; | |||||||||||||||||||||||||||
| 56 | 0 | return $version; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub versions { | ||||||||||||||||||||||||||
|
Subroutine
versions: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | $self->{versions} ||= $self->_find_version_for_doc(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"versions"} ||= $self->_find_version_for_doc
MC/DC0%0/2
$self->{"versions"} ||= $self->_find_version_for_doc
$self->{"versions"}
$self->_find_version_for_doc
Truth table0%0/3
A ||= B
A= $self->{"versions"}B= $self->_find_version_for_doc
| |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub _find_version_for_doc { | ||||||||||||||||||||||||||
|
Subroutine
_find_version_for_doc: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 65 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | my $name = $self->{name}; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | my $machine = $self->scanner(); | |||||||||||||||||||||||||||
| 70 | 0 | my $state = $machine->{init}; | |||||||||||||||||||||||||||
| 71 | 0 | my $lines = $self->{lines}; | |||||||||||||||||||||||||||
| 72 | 0 | my $ver_found = {}; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | LINE: | ||||||||||||||||||||||||||||
| 75 | 0 | for my $ln ( 0 .. @$lines - 1 ) { | |||||||||||||||||||||||||||
| 76 | 0 | my $line = $lines->[$ln]; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | next LINE if $line =~ /# No BumpVersion/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # Bail out when we're in a state with no possible actions. | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | last LINE unless @$state; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | STATE: { | ||||||||||||||||||||||||||||
| 84 | 0 | for my $trans (@$state) { | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( my @match = $line =~ $trans->{re} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ( $trans->{mark} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | my $ver = $2 . $3 . $4; | |||||||||||||||||||||||||||
| 88 | 0 | push @{ $ver_found->{ $ver } }, | |||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||
| 90 | file => $name, | ||||||||||||||||||||||||||||
| 91 | info => $self, | ||||||||||||||||||||||||||||
| 92 | line => $ln, | ||||||||||||||||||||||||||||
| 93 | pre => $1, | ||||||||||||||||||||||||||||
| 94 | ver => $ver, | ||||||||||||||||||||||||||||
| 95 | post => $5 | ||||||||||||||||||||||||||||
| 96 | }; | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ( my $code = $trans->{exec} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | $code->( $machine, \@match, $line ); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ( my $goto = $trans->{goto} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | $state = $machine->{$goto}; | |||||||||||||||||||||||||||
| 105 | 0 | redo STATE; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 0 | return $ver_found; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub version_re_perl { | ||||||||||||||||||||||||||
|
Subroutine
version_re_perl: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | 0 | my $ver_re = shift; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | return qr{ ^ ( .*? [\$\*] (?: \w+ (?: :: | ' ) )* VERSION \s* = | |||||||||||||||||||||||||||
| 118 | \D*? ) | ||||||||||||||||||||||||||||
| 119 | $ver_re | ||||||||||||||||||||||||||||
| 120 | ( .* ) $ }x; | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub version_re_pod { | ||||||||||||||||||||||||||
|
Subroutine
version_re_pod: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 124 | 0 | my $ver_re = shift; | |||||||||||||||||||||||||||
| 125 | 0 | return qr{ ^ ( .*? (?i: version ) .*? ) $ver_re ( .* ) $ }x; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub version_re_package { | ||||||||||||||||||||||||||
|
Subroutine
version_re_package: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 129 | 0 | my $ver_re = shift; | |||||||||||||||||||||||||||
| 130 | 0 | return qr{ ^ ( package \s+ \S+ \s+ ) $ver_re (.*) $ }x; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | # State machine for Perl source | ||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub scanner{ | ||||||||||||||||||||||||||
|
Subroutine
scanner: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 135 | # Perl::Version::REGEX | ||||||||||||||||||||||||||||
| 136 | 0 | my $ver_re = qr/ ( (?i: Revision: \s+ ) | v | ) | |||||||||||||||||||||||||||
| 137 | ( \d+ (?: [.] \d+)* ) | ||||||||||||||||||||||||||||
| 138 | ( (?: _ \d+ )? ) /x; | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | { | ||||||||||||||||||||||||||||
| 141 | 0 | init => [ | |||||||||||||||||||||||||||
| 142 | { | ||||||||||||||||||||||||||||
| 143 | re => qr{ ^ = (?! cut ) }x, | ||||||||||||||||||||||||||||
| 144 | goto => 'pod', | ||||||||||||||||||||||||||||
| 145 | }, | ||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||
| 147 | re => version_re_perl($ver_re), | ||||||||||||||||||||||||||||
| 148 | mark => 1, | ||||||||||||||||||||||||||||
| 149 | }, | ||||||||||||||||||||||||||||
| 150 | { | ||||||||||||||||||||||||||||
| 151 | re => version_re_package($ver_re), | ||||||||||||||||||||||||||||
| 152 | mark => 1, | ||||||||||||||||||||||||||||
| 153 | }, | ||||||||||||||||||||||||||||
| 154 | ], | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | # pod within perl | ||||||||||||||||||||||||||||
| 157 | pod => [ | ||||||||||||||||||||||||||||
| 158 | { | ||||||||||||||||||||||||||||
| 159 | re => qr{ ^ =head\d\s+VERSION\b }x, | ||||||||||||||||||||||||||||
| 160 | goto => 'version', | ||||||||||||||||||||||||||||
| 161 | }, | ||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||
| 163 | re => qr{ ^ =cut }x, | ||||||||||||||||||||||||||||
| 164 | goto => 'init', | ||||||||||||||||||||||||||||
| 165 | }, | ||||||||||||||||||||||||||||
| 166 | ], | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | # version section within pod | ||||||||||||||||||||||||||||
| 169 | version => [ | ||||||||||||||||||||||||||||
| 170 | { | ||||||||||||||||||||||||||||
| 171 | re => qr{ ^ = (?! head\d\s+VERSION\b ) }x, | ||||||||||||||||||||||||||||
| 172 | goto => 'pod', | ||||||||||||||||||||||||||||
| 173 | }, | ||||||||||||||||||||||||||||
| 174 | { | ||||||||||||||||||||||||||||
| 175 | re => version_re_pod($ver_re), | ||||||||||||||||||||||||||||
| 176 | mark => 1, | ||||||||||||||||||||||||||||
| 177 | }, | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | ], | ||||||||||||||||||||||||||||
| 180 | }; | ||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 3 | 1; | |||||||||||||||||||||||||||