blib/lib/Shipwright/Backend/Base.pm

filter: Statementstmt 33.2% 140 / 421 Branchbran 18.9% 25 / 132 Conditioncond 6.9% 4 / 58 MC/DCmcdc 3.1% 1 / 32 Subroutinesub 50.0% 26 / 52 Podpod 100% 30 / 30 totaltotal 31.1% 226 / 725 CC 119 SCAR 53.5
CC
119
Cov
28%
import
977.9
trim
156.0
_fill_deps
72.0
CRAP 210.0
« blib/lib/auto/share/dist/Shipwright/bin/shipwright-builder ↑ Summary blib/lib/Shipwright/Backend/SVK.pm »
1 package Shipwright::Backend::Base;
2  
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use File::Spec::Functions qw/catfile catdir splitpath/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Shipwright::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use File::Temp qw/tempdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use File::Copy 'copy';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use File::Copy::Recursive qw/rcopy/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use File::Path qw/make_path remove_tree/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use List::MoreUtils qw/uniq firstidx/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Module::Info;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 our %REQUIRE_OPTIONS = ( import => [qw/source/] );
15  
16 5 ▶use base qw/Shipwright::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 __PACKAGE__->mk_accessors(qw/repository log/);
18  
19 =head1 NAME
20  
21 Shipwright::Backend::Base - Base Backend Class
22  
23 =head1 DESCRIPTION
24  
25 Base Backend Class
26  
27 =head1 METHODS
28  
29 =over
30  
31 =item new
32  
33 the constructor
34  
35 =cut
36  
37 12 ▶sub new {
Subroutine new: called CC=2 SCAR=7.6
Pod documented
38 12 my $proto = shift;
39 12 ▶ my $self = bless {@_}, ref $proto || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0120
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
40 12 return $self->build(@_);
41 }
42  
43 =item build
44  
45 =cut
46  
47 12 ▶sub build {
Subroutine build: called CC=1 SCAR=0.0
Pod documented
48 12 my $self = shift;
49 12 $self->log( Log::Log4perl->get_logger( ref $self ) );
50 12 return $self;
51 }
52  
53 0 ▶sub _subclass_method {
Subroutine _subclass_method: not called CC=1 SCAR=6.9
54 0 my $method = ( caller(0) )[3];
55 0 confess_or_die "your should subclass $method\n";
56 }
57  
58 =item initialize
59  
60 initialize a project
61 you should subclass this method, and call this to get the dir with content initialized
62  
63 =cut
64  
65 2 ▶sub initialize {
Subroutine initialize: called CC=4 SCAR=13.9
Pod documented
66 2 my $self = shift;
67 2 my $dir =
68 tempdir( 'shipwright_backend_base_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
69  
70 2 ▶ rcopy( share_root(), $dir )
Branch: 1 branch
BranchTrueFalseTotal
rcopy(share_root(), $dir) or confess_or_die("copy share_root failed: $!") 2 0 2
71 or confess_or_die "copy share_root failed: $!";
72  
73 2 $self->_install_yaml_tiny($dir);
74 2 $self->_install_clean_inc($dir);
75 2 $self->_install_module_build($dir);
76 2 $self->_install_file_compare($dir);
77 2 $self->_install_file_copy_recursive($dir);
78 2 $self->_install_file_path($dir);
79  
80 # set proper permissions for yml under /shipwright/
81 2 my $sw_dir = catdir( $dir, 'shipwright' );
82 2 my $sw_dh;
83 2 ▶ opendir $sw_dh, $sw_dir or die "can't opendir $sw_dir: $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir $sw_dh, $sw_dir or die "can't opendir ${sw_dir}: $!" 2 0 2
84 2 for my $yml ( grep { /.yml$/ } readdir $sw_dh ) {
85 16 chmod 0644, catfile( $dir, 'shipwright', $yml ); ## no critic
86 }
87 2 closedir $sw_dh;
88  
89 2 chmod 0644, catfile( $dir, 't', 'test' );
90  
91 2 return $dir;
92 }
93  
94 2 ▶sub _install_module_build {
Subroutine _install_module_build: called CC=13 SCAR=27.7
95 2 my $self = shift;
96 2 my $dir = shift;
97 2 my $module_build_path = catdir( $dir, 'inc', 'Module', );
98 2 make_path( catdir( $module_build_path, 'Build' ) );
99 2 ▶ copy( Module::Info->new_from_module('Module::Build')->file,
Branch: 1 branch
BranchTrueFalseTotal
copy("Module::Info"->new_from_module("Module::Build")->file, $module_build_path) or confess_or_die("copy Module/Build.pm failed: $!") 2 0 2
100 $module_build_path ) or confess_or_die "copy Module/Build.pm failed: $!";
101 2 ▶ rcopy(
Branch: 1 branch
BranchTrueFalseTotal
rcopy(catdir("Module::Info"->new_from_module("Module::Build")->inc_dir, "Module", "Build"), catdir($module_build_path, "Build")) or confess_or_die("copy Module/Build failed: $!") 2 0 2
102 catdir(
103 Module::Info->new_from_module('Module::Build')->inc_dir, 'Module',
104 'Build'
105 ),
106 catdir( $module_build_path, 'Build' )
107 )
108 or confess_or_die "copy Module/Build failed: $!";
109  
110 # Module::Build needs Module::Metadata, Perl::OSType
111 2 ▶ if ( Module::Info->new_from_module('Perl::OSType') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Module::Info"->new_from_module("Perl::OSType")) 2 0 2
112 2 make_path( catdir( $dir, 'inc', 'Perl' ) );
113 2 ▶ copy( Module::Info->new_from_module('Perl::OSType')->file,
Branch: 1 branch
BranchTrueFalseTotal
copy("Module::Info"->new_from_module("Perl::OSType")->file, catdir($dir, "inc", "Perl")) or confess_or_die("copy Perl/OSType.pm failed: $!") 2 0 2
114 catdir( $dir, 'inc', 'Perl' ) )
115 or confess_or_die "copy Perl/OSType.pm failed: $!";
116 }
117  
118 # Module::Metadata 1.02 requires version 0.87+, which isn't in perl core yet
119 # we can't simply copy version.pm to inc because it's not plain perl.
120 # so here we do a maybe dangerous thing, hack Module::Metadata to not require
121 # version 0.87+
122 # so is Module::Build
123 2 my @files;
124 2 ▶ if ( -e catfile( $dir, 'inc', 'Module', 'Build', 'Version.pm' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e catfile($dir, "inc", "Module", "Build", "Version.pm")) 0 2 2
125 0 push @files, catfile( $dir, 'inc', 'Module', 'Build', 'Version.pm' );
126 }
127  
128 2 ▶ if ( Module::Info->new_from_module('Module::Metadata') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Module::Info"->new_from_module("Module::Metadata")) 2 0 2
129 2 ▶ copy( Module::Info->new_from_module('Module::Metadata')->file,
Branch: 1 branch
BranchTrueFalseTotal
copy("Module::Info"->new_from_module("Module::Metadata")->file, catdir($dir, "inc", "Module")) or confess_or_die("copy Module/Metadata.pm failed: $!") 2 0 2
130 catdir( $dir, 'inc', 'Module' ) )
131 or confess_or_die "copy Module/Metadata.pm failed: $!";
132 2 push @files, catfile( $dir, 'inc', 'Module', 'Metadata.pm' );
133 }
134  
135 2 for my $file ( @files ) {
136 2 ▶ open my $fh, '<', $file or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die $! 2 0 2
137 2 local $/;
138 2 my $content = <$fh>;
139 2 ▶ if ( $content =~ s!use version[^'"]+?(['"]?\s*;)!use version $1;! ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ s/use version[^'"]+?(['"]?\s*;)/use version $1;/) 2 0 2
140 2 ▶ chmod 0755, $file unless -w $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -w $file 0 2 2
141 2 ▶ open $fh, '>', $file or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $file or die $! 2 0 2
142 2 print $fh $content;
143 2 close $fh;
144 }
145 }
146 }
147  
148 2 ▶sub _install_yaml_tiny {
Subroutine _install_yaml_tiny: called CC=2 SCAR=7.0
149 2 my $self = shift;
150 2 my $dir = shift;
151  
152 2 my $yaml_tiny_path = catdir( $dir, 'inc', 'YAML' );
153 2 make_path( $yaml_tiny_path );
154 2 ▶ rcopy( Module::Info->new_from_module('YAML::Tiny')->file, $yaml_tiny_path )
Branch: 1 branch
BranchTrueFalseTotal
rcopy("Module::Info"->new_from_module("YAML::Tiny")->file, $yaml_tiny_path) or confess_or_die("copy YAML/Tiny.pm failed: $!") 2 0 2
155 or confess_or_die "copy YAML/Tiny.pm failed: $!";
156 }
157  
158 2 ▶sub _install_clean_inc {
Subroutine _install_clean_inc: called CC=3 SCAR=11.0
159 2 my $self = shift;
160 2 my $dir = shift;
161 2 my $util_inc_path = catdir( $dir, 'inc', 'Shipwright', 'Util' );
162 2 make_path( $util_inc_path );
163 2 for my $mod ( qw/CleanINC PatchModuleBuild/ ) {
164 4 ▶ rcopy( Module::Info->new_from_module("Shipwright::Util::$mod")->file,
Branch: 1 branch
BranchTrueFalseTotal
rcopy("Module::Info"->new_from_module("Shipwright::Util::$mod")->file, $util_inc_path) or confess_or_die("copy $mod failed: $!") 4 0 4
165 $util_inc_path )
166 or confess_or_die "copy $mod failed: $!";
167 }
168 }
169  
170 2 ▶sub _install_file_compare {
Subroutine _install_file_compare: called CC=2 SCAR=7.0
171 2 my $self = shift;
172 2 my $dir = shift;
173  
174 2 my $path = catdir( $dir, 'inc', 'File' );
175 2 make_path( $path );
176 2 ▶ rcopy( Module::Info->new_from_module('File::Compare')->file, $path )
Branch: 1 branch
BranchTrueFalseTotal
rcopy("Module::Info"->new_from_module("File::Compare")->file, $path) or confess_or_die("copy File/Compare.pm failed: $!") 2 0 2
177 or confess_or_die "copy File/Compare.pm failed: $!";
178 }
179  
180 2 ▶sub _install_file_copy_recursive {
Subroutine _install_file_copy_recursive: called CC=2 SCAR=7.0
181 2 my $self = shift;
182 2 my $dir = shift;
183  
184 2 my $path = catdir( $dir, 'inc', 'File', 'Copy' );
185 2 make_path( $path );
186 2 ▶ rcopy( Module::Info->new_from_module('File::Copy::Recursive')->file, $path )
Branch: 1 branch
BranchTrueFalseTotal
rcopy("Module::Info"->new_from_module("File::Copy::Recursive")->file, $path) or confess_or_die("copy File/Copy/Recursive.pm failed: $!") 2 0 2
187 or confess_or_die "copy File/Copy/Recursive.pm failed: $!";
188 }
189  
190 2 ▶sub _install_file_path {
Subroutine _install_file_path: called CC=2 SCAR=7.0
191 2 my $self = shift;
192 2 my $dir = shift;
193  
194 2 my $path = catdir( $dir, 'inc', 'File' );
195 2 ▶ rcopy( Module::Info->new_from_module('File::Path')->file, $path )
Branch: 1 branch
BranchTrueFalseTotal
rcopy("Module::Info"->new_from_module("File::Path")->file, $path) or confess_or_die("copy File/Path.pm failed: $!") 2 0 2
196 or confess_or_die "copy File/Path.pm failed: $!";
197 }
198  
199 =item import
200  
201 import a dist.
202  
203 =cut
204  
205 2 ▶sub import {
Subroutine import: called CC=32 SCAR=68.9
206 2 my $self = shift;
207 2 ▶ return unless ref $self; # get rid of class->import
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 2 0 2
208 0 my %args = @_;
209 0 my $name = ( splitpath( $args{source} ) )[-1];
210  
211 0 ▶ if ( $self->has_branch_support ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_branch_support) 0 0 0
212 0 ▶ if ( $args{branches} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'branches'}) { } 0 0 0
213 0 $args{as} = '';
214 }
215 else {
216 0 ▶ $args{as} ||= 'vendor';
Condition0%0/2
$args{"as"} ||= "vendor"
l!l
00
MC/DC0%0/1
$args{"as"} ||= "vendor"
$args{"as"}
Truth table0%0/2
A
A= $args{"as"}
Aresult
11
00
217 }
218 }
219  
220 0 ▶ unless ( $args{_initialize} || $args{_extra_tests} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'_initialize'} or $args{'_extra_tests'}) { } 0 0 0
Condition0%0/3
$args{"_initialize"} or $args{"_extra_tests"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"_initialize"} or $args{"_extra_tests"}
$args{"_initialize"} $args{"_extra_tests"}
Truth table0%0/3
A or B
A= $args{"_initialize"}B= $args{"_extra_tests"}
ABresult
1X1
011
000
221 0 ▶ if ( $args{_extra_tests} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'_extra_tests'}) { } 0 0 0
elsif ($args{'build_script'}) { } 0 0 0
222 0 ▶ $self->delete( path => "/t/extra" ) if $args{delete};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"delete"} 0 0 0
223  
224 0 $self->log->info( "importing extra tests to " . $self->repository );
225 0 for my $cmd ( $self->_cmd( import => %args, name => $name ) ) {
226 0 run_cmd($cmd);
227 }
228 }
229 elsif ( $args{build_script} ) {
230 0 ▶ if ( $self->info( path => "/scripts/$name" )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->info('path', "/scripts/$name") and not $args{'overwrite'}) { } 0 0 0
Condition0%0/3
$self->info("path", "/scripts/$name") and not $args{"overwrite"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->info("path", "/scripts/$name") and not $args{"overwrite"}
$self->info("path", "/scripts/$name") not $args{"overwrite"}
Truth table0%0/3
A and not(B)
A= $self->info("path", "/scripts/$name")B= not $args{"overwrite"}
ABresult
0X0
100
111
231 && not $args{overwrite} )
232 {
233 0 $self->log->warn("/scripts/$name exists already");
234 }
235 else {
236 0 ▶ $self->delete( path => "/scripts/$name" ) if $args{delete};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"delete"} 0 0 0
237  
238 0 $self->log->info( "importing $args{source}'s scripts to "
239 . $self->repository );
240 0 for my $cmd ( $self->_cmd( import => %args, name => $name ) ) {
241 0 run_cmd($cmd);
242 }
243 0 $self->update_refs;
244  
245 }
246 }
247 else {
248 0 ▶ if ( $self->has_branch_support ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_branch_support) { } 0 0 0
249 0 ▶ if ( $self->info( path => "/sources/$name/$args{as}" )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->info('path', "/sources/$name/$args{'as'}") and not $args{'overwrite'}) { } 0 0 0
Condition0%0/3
$self->info("path", qq[/sources/$name/$args{"as"}]) and not $args{"overwrite"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->info("path", qq[/sources/$name/$args{"as"}]) and not $args{"overwrite"}
$self->info("path", qq[/sources/$name/$args{"as"}]) not $args{"overwrite"}
Truth table0%0/3
A and not(B)
A= $self->info("path", qq[/sources/$name/$args{"as"}])B= not $args{"overwrite"}
ABresult
0X0
100
111
250 && not $args{overwrite} )
251 {
252 0 $self->log->warn( "sources/$name/$args{as} exists already" );
253 }
254 else {
255 $self->delete( path => "/sources/$name/$args{as}" )
256 0 ▶ if $args{delete};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"delete"} 0 0 0
257 0 $self->log->info(
258 "importing $args{source} to " . $self->repository );
259 0 $self->_add_to_order($name);
260  
261 0 my $version = $self->version;
262 0 ▶ if ( $args{as} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'as'}) { } 0 0 0
263 0 $version->{$name}{$args{as}} = $args{version};
264 }
265 else {
266 0 $version->{$name} = $args{version};
267 }
268 0 $self->version($version);
269  
270 0 my $branches = $self->branches;
271 0 ▶ if ( $args{branches} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'branches'}) { } 0 0 0
elsif (not $name =~ /^cpan-/ || $branches->{$name} && grep({$args{'as'} eq $_;} @{$$branches{$name};})) { } 0 0 0
272  
273 # mostly this happens when import from another shipwright repo
274 0 ▶ if ( @{ $args{branches} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$args{"branches"};}) 0 0 0
275 0 $branches->{$name} = $args{branches};
276 0 $self->branches($branches);
277 }
278 }
279 ▶ elsif (
Condition0%0/6
$name =~ /^cpan-/ || $branches->{$name} && grep({$args{'as'} eq $_;} @{$$branches{$name};})
l!l&&r!l&&!r
000
$branches->{$name} and grep {$args{"as"} eq $_;} @{$$branches{$name};}
!ll&&!rl&&r
000
MC/DC0%0/3
$name =~ /^cpan-/ || $branches->{$name} && grep({$args{'as'} eq $_;} @{$$branches{$name};})
$name =~ /^cpan-/ $branches->{$name} grep {$args{"as"} eq $_;} @{$$branches{$name};}
Truth table0%0/4
A || B and C
A= $name =~ /^cpan-/B= $branches->{$name}C= grep {$args{"as"} eq $_;} @{$$branches{$name};}
ABCresult
1XX1
0111
00X0
0100
280 $name !~ /^cpan-/ &&
281 !(
282 0 $branches->{$name} && grep { $args{as} eq $_ }
283 0 @{ $branches->{$name} }
284 )
285 )
286 {
287 $branches->{$name} =
288 0 ▶ [ @{ $branches->{$name} || [] }, $args{as} ];
Condition0%0/2
$branches->{$name} || []
l!l
00
MC/DC0%0/1
$branches->{$name} || []
$branches->{$name}
Truth table0%0/2
A
A= $branches->{$name}
Aresult
11
00
289 0 $self->branches($branches);
290 }
291  
292 0 for
293 my $cmd ( $self->_cmd( import => %args, name => $name ) )
294 {
295 0 run_cmd($cmd);
296 }
297 }
298 }
299 else {
300 0 ▶ if ( $self->info( path => "/dists/$name" )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->info('path', "/dists/$name") and not $args{'overwrite'}) { } 0 0 0
Condition0%0/3
$self->info("path", "/dists/$name") and not $args{"overwrite"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->info("path", "/dists/$name") and not $args{"overwrite"}
$self->info("path", "/dists/$name") not $args{"overwrite"}
Truth table0%0/3
A and not(B)
A= $self->info("path", "/dists/$name")B= not $args{"overwrite"}
ABresult
0X0
100
111
301 && not $args{overwrite} )
302 {
303 0 $self->log->warn( "dists/$name exists already" );
304 }
305 else {
306 0 ▶ $self->delete( path => "/dists/$name" ) if $args{delete};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"delete"} 0 0 0
307 0 $self->log->info(
308 "importing $args{source} to " . $self->repository );
309 0 $self->_add_to_order($name);
310  
311 0 my $version = $self->version;
312 0 $version->{$name} = $args{version};
313 0 $self->version($version);
314  
315 0 for
316 my $cmd ( $self->_cmd( import => %args, name => $name ) )
317 {
318 0 run_cmd($cmd);
319 }
320 }
321 }
322 }
323 }
324 else {
325 0 for my $cmd ( $self->_cmd( import => %args, name => $name ) ) {
326 0 run_cmd($cmd);
327 }
328 }
329 }
330  
331 =item export
332  
333  
334 =cut
335  
336 0 ▶sub export {
Subroutine export: not called CC=3 SCAR=24.8
Pod documented
337 0 my $self = shift;
338 0 my %args = @_;
339 0 ▶ my $path = $args{path} || '';
Condition0%0/2
$args{'path'} || ''
l!l
00
MC/DC0%0/1
$args{'path'} || ''
$args{'path'}
Truth table0%0/2
A
A= $args{'path'}
Aresult
11
00
340 0 $self->log->info(
341 'exporting ' . $self->repository . "/$path to $args{target}" );
342 0 for my $cmd ( $self->_cmd( export => %args ) ) {
343 0 run_cmd($cmd);
344 }
345 }
346  
347 =item checkout
348  
349 =cut
350  
351 0 ▶sub checkout {
Subroutine checkout: not called CC=3 SCAR=24.8
Pod documented
352 0 my $self = shift;
353 0 my %args = @_;
354 0 ▶ my $path = $args{path} || '';
Condition0%0/2
$args{'path'} || ''
l!l
00
MC/DC0%0/1
$args{'path'} || ''
$args{'path'}
Truth table0%0/2
A
A= $args{'path'}
Aresult
11
00
355 0 $self->log->info(
356 'exporting ' . $self->repository . "/$path to $args{target}" );
357 0 for my $cmd ( $self->_cmd( checkout => %args ) ) {
358 0 run_cmd($cmd);
359 }
360 }
361  
362 =item commit
363  
364 A wrapper around svn's commit command.
365  
366 =cut
367  
368 0 ▶sub commit {
Subroutine commit: not called CC=2 SCAR=17.9
Pod documented
369 0 my $self = shift;
370 0 my %args = @_;
371 0 $self->log->info( 'committing ' . $args{path} );
372 0 for my $cmd ( $self->_cmd( commit => @_ ) ) {
373 0 run_cmd( $cmd, 1 );
374 }
375 }
376  
377 0 ▶sub _add_to_order {
Subroutine _add_to_order: not called CC=2 SCAR=17.9
378 0 my $self = shift;
379 0 my $name = shift;
380  
381 0 my $order = $self->order;
382  
383 0 ▶ unless ( grep { $name eq $_ } @$order ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$name eq $_;} @$order) 0 0 0
384 0 $self->log->info( "adding $name to order for " . $self->repository );
385 0 push @$order, $name;
386 0 $self->order($order);
387 }
388 }
389  
390 =item update_order
391  
392 regenerate the dependency order.
393  
394 =cut
395  
396 0 ▶sub update_order {
Subroutine update_order: not called CC=6 SCAR=37.4
Pod documented
397 0 my $self = shift;
398 0 my %args = @_;
399  
400 0 $self->log->info( "updating order for " . $self->repository );
401  
402 0 ▶ my @dists = @{ $args{for_dists} || [] };
Condition0%0/2
$args{'for_dists'} || []
l!l
00
MC/DC0%0/1
$args{'for_dists'} || []
$args{'for_dists'}
Truth table0%0/2
A
A= $args{'for_dists'}
Aresult
11
00
403 0 ▶ unless (@dists) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@dists) 0 0 0
404 0 @dists = $self->dists;
405 }
406  
407 0 s{/$}{} for @dists;
408  
409 0 my $require = {};
410  
411 0 for (@dists) {
412 0 $self->_fill_deps( %args, require => $require, name => $_ );
413 }
414  
415 0 require Algorithm::Dependency::Ordered;
416 0 require Algorithm::Dependency::Source::HoA;
417  
418 0 my $source = Algorithm::Dependency::Source::HoA->new($require);
419 0 $source->load();
420 0 ▶ my $dep = Algorithm::Dependency::Ordered->new( source => $source, )
Branch: 1 branch
BranchTrueFalseTotal
my $dep = "Algorithm::Dependency::Ordered"->new("source", $source) or confess_or_die($@) 0 0 0
421 or confess_or_die $@;
422 0 my $order = $dep->schedule_all();
423  
424 0 $self->order($order);
425 }
426  
427 =item graph_deps
428  
429 return a dependency graph in graphviz format
430  
431 =cut
432  
433 0 ▶sub graph_deps {
Subroutine graph_deps: not called CC=7 SCAR=40.3
Pod documented
434 0 my $self = shift;
435 0 my %args = @_;
436  
437 0 $self->log->info( "outputting a graphviz order for " . $self->repository );
438  
439 0 ▶ my @dists = @{ $args{for_dists} || [] };
Condition0%0/2
$args{'for_dists'} || []
l!l
00
MC/DC0%0/1
$args{'for_dists'} || []
$args{'for_dists'}
Truth table0%0/2
A
A= $args{'for_dists'}
Aresult
11
00
440 0 ▶ unless (@dists) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@dists) 0 0 0
441 0 @dists = $self->dists;
442 }
443  
444 0 s{/$}{} for @dists;
445  
446 0 my $require = {};
447  
448 0 for my $distname (@dists) {
449 0 $self->_fill_deps( %args, require => $require, name => $distname );
450 }
451  
452 0 my $out = 'digraph g {
453 graph [ overlap = scale, rankdir= LR ];
454 node [ fontsize = "18", shape = record, fontsize = 18 ];
455 ';
456  
457 0 for my $dist (@dists) {
458 0 $out .= qq{ "$dist" [shape = record, fontsize = 18, label = "$dist" ];\n};
459 0 for my $dep ( @{ $require->{$dist} } ) {
460 0 $out .= qq{"$dist" -> "$dep";\n};
461 }
462 }
463 0 $out .= "\n};";
464 0 return $out;
465 }
466  
467 0 ▶sub _fill_deps {
Subroutine _fill_deps: not called CC=8 SCAR=42.8
468 0 my $self = shift;
469 0 my %args = @_;
470 0 my $require = $args{require};
471 0 my $name = $args{name};
472  
473 0 ▶ return if $require->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $require->{$name} 0 0 0
474 0 ▶ my $req = $self->requires( name => $name ) || {};
Condition0%0/2
$self->requires('name', $name) || {}
l!l
00
MC/DC0%0/1
$self->requires('name', $name) || {}
$self->requires('name', $name)
Truth table0%0/2
A
A= $self->requires('name', $name)
Aresult
11
00
475  
476 0 ▶ if ( $req->{requires} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{'requires'}) { } 0 0 0
477 0 for (qw/requires recommends build_requires test_requires/) {
478 0 push @{ $require->{$name} }, keys %{ $req->{$_} }
479 0 ▶ unless $args{"skip_$_"};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"skip_$_"} 0 0 0
480 }
481 }
482 else {
483  
484 #for back compatbility
485 0 push @{ $require->{$name} }, keys %$req;
486 }
487 0 @{ $require->{$name} } = uniq @{ $require->{$name} };
488  
489 0 for my $dep ( @{ $require->{$name} } ) {
490 0 ▶ next if $require->{$dep};
Branch: 1 branch
BranchTrueFalseTotal
if $require->{$dep} 0 0 0
491 0 $self->_fill_deps( %args, name => $dep );
492 }
493 }
494  
495 0 ▶sub _yml {
Subroutine _yml: not called CC=2 SCAR=17.9
496 0 my $self = shift;
497 0 my $path = shift;
498 0 my $yml = shift;
499  
500 0 my $file = catfile( $self->repository, $path );
501 0 ▶ if ($yml) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yml) { } 0 0 0
502  
503 0 dump_yaml_file( $file, $yml );
504 }
505 else {
506 0 load_yaml_file($file);
507 }
508 }
509  
510 =item order
511  
512 get or set the dependency order.
513  
514 =cut
515  
516 0 ▶sub order {
Subroutine order: not called CC=1 SCAR=6.9
Pod documented
517 0 my $self = shift;
518 0 my $order = shift;
519 0 my $path = '/shipwright/order.yml';
520 0 return $self->_yml( $path, $order );
521 }
522  
523 =item map
524  
525 get or set the map.
526  
527 =cut
528  
529 0 ▶sub map {
Subroutine map: not called CC=1 SCAR=6.9
Pod documented
530 0 my $self = shift;
531 0 my $map = shift;
532  
533 0 my $path = '/shipwright/map.yml';
534 0 return $self->_yml( $path, $map );
535 }
536  
537 =item source
538  
539 get or set the sources map.
540  
541 =cut
542  
543 0 ▶sub source {
Subroutine source: not called CC=1 SCAR=6.9
Pod documented
544 0 my $self = shift;
545 0 my $source = shift;
546 0 my $path = '/shipwright/source.yml';
547 0 return $self->_yml( $path, $source );
548 }
549  
550 =item flags
551  
552 get or set flags.
553  
554 =cut
555  
556 5 ▶sub flags {
Subroutine flags: called CC=1 SCAR=0.0
Pod documented
557 5 my $self = shift;
558 5 my $flags = shift;
559  
560 5 my $path = '/shipwright/flags.yml';
561 5 return $self->_yml( $path, $flags );
562 }
563  
564 =item version
565  
566 get or set version.
567  
568 =cut
569  
570 0 ▶sub version {
Subroutine version: not called CC=1 SCAR=6.9
Pod documented
571 0 my $self = shift;
572 0 my $version = shift;
573  
574 0 my $path = '/shipwright/version.yml';
575 0 return $self->_yml( $path, $version );
576 }
577  
578 =item branches
579  
580 get or set branches.
581  
582 =cut
583  
584 0 ▶sub branches {
Subroutine branches: not called CC=2 SCAR=17.9
Pod documented
585 0 my $self = shift;
586 0 my $branches = shift;
587  
588 0 ▶ if ( $self->has_branch_support ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_branch_support) 0 0 0
589 0 my $path = '/shipwright/branches.yml';
590 0 return $self->_yml( $path, $branches );
591 }
592  
593 # no branches support in 1.x
594 0 return;
595 }
596  
597 =item ktf
598  
599 get or set known failure conditions.
600  
601 =cut
602  
603 0 ▶sub ktf {
Subroutine ktf: not called CC=1 SCAR=6.9
Pod documented
604 0 my $self = shift;
605 0 my $ktf = shift;
606 0 my $path = '/shipwright/known_test_failures.yml';
607  
608 0 return $self->_yml( $path, $ktf );
609 }
610  
611 =item refs
612  
613 get or set refs
614  
615 =cut
616  
617 0 ▶sub refs {
Subroutine refs: not called CC=1 SCAR=6.9
Pod documented
618 0 my $self = shift;
619 0 my $refs = shift;
620 0 my $path = '/shipwright/refs.yml';
621  
622 0 return $self->_yml( $path, $refs );
623 }
624  
625 =item delete
626  
627  
628 =cut
629  
630 2 ▶sub delete {
Subroutine delete: called CC=4 SCAR=14.1
Pod documented
631 2 my $self = shift;
632 2 my %args = @_;
633 2 ▶ my $path = $args{path} || '';
Condition50%1/2
$args{'path'} || ''
l!l
02
MC/DC0%0/1
$args{'path'} || ''
$args{'path'}
Truth table50%1/2
A
A= $args{'path'}
Aresult
11
00
634 2 ▶ if ( $self->info( path => $path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->info("path", $path)) 2 0 2
635 2 $self->log->info( "deleting " . $self->repository . $path );
636 2 for my $cmd ( $self->_cmd( delete => path => $path ) ) {
637 2 run_cmd( $cmd, 1 );
638 }
639 }
640 }
641  
642 =item list
643  
644  
645 =cut
646  
647 0 ▶sub list {
Subroutine list: not called CC=3 SCAR=24.8
Pod documented
648 0 my $self = shift;
649 0 my %args = @_;
650 0 ▶ my $path = $args{path} || '';
Condition0%0/2
$args{'path'} || ''
l!l
00
MC/DC0%0/1
$args{'path'} || ''
$args{'path'}
Truth table0%0/2
A
A= $args{'path'}
Aresult
11
00
651 0 ▶ if ( $self->info( path => $path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->info("path", $path)) 0 0 0
652 0 my $out = run_cmd( $self->_cmd( list => path => $path ) );
653 0 return $out;
654 }
655 }
656  
657 =item dists
658  
659  
660 =cut
661  
662 0 ▶sub dists {
Subroutine dists: not called CC=1 SCAR=6.9
Pod documented
663 0 my $self = shift;
664 0 my %args = @_;
665 0 my $out = $self->list( path => '/scripts' );
666 0 return split /\s+/, $out;
667 }
668  
669 =item move
670  
671 =cut
672  
673 0 ▶sub move {
Subroutine move: not called CC=5 SCAR=34.0
Pod documented
674 0 my $self = shift;
675 0 my %args = @_;
676 0 ▶ my $path = $args{path} || '';
Condition0%0/2
$args{'path'} || ''
l!l
00
MC/DC0%0/1
$args{'path'} || ''
$args{'path'}
Truth table0%0/2
A
A= $args{'path'}
Aresult
11
00
677 0 ▶ my $new_path = $args{new_path} || '';
Condition0%0/2
$args{'new_path'} || ''
l!l
00
MC/DC0%0/1
$args{'new_path'} || ''
$args{'new_path'}
Truth table0%0/2
A
A= $args{'new_path'}
Aresult
11
00
678 0 ▶ if ( $self->info( path => $path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->info("path", $path)) 0 0 0
679 0 $self->log->info(
680 "moving " . $self->repository . "/$path to /$new_path" );
681 0 for my $cmd (
682 $self->_cmd(
683 move => path => $path,
684 new_path => $new_path,
685 )
686 )
687 {
688 0 run_cmd($cmd);
689 }
690 }
691 }
692  
693 =item info
694  
695 =cut
696  
697 4 ▶sub info {
Subroutine info: called CC=4 SCAR=14.2
Pod documented
698 4 my $self = shift;
699 4 my %args = @_;
700 4 ▶ my $path = $args{path} || '';
Condition100%2/2
$args{'path'} || ''
l!l
22
MC/DC100%1/1
$args{'path'} || ''
$args{'path'}
Truth table100%2/2
A
A= $args{'path'}
Aresult
11
00
701  
702 4 my ( $info, $err ) =
703 run_cmd( $self->_cmd( info => path => $path ), 1 );
704 4 ▶ $self->log->warn($err) if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 4 4
705  
706 4 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 4 0 4
707 4 return $info, $err;
708 }
709 else {
710 0 return $info;
711 }
712 }
713  
714 =item requires
715  
716 return the hashref of require.yml for a dist.
717  
718 =cut
719  
720 0 ▶sub requires {
Subroutine requires: not called CC=1 SCAR=6.9
Pod documented
721 0 my $self = shift;
722 0 my %args = @_;
723 0 my $name = $args{name};
724  
725 0 return $self->_yml( "/scripts/$name/require.yml" );
726 }
727  
728 =item check_repository
729  
730 Check if the given repository is valid.
731  
732 =cut
733  
734 2 ▶sub check_repository {
Subroutine check_repository: called CC=3 SCAR=11.2
Pod documented
735 2 my $self = shift;
736 2 my %args = @_;
737  
738 2 ▶ if ( $args{action} eq 'create' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'action'} eq 'create') { } 0 2 2
739 0 return 1;
740 }
741 else {
742  
743 # every valid shipwright repo has '/shipwright' subdir;
744 2 my $info = $self->info( path => '/shipwright' );
745  
746 2 ▶ return 1 if $info;
Branch: 1 branch
BranchTrueFalseTotal
if $info 1 1 2
747 }
748 1 return;
749 }
750  
751 =item update
752  
753 you should subclass this method, and run this to get the file path with latest version
754  
755 =cut
756  
757 0 ▶sub update {
Subroutine update: not called CC=7 SCAR=40.3
Pod documented
758 0 my $self = shift;
759 0 my %args = @_;
760  
761 0 ▶ confess_or_die "need path option" unless $args{path};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"path"} 0 0 0
762  
763 0 ▶ if ( $args{path} =~ m{/$} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'path'} =~ m[/$]) { } 0 0 0
764 # it's a directory
765 0 ▶ if ( $args{path} eq '/inc/' && ! $args{source} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'path'} eq '/inc/' and not $args{'source'}) { } 0 0 0
elsif ($args{'source'}) { } 0 0 0
Condition0%0/3
$args{"path"} eq "/inc/" and not $args{"source"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"path"} eq "/inc/" and not $args{"source"}
$args{"path"} eq "/inc/" not $args{"source"}
Truth table0%0/3
A and not(B)
A= $args{"path"} eq "/inc/"B= not $args{"source"}
ABresult
0X0
100
111
766 0 my $dir = tempdir(
767 'shipwright_backend_base_XXXXXX',
768 CLEANUP => 1,
769 TMPDIR => 1,
770 );
771 0 $self->_install_yaml_tiny($dir);
772 0 $self->_install_clean_inc($dir);
773 0 $self->_install_module_build($dir);
774 0 $self->_update_dir( '/inc/', catdir($dir, 'inc') );
775 }
776 elsif ( $args{source} ) {
777 0 $self->_update_dir( $args{path}, $args{source} );
778 }
779 }
780 else {
781  
782 confess_or_die "$args{path} seems not shipwright's own file"
783 0 ▶ unless -e catfile( share_root(), $args{path} );
Branch: 1 branch
BranchTrueFalseTotal
unless -e catfile(share_root(), $args{"path"}) 0 0 0
784  
785 return $self->_update_file( $args{path},
786 0 catfile( share_root(), $args{path} ) );
787 }
788 }
789  
790 =item test_script
791  
792 get or set test_script for a project, i.e. /t/test
793  
794 =cut
795  
796 0 ▶sub test_script {
Subroutine test_script: not called CC=2 SCAR=17.9
Pod documented
797 0 my $self = shift;
798 0 my %args = @_;
799  
800 0 ▶ if ( $args{source} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'source'}) { } 0 0 0
801 0 $self->_update_file( '/t/test', $args{source} );
802 }
803 else {
804 0 return $self->cat( path => '/t/test' );
805 }
806 }
807  
808 =item trim
809  
810 trim dists
811  
812 =cut
813  
814 0 ▶sub trim {
Subroutine trim: not called CC=12 SCAR=50.5
Pod documented
815 0 my $self = shift;
816 0 my %args = @_;
817 0 my @names_to_trim;
818  
819 0 ▶ if ( ref $args{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{'name'}) { } 0 0 0
820 0 @names_to_trim = @{ $args{name} };
821 }
822 else {
823 0 @names_to_trim = $args{name};
824 }
825  
826 0 my $order = $self->order;
827 0 my $map = $self->map;
828 0 ▶ my $version = $self->version || {};
Condition0%0/2
$self->version || {}
l!l
00
MC/DC0%0/1
$self->version || {}
$self->version
Truth table0%0/2
A
A= $self->version
Aresult
11
00
829 0 ▶ my $source = $self->source || {};
Condition0%0/2
$self->source || {}
l!l
00
MC/DC0%0/1
$self->source || {}
$self->source
Truth table0%0/2
A
A= $self->source
Aresult
11
00
830 0 ▶ my $flags = $self->flags || {};
Condition0%0/2
$self->flags || {}
l!l
00
MC/DC0%0/1
$self->flags || {}
$self->flags
Truth table0%0/2
A
A= $self->flags
Aresult
11
00
831  
832 0 for my $name (@names_to_trim) {
833 0 ▶ if ( $self->has_branch_support ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_branch_support) { } 0 0 0
834 0 $self->delete( path => "/sources/$name" );
835 }
836 else {
837 0 $self->delete( path => "/sources/$name" );
838 }
839 0 $self->delete( path => "/scripts/$name" );
840  
841 # clean order.yml
842 0 @$order = grep { $_ ne $name } @$order;
843  
844 # clean map.yml
845 0 for ( keys %$map ) {
846 0 ▶ delete $map->{$_} if $map->{$_} eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $map->{$_} eq $name 0 0 0
847 }
848  
849 # clean version.yml, source.yml and flags.yml
850  
851 0 for my $hashref ( $source, $flags, $version ) {
852 0 for ( keys %$hashref ) {
853 0 ▶ if ( $_ eq $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq $name) 0 0 0
854 0 delete $hashref->{$_};
855 0 last;
856 }
857 }
858 }
859  
860 }
861 0 $self->version($version);
862 0 $self->map($map);
863 0 $self->source($source);
864 0 $self->flags($flags);
865 0 $self->order($order);
866 0 $self->update_refs;
867 }
868  
869 =item update_refs
870  
871 update refs.
872  
873 we need update this after import and trim
874  
875 =cut
876  
877 0 ▶sub update_refs {
Subroutine update_refs: not called CC=6 SCAR=37.4
Pod documented
878 0 my $self = shift;
879 0 my $order = $self->order;
880 0 my $refs = {};
881  
882 0 for my $name (@$order) {
883  
884 # initialize here, in case we don't have $name entry in $refs
885 0 ▶ $refs->{$name} ||= 0;
Condition0%0/2
$refs->{$name} ||= 0
l!l
00
MC/DC0%0/1
$refs->{$name} ||= 0
$refs->{$name}
Truth table0%0/2
A
A= $refs->{$name}
Aresult
11
00
886  
887 0 ▶ my $req = $self->requires( name => $name ) || {};
Condition0%0/2
$self->requires('name', $name) || {}
l!l
00
MC/DC0%0/1
$self->requires('name', $name) || {}
$self->requires('name', $name)
Truth table0%0/2
A
A= $self->requires('name', $name)
Aresult
11
00
888  
889 0 my @deps;
890 0 ▶ if ( $req->{requires} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{'requires'}) { } 0 0 0
891 @deps = (
892 0 keys %{ $req->{requires} },
893 0 keys %{ $req->{recommends} },
894 0 keys %{ $req->{build_requires} },
895 0 keys %{ $req->{test_requires} }
896 );
897 }
898 else {
899  
900 #for back compatbility
901 0 @deps = keys %$req;
902 }
903  
904 0 @deps = uniq @deps;
905  
906 0 for (@deps) {
907 0 $refs->{$_}++;
908 }
909 }
910  
911 0 $self->refs($refs);
912 }
913  
914 =item has_branch_support
915  
916 return true if has branch support
917  
918 =cut
919  
920 0 ▶sub has_branch_support {
Subroutine has_branch_support: not called CC=2 SCAR=17.9
Pod documented
921 0 my $self = shift;
922 0 ▶ return 1 if $self->info( path => '/shipwright/branches.yml' );
Branch: 1 branch
BranchTrueFalseTotal
if $self->info("path", "/shipwright/branches.yml") 0 0 0
923 0 return;
924 }
925  
926 5 *_initialize_local_dir = *_cmd = *_update_file = *_update_dir =
927 *_subclass_method;
928  
929 =item local_dir
930  
931 for vcs backend, we made a local checkout/clone version, which will live here
932  
933 =cut
934  
935 0 ▶sub local_dir {
Subroutine local_dir: not called CC=2 SCAR=17.9
Pod documented
936 0 my $self = shift;
937 0 my $need_init = shift;
938 0 my $base_dir =
939 catdir( shipwright_user_root(), 'backends' );
940 0 ▶ make_path( $base_dir ) unless -e $base_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $base_dir 0 0 0
941 0 my $repo = $self->repository;
942 0 $repo =~ s/:/-/g;
943 0 $repo =~ s![/\\]!_!g;
944 0 my $target = catdir( $base_dir, $repo );
945 0 return $target;
946  
947 }
948  
949 =item strip_repository
950  
951 =cut
952  
953 11 ▶sub strip_repository {
Subroutine strip_repository: called CC=1 SCAR=0.0
Pod documented
954 11 my $self = shift;
955 11 my $repo = $self->repository;
956 11 $repo =~ s/^[a-z+]+://;
957 11 $self->repository($repo);
958 11 return;
959 }
960  
961 =back
962  
963 =cut
964  
965 5 1;
966 __END__
« blib/lib/auto/share/dist/Shipwright/bin/shipwright-builder ↑ Summary blib/lib/Shipwright/Backend/SVK.pm »