« blib/lib/Alien/Build/Plugin/PkgConfig/CommandLine.pm
↑ Summary
blib/lib/Alien/Build/Plugin/Digest/SHAPP.pm »
| 1 | package Alien::Build::Util; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 71 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 71 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 71 | ▶ | use 5.008004; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 71 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 71 | ▶ | use Path::Tiny qw( path ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 71 | ▶ | use Config; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | # ABSTRACT: Private utility functions for Alien::Build | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 71 | our $VERSION = '2.88'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 71 | our @EXPORT_OK = qw( _mirror _dump _destdir_prefix _perl_config _ssl_reqs _has_ssl ); | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | # usage: _mirror $source_directory, $dest_direction, \%options | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # options: | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # - filter -> regex for files that should match | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # - empty_directory -> if true, create all directories, including empty ones. | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # - verbose -> turn on verbosity | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | sub _mirror | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 49 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mirror: called CC=2 SCAR=7.3
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 49 | my($src_root, $dst_root, $opt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 49 | ($src_root, $dst_root) = map { path($_) } ($src_root, $dst_root); | |||||||||||||||||||||||||||||||||||||||||
| 27 | 49 | ▶ | $opt ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opt ||= {}
MC/DC100%1/1
$opt ||= {}
$opt
Truth table100%2/2
A
A= $opt
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 49 | require Alien::Build; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 49 | require File::Find; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 49 | require File::Copy; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | File::Find::find({ | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 299 | ▶ | wanted => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=25 SCAR=37.9
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 299 | ▶ | next unless -e $File::Find::name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 299 | my $src = path($File::Find::name)->relative($src_root); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 299 | ▶ | return if $opt->{filter} && "$src" !~ $opt->{filter}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opt->{"filter"} and not "$src" =~ /$opt->{"filter"}/
MC/DC100%2/2
$opt->{"filter"} and not "$src" =~ /$opt->{"filter"}/
$opt->{"filter"}
not "$src" =~ /$opt->{"filter"}/
Truth table100%3/3
A and not(B)
A= $opt->{"filter"}B= not "$src" =~ /$opt->{"filter"}/
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 273 | ▶ | return if "$src" eq '.'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 228 | my $dst = $dst_root->child("$src"); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 228 | $src = $src->absolute($src_root); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 228 | ▶ | if(-l "$src") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | ▶ | unless(-d $dst->parent) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | Alien::Build->log("mkdir -p @{[ $dst->parent ]}") if $opt->{verbose}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $dst->parent->mkpath; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | # TODO: rmtree if a directory? | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | if(-e "$dst") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | { unlink "$dst" } | |||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | my $target = readlink "$src"; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | ▶ | Alien::Build->log("ln -s $target $dst") if $opt->{verbose}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | ▶ | symlink($target, $dst) || die "unable to symlink $target => $dst"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | elsif(-d "$src") | ||||||||||||||||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 85 | ▶ | if($opt->{empty_directory}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 9 | ▶ | unless(-d $dst) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 9 | ▶ | Alien::Build->log("mkdir $dst") if $opt->{verbose}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 9 | ▶ | mkdir($dst) || die "unable to create directory $dst: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | elsif(-f "$src") | ||||||||||||||||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 140 | ▶ | unless(-d $dst->parent) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 79 | ▶ | Alien::Build->log("mkdir -p @{[ $dst->parent ]}") if $opt->{verbose}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 79 | $dst->parent->mkpath; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # TODO: rmtree if a directory? | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 140 | ▶ | if(-e "$dst") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | { unlink "$dst" } | |||||||||||||||||||||||||||||||||||||||||
| 76 | 140 | ▶ | Alien::Build->log("cp $src $dst") if $opt->{verbose}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 140 | ▶ | File::Copy::cp("$src", "$dst") || die "copy error $src => $dst: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 140 | ▶ | if($] < 5.012 && -x "$src" && $^O ne 'MSWin32') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$] < "5.012" and -x "$src" and $^O ne "MSWin32"
$] < "5.012" and -x "$src"
MC/DC0%0/3
$] < "5.012" and -x "$src" and $^O ne "MSWin32"
$] < "5.012"
-x "$src"
$^O ne "MSWin32"
Truth table25%1/4
A and B and C
A= $] < "5.012"B= -x "$src"C= $^O ne "MSWin32"
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # apparently Perl 5.8 and 5.10 do not preserver perms | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $mode = [stat "$src"]->[2] & oct(777); | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | eval { chmod $mode, "$dst" }; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 49 | no_chdir => 1, | |||||||||||||||||||||||||||||||||||||||||
| 87 | }, "$src_root"); | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 49 | (); | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | sub _dump | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 50 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dump: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 50 | ▶ | if(eval { require YAML }) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 50 | return YAML::Dump(@_); | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | else | ||||||||||||||||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | return Data::Dumper::Dumper(@_); | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | sub _destdir_prefix | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 20 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_destdir_prefix: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 20 | my($destdir, $prefix) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 20 | ▶ | $prefix =~ s{^/?([a-z]):}{$1}i if $^O eq 'MSWin32'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 20 | path($destdir)->child($prefix)->stringify; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | sub _perl_config | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_perl_config: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 6 | my($key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 6 | $Config{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | sub _ssl_reqs | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ssl_reqs: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 12 | 'Net::SSLeay' => '1.49', | |||||||||||||||||||||||||||||||||||||||||
| 122 | 'IO::Socket::SSL' => '1.56', | ||||||||||||||||||||||||||||||||||||||||||
| 123 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | sub _has_ssl | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_has_ssl: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | my %reqs = %{ _ssl_reqs() }; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 6 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 130 | 6 | require Net::SSLeay; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 6 | ▶ | die "need Net::SSLeay $reqs{'Net::SSLeay'}" unless Net::SSLeay->VERSION($reqs{'Net::SSLeay'}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 6 | require IO::Socket::SSL; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 6 | ▶ | die "need IO::Socket::SSL $reqs{'IO::Socket::SSL'}" unless IO::Socket::SSL->VERSION($reqs{'IO::Socket::SSL'}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 6 | $@ eq ''; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 71 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | __END__ | ||||||||||||||||||||||||||||||||||||||||||