blib/lib/Shipwright/Source.pm

filter: Statementstmt 97.0% 65 / 67 Branchbran 85.2% 29 / 34 Conditioncond 37.5% 9 / 24 MC/DCmcdc 6.2% 1 / 16 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 75.8% 116 / 153 CC 28 SCAR 25.2
CC
28
Cov
82%
new
17.9
type
14.1
_translate_source
2.5
CRAP 12.4
« blib/lib/Shipwright/Source/SVK.pm ↑ Summary blib/lib/Shipwright/Source/SVN.pm »
1 package Shipwright::Source;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use UNIVERSAL::require;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use File::Temp qw/tempdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use File::Spec::Functions qw/catfile catdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Shipwright::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use File::Path qw/make_path/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Shipwright::Source - Source
14  
15 =head1 SYNOPSIS
16  
17 shipwright import -r ... cpan:XML::LibXML
18  
19 use Shipwright::Source;
20  
21 =head1 SUPPORTED SOURCES
22  
23 Currently, the supported sources are L<CPAN|Shipwright::SOURCE::CPAN>, L<Compressed|Shipwright::SOURCE::Compressed>, L<Directory|Shipwright::SOURCE::Directory>, L<FTP|Shipwright::SOURCE::FTP>, L<Git|Shipwright::SOURCE::Git>, L<HTTP|Shipwright::SOURCE::HTTP>, L<SVK|Shipwright::SOURCE::SVK>, L<SVN|Shipwright::SOURCE::SVN> and L<Shipwright|Shipwright::SOURCE::Shipwright>.
24  
25 =head1 METHODS
26  
27 =head2 new
28  
29 =cut
30  
31 $ENV{SHIPWRIGHT_SOURCE_ROOT} ||=
32 3 ▶ tempdir( 'shipwright_source_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
Condition33%1/3
$ENV{"SHIPWRIGHT_SOURCE_ROOT"} ||= tempdir("shipwright_source_XXXXXX", "CLEANUP", 1, "TMPDIR", 1)
l!l&&r!l&&!r
030
MC/DC0%0/2
$ENV{"SHIPWRIGHT_SOURCE_ROOT"} ||= tempdir("shipwright_source_XXXXXX", "CLEANUP", 1, "TMPDIR", 1)
$ENV{"SHIPWRIGHT_SOURCE_ROOT"} tempdir("shipwright_source_XXXXXX", "CLEANUP", 1, "TMPDIR", 1)
Truth table33%1/3
A ||= B
A= $ENV{"SHIPWRIGHT_SOURCE_ROOT"}B= tempdir("shipwright_source_XXXXXX", "CLEANUP", 1, "TMPDIR", 1)
ABresult
1X1
011
000
33  
34 12 ▶sub new {
Subroutine new: called CC=14 SCAR=28.8
Pod documented
35 12 my $class = shift;
36 my %args = (
37 follow => 1,
38 directory => $ENV{SHIPWRIGHT_SOURCE_ROOT},
39 12 @_,
40 );
41  
42 $args{download_directory} ||=
43 12 ▶ catdir( shipwright_user_root(), 'downloads' );
Condition33%1/3
$args{"download_directory"} ||= catdir(shipwright_user_root(), "downloads")
l!l&&r!l&&!r
0120
MC/DC0%0/2
$args{"download_directory"} ||= catdir(shipwright_user_root(), "downloads")
$args{"download_directory"} catdir(shipwright_user_root(), "downloads")
Truth table33%1/3
A ||= B
A= $args{"download_directory"}B= catdir(shipwright_user_root(), "downloads")
ABresult
1X1
011
000
44  
45 12 ▶ $args{scripts_directory} ||= catdir( $args{directory}, '__scripts' );
Condition33%1/3
$args{"scripts_directory"} ||= catdir($args{"directory"}, "__scripts")
l!l&&r!l&&!r
0120
MC/DC0%0/2
$args{"scripts_directory"} ||= catdir($args{"directory"}, "__scripts")
$args{"scripts_directory"} catdir($args{"directory"}, "__scripts")
Truth table33%1/3
A ||= B
A= $args{"scripts_directory"}B= catdir($args{"directory"}, "__scripts")
ABresult
1X1
011
000
46 12 ▶ $args{map_path} ||= catfile( $args{directory}, 'map.yml' );
Condition33%1/3
$args{"map_path"} ||= catfile($args{"directory"}, "map.yml")
l!l&&r!l&&!r
0120
MC/DC0%0/2
$args{"map_path"} ||= catfile($args{"directory"}, "map.yml")
$args{"map_path"} catfile($args{"directory"}, "map.yml")
Truth table33%1/3
A ||= B
A= $args{"map_path"}B= catfile($args{"directory"}, "map.yml")
ABresult
1X1
011
000
47 12 ▶ $args{url_path} ||= catfile( $args{directory}, 'url.yml' );
Condition33%1/3
$args{"url_path"} ||= catfile($args{"directory"}, "url.yml")
l!l&&r!l&&!r
0120
MC/DC0%0/2
$args{"url_path"} ||= catfile($args{"directory"}, "url.yml")
$args{"url_path"} catfile($args{"directory"}, "url.yml")
Truth table33%1/3
A ||= B
A= $args{"url_path"}B= catfile($args{"directory"}, "url.yml")
ABresult
1X1
011
000
48 12 ▶ $args{version_path} ||= catfile( $args{directory}, 'version.yml' );
Condition33%1/3
$args{"version_path"} ||= catfile($args{"directory"}, "version.yml")
l!l&&r!l&&!r
0120
MC/DC0%0/2
$args{"version_path"} ||= catfile($args{"directory"}, "version.yml")
$args{"version_path"} catfile($args{"directory"}, "version.yml")
Truth table33%1/3
A ||= B
A= $args{"version_path"}B= catfile($args{"directory"}, "version.yml")
ABresult
1X1
011
000
49 12 ▶ $args{branches_path} ||= catfile( $args{directory}, 'branches.yml' );
Condition33%1/3
$args{"branches_path"} ||= catfile($args{"directory"}, "branches.yml")
l!l&&r!l&&!r
0120
MC/DC0%0/2
$args{"branches_path"} ||= catfile($args{"directory"}, "branches.yml")
$args{"branches_path"} catfile($args{"directory"}, "branches.yml")
Truth table33%1/3
A ||= B
A= $args{"branches_path"}B= catfile($args{"directory"}, "branches.yml")
ABresult
1X1
011
000
50  
51 12 for (qw/map_path url_path version_path branches_path/) {
52 48 ▶ next if -e $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
if -e $args{$_} 40 8 48
53 8 ▶ open my $fh, '>', $args{$_} or confess_or_die "can't write to $args{$_}: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $args{$_} or confess_or_die("can't write to $args{$_}: $!") 8 0 8
54 8 close $fh;
55 }
56  
57 12 ▶ confess_or_die "need source arg" unless exists $args{source};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"source"} 1 11 12
58  
59 11 for my $dir (qw/directory download_directory scripts_directory/) {
60 33 ▶ make_path( $args{$dir} ) unless -e $args{$dir};
Branch: 1 branch
BranchTrueFalseTotal
unless -e $args{$dir} 4 29 33
61 }
62  
63 11 my $type = type( \$args{source} );
64  
65 11 ▶ confess_or_die "invalid source: $args{source}" unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 1 10 11
66  
67 10 my $module = 'Shipwright::Source::' . $type;
68 10 $module->require;
69 10 return $module->new(%args);
70 }
71  
72 =head2 type
73  
74 =cut
75  
76 11 ▶sub type {
Subroutine type: called CC=14 SCAR=26.5
Pod documented
77 11 my $source = shift;
78 11 ▶ return unless $$source;
Branch: 1 branch
BranchTrueFalseTotal
unless $$source 1 10 11
79  
80 10 _translate_source($source);
81  
82 10 ▶ if ( $$source =~ /\.(?:tar\.(?:gz|bz2)|tgz|tbz|zip)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$source =~ /\.(?:tar\.(?:gz|bz2)|tgz|tbz|zip)$/) 4 6 10
83 4 ▶ if ( $$source =~ s/^file://i || -f $$source ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$source =~ s/^file://i or -f $$source) 1 3 4
Condition66%2/3
$$source =~ s/^file://i or -f $$source
l!l&&r!l&&!r
103
MC/DC50%1/2
$$source =~ s/^file://i or -f $$source
$$source =~ s/^file://i -f $$source
Truth table66%2/3
A or B
A= $$source =~ s/^file://iB= -f $$source
ABresult
1X1
011
000
84 1 return 'Compressed';
85 }
86 }
87  
88 9 ▶ return 'Directory' if $$source =~ s/^dir(?:ectory)?:(?!:\w+)//i;
Branch: 1 branch
BranchTrueFalseTotal
if $$source =~ s/^dir(?:ectory)?:(?!:\w+)//i 1 8 9
89  
90 8 ▶ return 'Shipyard' if $$source =~ s/^(?:shipyard|shipwright)://i;
Branch: 1 branch
BranchTrueFalseTotal
if $$source =~ s/^(?:shipyard|shipwright)://i 0 8 8
91  
92 # prefix that can be omitted
93 8 for my $type (qw/svn http https ftp git/) {
94 32 ▶ if ( $$source =~ /^$type:(?!:\w+)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$source =~ /^$type:(?!:\w+)/i) 4 28 32
95 4 $$source =~ s{^$type:(?!//)}{}i;
96 4 ▶ return $type eq 'git' ? 'Git' : $type eq 'https' ? 'HTTP' : uc $type;
Branch: 2 branches
BranchTrueFalseTotal
$type eq 'git' ? : 1 3 4
$type eq 'https' ? : 0 3 3
97 }
98 }
99  
100 4 ▶ if ( $$source =~ m{^(//|svk:(?!:\w+))}i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$source =~ m[^(//|svk:(?!:\w+))]i) 1 3 4
101 1 $$source =~ s/^svk://i;
102 1 return 'SVK';
103 }
104  
105 3 ▶ return 'Directory' if -d $$source;
Branch: 1 branch
BranchTrueFalseTotal
if -d $$source 0 3 3
106  
107 # default is cpan module or distribution
108 3 $$source =~ s/^cpan:(?!:\w+)//i;
109  
110 # in case typos like IO:File
111 3 $$source =~ s/(?<!:):(?!:)/::/g;
112  
113 # if it's not a distribution name like
114 # 'S/SU/SUNNAVY/IP-QQWry-v0.0.15.tar.gz', convert '-' to '::'.
115 3 ▶ $$source =~ s/-/::/g
Branch: 1 branch
BranchTrueFalseTotal
unless $$source =~ /\.(?:tar\.(?:gz|bz2)|tgz|tbz)$/ 2 1 3
116 unless $$source =~ /\.(?:tar\.(?:gz|bz2)|tgz|tbz)$/;
117  
118 3 return 'CPAN';
119  
120 }
121  
122 10 ▶sub _translate_source {
Subroutine _translate_source: called CC=2 SCAR=9.2
123 10 my $source = shift;
124 10 ▶ if ( $$source =~ /^(file|dir(ectory)?|shipwright):~/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$source =~ /^(file|dir(ectory)?|shipwright):~/i) 0 10 10
125  
126 # replace prefix ~ with real home dir
127 0 $$source =~ s/~/user_home/e;
128 }
129 }
130  
131 3 1;
132  
133 __END__
« blib/lib/Shipwright/Source/SVK.pm ↑ Summary blib/lib/Shipwright/Source/SVN.pm »