| 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)
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)
| |||||||||||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 12 | ▶ | $args{scripts_directory} ||= catdir( $args{directory}, '__scripts' ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{"scripts_directory"} ||= catdir($args{"directory"}, "__scripts")
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")
| |||||||||||||||||||||||||||||
| 46 | 12 | ▶ | $args{map_path} ||= catfile( $args{directory}, 'map.yml' ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{"map_path"} ||= catfile($args{"directory"}, "map.yml")
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")
| |||||||||||||||||||||||||||||
| 47 | 12 | ▶ | $args{url_path} ||= catfile( $args{directory}, 'url.yml' ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{"url_path"} ||= catfile($args{"directory"}, "url.yml")
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")
| |||||||||||||||||||||||||||||
| 48 | 12 | ▶ | $args{version_path} ||= catfile( $args{directory}, 'version.yml' ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{"version_path"} ||= catfile($args{"directory"}, "version.yml")
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")
| |||||||||||||||||||||||||||||
| 49 | 12 | ▶ | $args{branches_path} ||= catfile( $args{directory}, 'branches.yml' ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{"branches_path"} ||= catfile($args{"directory"}, "branches.yml")
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")
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 12 | for (qw/map_path url_path version_path branches_path/) { | |||||||||||||||||||||||||||
| 52 | 48 | ▶ | next if -e $args{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 8 | ▶ | open my $fh, '>', $args{$_} or confess_or_die "can't write to $args{$_}: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 8 | close $fh; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 12 | ▶ | confess_or_die "need source arg" unless exists $args{source}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 11 | my $type = type( \$args{source} ); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 11 | ▶ | confess_or_die "invalid source: $args{source}" unless $type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 10 | _translate_source($source); | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 10 | ▶ | if ( $$source =~ /\.(?:tar\.(?:gz|bz2)|tgz|tbz|zip)$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 4 | ▶ | if ( $$source =~ s/^file://i || -f $$source ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$$source =~ s/^file://i or -f $$source
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
| |||||||||||||||||||||||||||||
| 84 | 1 | return 'Compressed'; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 9 | ▶ | return 'Directory' if $$source =~ s/^dir(?:ectory)?:(?!:\w+)//i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 8 | ▶ | return 'Shipyard' if $$source =~ s/^(?:shipyard|shipwright)://i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 95 | 4 | $$source =~ s{^$type:(?!//)}{}i; | |||||||||||||||||||||||||||
| 96 | 4 | ▶ | return $type eq 'git' ? 'Git' : $type eq 'https' ? 'HTTP' : uc $type; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 4 | ▶ | if ( $$source =~ m{^(//|svk:(?!:\w+))}i ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 1 | $$source =~ s/^svk://i; | |||||||||||||||||||||||||||
| 102 | 1 | return 'SVK'; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 3 | ▶ | return 'Directory' if -d $$source; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # replace prefix ~ with real home dir | ||||||||||||||||||||||||||||
| 127 | 0 | $$source =~ s/~/user_home/e; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 3 | 1; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||