| 1 | package File::ShareDir::Dist::Install; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use base qw( Exporter ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our @EXPORT = qw( install install_dir install_config_get install_config_set ); | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # ABSTRACT: Install per-dist shared files | ||||||||||||||||||||||||||||
| 13 | 2 | our $VERSION = '0.07'; # VERSION | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub install_dir | ||||||||||||||||||||||||||||
| 17 | 29 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
install_dir: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 29 | my($dist_name) = @_; | |||||||||||||||||||||||||||
| 19 | 29 | ▶ | croak "Not a valid dist_name: undef" unless defined $dist_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 27 | ▶ | croak "Not a valid dist_name: $dist_name" unless $dist_name =~ /^[A-Za-z0-9_][A-Za-z0-9_-]*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 25 | "blib/lib/auto/share/dist/$dist_name"; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub _mkpath | ||||||||||||||||||||||||||||
| 26 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_mkpath: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 5 | my($dist_name) = @_; | |||||||||||||||||||||||||||
| 28 | 5 | require File::Path; | |||||||||||||||||||||||||||
| 29 | 5 | File::Path::mkpath(install_dir($dist_name), { verbose => 0, mode => 0755 }); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub install | ||||||||||||||||||||||||||||
| 33 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
install: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 6 | my($source_dir, $dist_name) = @_; | |||||||||||||||||||||||||||
| 35 | 6 | ▶ | ($source_dir, $dist_name) = @ARGV unless defined $source_dir || defined $dist_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $source_dir or defined $dist_name
MC/DC50%1/2
defined $source_dir or defined $dist_name
defined $source_dir
defined $dist_name
Truth table66%2/3
A or B
A= defined $source_dirB= defined $dist_name
| |||||||||||||||||||||||||||||
| 36 | 6 | ▶ | croak "No such directory: undef" unless defined $source_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 5 | ▶ | croak "No such directory: $source_dir" unless -d $source_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 4 | my $dest_dir = install_dir $dist_name; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # Can I just say... | ||||||||||||||||||||||||||||
| 41 | # File::Find has a terrible terrible terrible interface. | ||||||||||||||||||||||||||||
| 42 | 2 | my @files = do { | |||||||||||||||||||||||||||
| 43 | 2 | require Cwd; | |||||||||||||||||||||||||||
| 44 | 2 | require File::Find; | |||||||||||||||||||||||||||
| 45 | 2 | my $save = Cwd::getcwd(); | |||||||||||||||||||||||||||
| 46 | 2 | ▶ | chdir($source_dir) || die "unable to chdir $source_dir"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 2 | my @list; | |||||||||||||||||||||||||||
| 48 | 8 | ▶ | File::Find::find(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 49 | 8 | ▶ | return unless -f $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 4 | push @list, $File::Find::name; | |||||||||||||||||||||||||||
| 51 | 2 | }, File::Spec->curdir); | |||||||||||||||||||||||||||
| 52 | 2 | chdir $save; | |||||||||||||||||||||||||||
| 53 | 2 | @list; | |||||||||||||||||||||||||||
| 54 | }; | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 2 | require File::Basename; | |||||||||||||||||||||||||||
| 57 | 2 | require File::Path; | |||||||||||||||||||||||||||
| 58 | 2 | require File::Copy; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 2 | foreach my $file (@files) | |||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||
| 62 | 4 | my $from = File::Spec->catfile($source_dir, $file); | |||||||||||||||||||||||||||
| 63 | 4 | my $to = File::Spec->catfile($dest_dir, $file); | |||||||||||||||||||||||||||
| 64 | 4 | my $dir = File::Basename::dirname($to); | |||||||||||||||||||||||||||
| 65 | 4 | File::Path::mkpath($dir, { verbose => 0, mode => 0755 }); | |||||||||||||||||||||||||||
| 66 | 4 | ▶ | File::Copy::cp($from, $to) || die "Copy failed $from => $to: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub install_config_get | ||||||||||||||||||||||||||||
| 72 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
install_config_get: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 9 | my($dist_name) = @_; | |||||||||||||||||||||||||||
| 74 | 9 | my $fn = File::Spec->catfile(install_dir($dist_name), 'config.pl'); | |||||||||||||||||||||||||||
| 75 | 9 | ▶ | if(-e $fn) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||
| 77 | 6 | my $fh; | |||||||||||||||||||||||||||
| 78 | 6 | ▶ | open($fh, '<', $fn) || die "error reading $fn $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 6 | my $pl = do { local $/; <$fh> }; | |||||||||||||||||||||||||||
| 80 | 6 | close $fh; | |||||||||||||||||||||||||||
| 81 | 6 | my $config = eval $pl; | |||||||||||||||||||||||||||
| 82 | 6 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 6 | return $config; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | else | ||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||
| 87 | 3 | return {}; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | sub install_config_set; | ||||||||||||||||||||||||||||
| 93 | sub install_config_set | ||||||||||||||||||||||||||||
| 94 | 8 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
install_config_set: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 8 | my($dist_name, $one, $two) = @_; | |||||||||||||||||||||||||||
| 96 | 8 | ▶ | ($dist_name, $one, $two) = @ARGV unless defined $dist_name && defined $one; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $dist_name and defined $one
MC/DC50%1/2
defined $dist_name and defined $one
defined $dist_name
defined $one
Truth table66%2/3
A and B
A= defined $dist_nameB= defined $one
| |||||||||||||||||||||||||||||
| 97 | 8 | ▶ | if(defined $two) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||
| 99 | 3 | my($key, $value) = ($one, $two); | |||||||||||||||||||||||||||
| 100 | 3 | my $config = install_config_get $dist_name; | |||||||||||||||||||||||||||
| 101 | 3 | $config->{$key} = $value; | |||||||||||||||||||||||||||
| 102 | 3 | return install_config_set $dist_name, $config; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | else | ||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||
| 106 | 5 | my($config) = ($one); | |||||||||||||||||||||||||||
| 107 | 5 | ▶ | croak "config is not a hash!" unless ref $config eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 5 | require Data::Dumper; | |||||||||||||||||||||||||||
| 109 | 5 | my $dd = Data::Dumper | |||||||||||||||||||||||||||
| 110 | ->new([$config],['x']) | ||||||||||||||||||||||||||||
| 111 | ->Indent(1) | ||||||||||||||||||||||||||||
| 112 | ->Terse(0) | ||||||||||||||||||||||||||||
| 113 | ->Purity(1) | ||||||||||||||||||||||||||||
| 114 | ->Sortkeys(1) | ||||||||||||||||||||||||||||
| 115 | ->Dump; | ||||||||||||||||||||||||||||
| 116 | 5 | my $fh; | |||||||||||||||||||||||||||
| 117 | 5 | _mkpath($dist_name); | |||||||||||||||||||||||||||
| 118 | 5 | my $fn = File::Spec->catfile(install_dir($dist_name), 'config.pl'); | |||||||||||||||||||||||||||
| 119 | 5 | ▶ | open($fh, '>', $fn) || die "error writing $fn $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 5 | print $fh 'do { my '; | |||||||||||||||||||||||||||
| 121 | 5 | print $fh $dd; | |||||||||||||||||||||||||||
| 122 | 5 | print $fh '$x;}'; | |||||||||||||||||||||||||||
| 123 | 5 | close $fh; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 2 | 1; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||||||||||