| 1 | package ShipIt::Step::ChangeAllVersions; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.008_001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | our $VERSION = '1.002'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use parent qw(ShipIt::Step); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Fatal qw(open close rename opendir closedir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use File::Find qw(find); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use File::stat (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | my $looks_like_perl = qr/\. p(?: [ml]c? | od | erl ) \z/xms; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | sub collect_files { | ||||||||||||||||||||||||||
|
Subroutine
collect_files: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 3 | my @files; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # from subdir | ||||||||||||||||||||||||||||
| 20 | 14 | ▶ | find sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 21 | 14 | ▶ | return if not ( -f $_ && not -l $_ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-f $_ and not -l $_
MC/DC50%1/2
-f $_ and not -l $_
-f $_
not -l $_
Truth table66%2/3
A and not(B)
A= -f $_B= not -l $_
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 7 | ▶ | if($_ =~ $looks_like_perl) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 3 | push @files, $File::Find::name; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | else { | ||||||||||||||||||||||||||||
| 27 | 4 | open my $in, '<', $_; | |||||||||||||||||||||||||||
| 28 | 4 | read $in, my($buff), 2; # I don't care whether it fail or not | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 4 | ▶ | if($buff && $buff eq '#!'){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$buff and $buff eq "#!"
MC/DC50%1/2
$buff and $buff eq "#!"
$buff
$buff eq "#!"
Truth table66%2/3
A and B
A= $buffB= $buff eq "#!"
| |||||||||||||||||||||||||||||
| 31 | 2 | push @files, $File::Find::name; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 4 | close $in; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 3 | }, grep{ -d } qw(lib script bin); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # from toplevel | ||||||||||||||||||||||||||||
| 38 | 3 | opendir my $dirh, '.'; | |||||||||||||||||||||||||||
| 39 | 3 | push @files, grep { ! -l $_ } grep{ $_ =~ $looks_like_perl } readdir($dirh); | |||||||||||||||||||||||||||
| 40 | 3 | closedir $dirh; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 3 | return @files; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=11 SCAR=24.2
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 2 | my ($self, $state) = @_; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | my $dry_run = $state->dry_run; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | ▶ | if($dry_run){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | $self->log("*** DRY RUN, not actually updating versions."); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | my $current_version = quotemeta $state->pt->{version}; | |||||||||||||||||||||||||||
| 55 | 2 | my $new_version = $state->version; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | foreach my $module ($self->collect_files) { | |||||||||||||||||||||||||||
| 58 | 8 | open my $in, '<', $module; | |||||||||||||||||||||||||||
| 59 | 8 | binmode $in; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 8 | my $out; | |||||||||||||||||||||||||||
| 62 | 8 | ▶ | if(!$dry_run){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 8 | open $out, '>', "$module.tmp"; | |||||||||||||||||||||||||||
| 64 | 8 | binmode $out; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 8 | my $need_replace = 0; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 8 | ▶ | while (<$in>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # update $VERSION variable | ||||||||||||||||||||||||||||
| 72 | 90 | ▶ | if (s/(\$VERSION .+) \b $current_version \b/$1$new_version/xms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 6 | $self->{changed_version_variable}{$module}++; | |||||||||||||||||||||||||||
| 74 | 6 | $self->log("Update \$VERSION in $module."); | |||||||||||||||||||||||||||
| 75 | 6 | $need_replace++; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # update the VERSION section which says, | ||||||||||||||||||||||||||||
| 79 | # "This is Foo version $ver.", | ||||||||||||||||||||||||||||
| 80 | # or "This document descrives Foo version $ver." | ||||||||||||||||||||||||||||
| 81 | 90 | ▶ | if (/\A =head1 \s+ VERSION\b/xms ... /\A =\w+/xms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 30 | ▶ | if (s/(version \b .+) $current_version/$1$new_version/xms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 6 | $self->{changed_version_section}{$module}++; | |||||||||||||||||||||||||||
| 84 | 6 | $self->log("Update the VERSION section in $module."); | |||||||||||||||||||||||||||
| 85 | 6 | $need_replace++; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 90 | ▶ | print $out $_ if defined $out; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 8 | close $in; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 8 | ▶ | next if $dry_run; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 8 | close $out; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 8 | ▶ | if($need_replace) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 8 | my $mode = File::stat::stat($module)->mode; | |||||||||||||||||||||||||||
| 100 | 8 | rename $module => "$module~"; | |||||||||||||||||||||||||||
| 101 | 8 | rename "$module.tmp" => $module; | |||||||||||||||||||||||||||
| 102 | 8 | chmod $mode, $module; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 8 | unlink "$module~"; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | else{ | ||||||||||||||||||||||||||||
| 107 | 0 | unlink "$module.tmp"; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 2 | return 1; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 6 | ▶ | sub changed_version_variable { # for testing | ||||||||||||||||||||||||||
|
Subroutine
changed_version_variable: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | 6 | return $_[0]->{changed_version_variable}; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 6 | ▶ | sub changed_version_section { # for testing | ||||||||||||||||||||||||||
|
Subroutine
changed_version_section: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 6 | return $_[0]->{changed_version_section}; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 12 | ▶ | sub log { | ||||||||||||||||||||||||||
|
Subroutine
log: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 123 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 124 | 12 | print @_, "\n"; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 3 | 1; | |||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||