blib/lib/Dist/Zilla/Plugin/Version/FromSubversion.pm

filter: Statementstmt 31.3% 21 / 67 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 4 / 8 Podpod 0.0% 0 / 1 totaltotal 22.7% 25 / 110 CC 16 SCAR 48.7
CC
16
Cov
22%
provide_version
210.0
_extract_rev_keyword
12.0
__ANON__
2.0
CRAP 129.7
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Dist::Zilla::Plugin::Version::FromSubversion;
4 {
5 1 $Dist::Zilla::Plugin::Version::FromSubversion::VERSION = '1.000019';
6 }
7  
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 with (
10 'Dist::Zilla::Role::VersionProvider',
11 'Dist::Zilla::Role::TextTemplate',
12 );
13  
14 1 has major => (
15 is => 'ro',
16 isa => 'Int',
17 required => 1,
18 default => 1,
19 );
20  
21 1 has format => (
22 is => 'ro',
23 isa => 'Str',
24 required => 1,
25 default => q<{{ $major + int($revision / 1_000_000) }}>
26 . q<.{{ sprintf '%06u', $revision % 1_000_000 }}>
27 . q<{{$ENV{DEV} ? (sprintf '_%03u', $ENV{DEV}) : ''}}>
28 );
29  
30 1 has fallback_revision => (
31 is => 'ro',
32 isa => 'Str',
33 );
34  
35 has fallback_file => (
36 is => 'ro',
37 isa => 'ArrayRef',
38 0 ▶ default => sub { [ ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 1 );
40  
41 sub provide_version
42 0 ▶{
Subroutine provide_version: not called CC=14 SCAR=53.5
Pod undocumented
43 0 my $self = shift;
44  
45 0 my $rev;
46 0 my $root = $self->zilla->root;
47  
48 # Are we in a working copy?
49 0 ▶ if (-d $root->subdir('.svn')) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $root->subdir('.svn')) { } 0 0 0
50 0 require SVN::Client;
51 0 ▶ my $svn = SVN::Client->new or die "can't initialize SVN::Client";
Branch: 1 branch
BranchTrueFalseTotal
my $svn = "SVN::Client"->new or die "can't initialize SVN::Client" 0 0 0
52  
53 0 ▶ $svn->info("", undef, undef, sub { $rev = $_[1]->rev }, 0);
Subroutine __ANON__: not called CC=1 SCAR=6.9
54  
55 0 my $dist_ini = $root->file('dist.ini')->absolute->stringify;
56 0 ▶ if (-f $dist_ini && $self->fallback_revision) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $dist_ini and $self->fallback_revision) 0 0 0
Condition0%0/3
-f $dist_ini and $self->fallback_revision
!ll&&!rl&&r
000
MC/DC0%0/2
-f $dist_ini and $self->fallback_revision
-f $dist_ini $self->fallback_revision
Truth table0%0/3
A and B
A= -f $dist_iniB= $self->fallback_revision
ABresult
0X0
100
111
57 0 my $kwd = $svn->propget('svn:keywords', $dist_ini, undef, 0);
58 0 ▶ unless (exists $kwd->{$dist_ini}
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $kwd->{$dist_ini} and grep /^(?:Rev(?:ision)?|LastChangedRevision)$/, split(' ', $kwd->{$dist_ini}, 0)) 0 0 0
Condition0%0/3
exists $kwd->{$dist_ini} and grep /^(?:Rev(?:ision)?|LastChangedRevision)$/, split(' ', $kwd->{$dist_ini}, 0)
!ll&&!rl&&r
000
MC/DC0%0/2
exists $kwd->{$dist_ini} and grep /^(?:Rev(?:ision)?|LastChangedRevision)$/, split(' ', $kwd->{$dist_ini}, 0)
exists $kwd->{$dist_ini} grep /^(?:Rev(?:ision)?|LastChangedRevision)$/, split(' ', $kwd->{$dist_ini}, 0)
Truth table0%0/3
A and B
A= exists $kwd->{$dist_ini}B= grep /^(?:Rev(?:ision)?|LastChangedRevision)$/, split(' ', $kwd->{$dist_ini}, 0)
ABresult
0X0
100
111
59 && grep /^(?:Rev(?:ision)?|LastChangedRevision)$/, split ' ', $kwd->{$dist_ini}) {
60 0 $self->log("enable svn:keywords expansion on dist.ini to activate fallback_revision:\n svn propset svn:keywords \"Revision\" dist.ini");
61 }
62 }
63 0 ▶ if (@{ $self->fallback_file }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->fallback_file;}) 0 0 0
64 0 foreach my $file (@{ $self->fallback_revision }) {
65 0 my $path = $root->file($file)->absolute->stringify;
66 0 my $kwd = $svn->propget('svn:keywords', $path, undef, 0);
67 0 ▶ unless (exists $kwd->{$path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $kwd->{$path}) { } 0 0 0
68 # TODO fix path to use platform path separators
69 0 $self->log_fatal(
70 "enable svn:keywords expansion on $file to activate fallback_file:\n"
71 ." svn propset svn:keywords \"Revision\" $file");
72 } else {
73 0 my @kwd_rev = grep /^(?:Rev(?:ision)?|LastChangedRevision)$/, split ' ', $kwd->{$path};
74 0 ▶ unless (@kwd_rev) {
Branch: 1 branch
BranchTrueFalseTotal
if (@kwd_rev) { } 0 0 0
75 0 $self->log_fatal(
76 "enable svn:keywords expansion on $file to activate fallback_file:\n"
77 ." svn propset svn:keywords \"$kwd->{$path} Revision\" $file");
78 } else {
79 0 my ($kwd) = $self->_extract_rev_keyword($path, @kwd_rev);
80 0 ▶ unless (defined $kwd) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $kwd) 0 0 0
81 0 $self->log_fatal(
82 "keyword $kwd_rev[0] is missing in $path"
83 );
84 }
85 }
86 }
87 }
88 }
89 } else {
90 0 my $fb = $self->fallback_revision;
91 0 ▶ unless ($fb) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fb) 0 0 0
92 0 $self->log_fatal("not in a Subversion working copy. Use the fallback_revision option in dist.ini or switch to [AutoVersion]");
93 }
94 0 ▶ unless ($fb =~ /\$(?:Rev(?:ision)?|LastChangedRevision): ([0-9]+)\S*\s*\$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fb =~ /\$(?:Rev(?:ision)?|LastChangedRevision): ([0-9]+)\S*\s*\$/) 0 0 0
95 0 $self->log_fatal('invalid fallback_revision value: use $Revision: $');
96 }
97 0 $rev = $1;
98 }
99  
100  
101 0 my $version = $self->fill_in_string(
102 $self->format,
103 {
104 major => \( $self->major ),
105 revision => $rev,
106 },
107 );
108  
109 0 $self->log([ 'providing version %s', $version ]);
110  
111 0 return $version;
112 }
113  
114  
115 sub _extract_rev_keyword
116 0 ▶{
Subroutine _extract_rev_keyword: not called CC=3 SCAR=24.8
117 0 my $self = shift;
118 0 my $file = shift;
119 0 ▶ my $kwd_rev_re =
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
120 @_
121 ? ('\$'.join('|', @_).'::?\s*(\S+)\s*\$')
122 : qr/\$(Rev(?:ision)?|LastChangedRevision)::?\s*([0-9]+[A-Z])?\s*\$/;
123 0 my $content = do {
124 0 ▶ open my $f, '<:bytes', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $f, "<:bytes", $file or $self->log_fatal("can't open ${file}: $!") 0 0 0
125 or $self->log_fatal("can't open $file: $!");
126 0 local $/;
127 <$f>
128 0 };
129 0 my ($keyword, $rev) = $content =~ /$kwd_rev_re/;
130 0 ($keyword, $rev)
131 }
132  
133  
134 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
135 1 __PACKAGE__->meta->make_immutable;
136 1 1;
137 __END__
↑ Summary