ShipIt/ProjectType/Perl.pm

filter: Statementstmt 66.6% 88 / 132 Branchbran 26.0% 13 / 50 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.1% 23 / 27 Podpod 16.6% 1 / 6 totaltotal 58.1% 125 / 215 CC 26 SCAR 25.3
CC
26
Cov
55%
current_version_from_makefilepl
42.0
current_version_from_buildpl
42.0
current_version
12.0
CRAP 12.5
« ShipIt/VC/Git.pm ↑ Summary ShipIt/Step/ChangeRPMVersion.pm »
1 package ShipIt::ProjectType::Perl;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use base 'ShipIt::ProjectType';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use ShipIt::Util qw(slurp write_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use ShipIt::ProjectType::Perl::MakeMaker;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use ShipIt::ProjectType::Perl::ModuleBuild;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # factory when called directly.
10 # returns undef if not a perl project, otherwise returns
11 # ::MakeMaker or ::ModuleBuild instance.
12 4 ▶sub new {
Subroutine new: called CC=4 SCAR=14.5
Pod undocumented
13 4 my ($class) = @_;
14 4 ▶ if ($class eq "ShipIt::ProjectType::Perl") {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "ShipIt::ProjectType::Perl") 2 2 4
15 2 ▶ return ShipIt::ProjectType::Perl::ModuleBuild->new if -e "Build.PL";
Branch: 1 branch
BranchTrueFalseTotal
if -e "Build.PL" 0 2 2
16 2 ▶ return ShipIt::ProjectType::Perl::MakeMaker->new if -e "Makefile.PL";
Branch: 1 branch
BranchTrueFalseTotal
if -e "Makefile.PL" 2 0 2
17 0 return undef;
18 }
19 2 return bless {}, $class;
20 }
21  
22 # fields:
23 # version -- if defined, cached current version
24 # ver_from -- if Makefile.PL says so, what file our $VERSION comes from
25  
26 0 ▶sub current_version {
Subroutine current_version: not called CC=3 SCAR=24.8
Pod undocumented
27 0 my $self = shift;
28 0 ▶ return $self->{version} if defined $self->{version};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"version"} 0 0 0
29  
30 0 ▶ if (-e "Build.PL") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e 'Build.PL') { } 0 0 0
31 0 return $self->{version} = $self->current_version_from_buildpl;
32 } else {
33 0 return $self->{version} = $self->current_version_from_makefilepl;
34 }
35 }
36  
37 0 ▶sub current_version_from_makefilepl {
Subroutine current_version_from_makefilepl: not called CC=6 SCAR=37.4
Pod undocumented
38 0 my $self = shift;
39 0 ▶ open (my $fh, "Makefile.PL") or die "Can't open Makefile.PL: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "Makefile.PL" or die "Can't open Makefile.PL: $!\n" 0 0 0
40 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
41 # MakeMaker
42 0 ▶ if (/VERSION_FROM.+([\'\"])(.+?)\1/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/VERSION_FROM.+([\'\"])(.+?)\1/) 0 0 0
43 0 $self->{ver_from} = $2;
44 0 last;
45 }
46 # Module::Install
47 0 ▶ if (/(?:(?:all|version)_from|reference_module)(?:\s*\(|\s+)([\'\"])(.+?)\1/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(?:(?:all|version)_from|reference_module)(?:\s*\(|\s+)([\'\"])(.+?)\1/) 0 0 0
48 0 $self->{ver_from} = $2;
49 0 last;
50 }
51 0 ▶ if (/\bVERSION\b.+([\'\"])(.+?)\1/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\bVERSION\b.+([\'\"])(.+?)\1/) 0 0 0
52 0 return $2;
53 }
54 }
55 0 close($fh);
56 0 return $self->version_from_file;
57 }
58  
59 0 ▶sub current_version_from_buildpl {
Subroutine current_version_from_buildpl: not called CC=6 SCAR=37.4
Pod undocumented
60 0 my $self = shift;
61 0 ▶ open (my $fh, "Build.PL") or die "Can't open Build.PL: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "Build.PL" or die "Can't open Build.PL: $!\n" 0 0 0
62 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
63 0 ▶ if (/\bdist_version_from\b.+([\'\"])(.+?)\1/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\bdist_version_from\b.+([\'\"])(.+?)\1/) 0 0 0
64 0 $self->{ver_from} = $2;
65 0 last;
66 }
67 0 ▶ if (/\bmodule_name\b.+([\'\"])(.+?)\1/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\bmodule_name\b.+([\'\"])(.+?)\1/) 0 0 0
68 0 $self->{ver_from} = $self->_module_to_file($2);
69 # no last since we prefer dist_version_from
70 }
71 0 ▶ if (/\bdist_version\b.+([\'\"])(.+?)\1/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\bdist_version\b.+([\'\"])(.+?)\1/) 0 0 0
72 0 return $2;
73 }
74 }
75 0 close($fh);
76 0 return $self->version_from_file;
77 }
78  
79 0 ▶sub _module_to_file {
Subroutine _module_to_file: not called CC=2 SCAR=17.9
80 0 my ($self, $mod) = @_;
81  
82 0 my @parts = split /::/, $mod;
83 0 $parts[-1] .= q{.pm};
84  
85 0 ▶ unshift @parts, 'lib' if -d 'lib';
Branch: 1 branch
BranchTrueFalseTotal
if -d "lib" 0 0 0
86  
87 0 return File::Spec->catfile(@parts);
88 }
89  
90 114 ▶sub _versioncode_from_string {
Subroutine _versioncode_from_string: called CC=2 SCAR=6.9
91 114 my ($self, $string) = @_;
92  
93 114 ▶ if ($string =~ /
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ / ( ( use \s* version \s* ; \s* )? (our)? \s* \$VER SION \s* = \s* # trick PAUSE from parsing this line ( ['"] v?[\d\.\_]+ ['"] | q{1,2}\( \s* v?[\d\.\_]+ \s* \) | [\d\.\_]+ | qv\( \s* ['"] v? [\d\.\_]+ ['"] \s* \) ) ) /msx) 39 75 114
94 (
95 ( use \s* version \s* ; \s* )?
96 (our)? \s* \$VER SION \s* = \s* # trick PAUSE from parsing this line
97 (
98 ['"] v?[\d\.\_]+ ['"]
99 | q{1,2}\( \s* v?[\d\.\_]+ \s* \)
100 | [\d\.\_]+
101 | qv\( \s* ['"] v? [\d\.\_]+ ['"] \s* \)
102 )
103 )
104 /xms) {
105 39 return $1;
106 }
107  
108 75 return 0;
109 }
110  
111 # returns $VERSION from a file, assuming $self->{ver_from} is already set
112 21 ▶sub version_from_file {
Subroutine version_from_file: called CC=6 SCAR=18.0
Pod undocumented
113 21 my $self = shift;
114 21 ▶ my $file = $self->{ver_from} or die "no ver_from set";
Branch: 1 branch
BranchTrueFalseTotal
my $file = $self->{"ver_from"} or die "no ver_from set" 21 0 21
115 21 ▶ open (my $fh, $file) or die "Failed to open $file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $file or die "Failed to open ${file}: $!\n" 21 0 21
116 21 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 93 0 93
117 93 ▶ if (my $versionpart = $self->_versioncode_from_string($line)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $versionpart = $self->_versioncode_from_string($line)) 21 72 93
118 21 eval {
119 package __ShipIt_Temp_Package;
120 2 ▶ use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
121 1 ▶ eval $versionpart;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
122 };
123 21 ▶ next if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 21 21
124 21 return $__ShipIt_Temp_Package::VERSION;
125 }
126 }
127 0 die "No \$VERSION found in file $file\nMaybe, you forgot to quote \$VERSION?";
128 }
129  
130 7 ▶sub update_version {
Subroutine update_version: called CC=4 SCAR=17.5
Pod documented
131 7 my ($self, $newver) = @_;
132  
133 7 ▶ if (my $file = $self->{ver_from}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = $self->{"ver_from"}) 7 0 7
134 7 my $contents = slurp($file);
135  
136 7 my $versionpart = $self->_versioncode_from_string($contents);
137 7 my $newversionpart = $versionpart;
138 7 my $version_withoutv = $self->{version};
139 7 $version_withoutv =~ s/^v//;
140 7 $newversionpart =~ s/ v? $version_withoutv /$newver/xms;
141  
142 7 my ($x, $y) = (quotemeta($versionpart), $newversionpart);
143 7 $contents =~ s/$x/$y/;
144 7 write_file($file, $contents);
145  
146 7 return 1;
147 }
148  
149 0 ▶ if (-e "Makefile.PL") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "Makefile.PL") 0 0 0
150 0 my $file = "Makefile.PL";
151 0 my $contents = slurp($file);
152 0 ▶ $contents =~ s/(\bVERSION\b.+)([\'\"])(.+?)\2/$1$2$newver$2/
Branch: 1 branch
BranchTrueFalseTotal
$contents =~ s/(\bVERSION\b.+)([\'\"])(.+?)\2/$1$2$newver$2/ or die "Failed to replace VERSION in MakeFile.PL\n" 0 0 0
153 or die "Failed to replace VERSION in MakeFile.PL\n";
154 0 write_file($file, $contents);
155 0 return 1;
156  
157 }
158  
159 0 die "perl update not done";
160 }
161  
162 2 1;
« ShipIt/VC/Git.pm ↑ Summary ShipIt/Step/ChangeRPMVersion.pm »