| 1 | package PAR::Dist::InstallPPD; | ||
| 2 | |||
| 3 | 2 | ▶ | use 5.006; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 0 | ▶ | use PAR::Dist::FromPPD (); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | use PAR::Dist (); | ||
| 9 | use File::Temp (); | ||
| 10 | use File::Spec; | ||
| 11 | use File::Path; | ||
| 12 | use Cwd; | ||
| 13 | |||
| 14 | require Config; | ||
| 15 | require Exporter; | ||
| 16 | |||
| 17 | our @ISA = qw(Exporter); | ||
| 18 | |||
| 19 | our %EXPORT_TAGS = ( 'all' => [ qw( | ||
| 20 | par_install_ppd | ||
| 21 | ) ] ); | ||
| 22 | |||
| 23 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | ||
| 24 | |||
| 25 | our @EXPORT = qw( | ||
| 26 | par_install_ppd | ||
| 27 | ); | ||
| 28 | |||
| 29 | our $VERSION = '0.02'; | ||
| 30 | |||
| 31 | our $VERBOSE = 0; | ||
| 32 | |||
| 33 | |||
| 34 | sub _verbose { | ||
| 35 | $VERBOSE = shift if (@_); | ||
| 36 | return $VERBOSE | ||
| 37 | } | ||
| 38 | |||
| 39 | sub _diag { | ||
| 40 | my $msg = shift; | ||
| 41 | return unless _verbose(); | ||
| 42 | print $msg ."\n"; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub par_install_ppd { | ||
| 46 | die "Uneven number of arguments to 'par_install_ppd'." if @_ % 2; | ||
| 47 | my %args = @_; | ||
| 48 | |||
| 49 | _verbose($args{'verbose'}); | ||
| 50 | |||
| 51 | _diag "Creating temporary directory for temporary .par"; | ||
| 52 | |||
| 53 | my $tdir = $args{out} = File::Temp::tempdir( | ||
| 54 | CLEANUP => 1, | ||
| 55 | DIR => File::Spec->tmpdir(), | ||
| 56 | ); | ||
| 57 | |||
| 58 | _diag "Preparing meta data for temporary .par"; | ||
| 59 | |||
| 60 | # should be figured out by ::FromPPD | ||
| 61 | delete $args{$_} for qw( | ||
| 62 | distversion perlversion | ||
| 63 | ); | ||
| 64 | # just need to be defined. | ||
| 65 | $args{arch} = $Config::Config{archname}; | ||
| 66 | $args{perlversion} = sprintf('%vd', $^V); | ||
| 67 | |||
| 68 | # Accept running perl version (5.8.8) | ||
| 69 | # or main perl version (5.8) | ||
| 70 | # or any other subversions (5.8.6) | ||
| 71 | my $perlver = sprintf('%vd', $^V); | ||
| 72 | my $mainperlver = $perlver; | ||
| 73 | $mainperlver =~ s/^(\d+)\.(\d+)\..*$/$1.$2/; | ||
| 74 | _diag "Setting perl version to ($perlver|$mainperlver|$mainperlver\\.\\d+)" | ||
| 75 | if not defined $args{selectperl}; | ||
| 76 | $args{selectperl} ||= qr/^(?:$perlver|$mainperlver|$mainperlver\.\d+)$/; | ||
| 77 | |||
| 78 | |||
| 79 | # Accept running arch | ||
| 80 | my $arch = quotemeta( $Config::Config{archname} ); | ||
| 81 | _diag "Setting architecture to $Config::Config{archname}" | ||
| 82 | if not defined $args{selectarch}; | ||
| 83 | my $perlver_nodots = $mainperlver; | ||
| 84 | $perlver_nodots =~ s/\.//g; | ||
| 85 | $args{selectarch} ||= qr/^(?:$arch-?(?:$perlver_nodots\d*|$mainperlver(?:\.\d+)?)|$arch)$/; | ||
| 86 | |||
| 87 | _diag "Using temporary directory $tdir."; | ||
| 88 | _diag "Invoking PAR::Dist::FromPPD to create the .par file."; | ||
| 89 | |||
| 90 | PAR::Dist::FromPPD::ppd_to_par(%args); | ||
| 91 | |||
| 92 | _diag "Searching for generated .par file."; | ||
| 93 | |||
| 94 | _diag "chdir() to '$tdir'"; | ||
| 95 | my $cwd = Cwd::cwd(); | ||
| 96 | chdir($tdir); | ||
| 97 | |||
| 98 | opendir my $dh, '.' or die $!; | ||
| 99 | |||
| 100 | my @par_files = grep {-f $_ and /\.par$/i} readdir($dh); | ||
| 101 | |||
| 102 | _diag "Found PAR files: @par_files."; | ||
| 103 | |||
| 104 | _diag "Installing PAR files."; | ||
| 105 | |||
| 106 | foreach my $file (@par_files) { | ||
| 107 | _diag "Installing file '$file' with PAR::Dist::install_par()."; | ||
| 108 | PAR::Dist::install_par($file); | ||
| 109 | } | ||
| 110 | |||
| 111 | _diag "Done installing PAR files."; | ||
| 112 | |||
| 113 | chdir($cwd); | ||
| 114 | File::Path::rmtree([$tdir]); | ||
| 115 | return(1); | ||
| 116 | } | ||
| 117 | |||
| 118 | |||
| 119 | |||
| 120 | |||
| 121 | 1; | ||
| 122 | __END__ | ||