blib/script/hon-deploy-perl-distrib.pl untested

filter: Statementstmt 0.0% 0 / 70 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 11 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 104 SCAR 37.4
CC
6
Cov
0%
installDistrib
42.0
BEGIN
2.0
BEGIN
2.0
CRAP 42.0
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4  
5 use Getopt::Long;
6 use Pod::Usage;
7  
8 use LWP::Simple qw/mirror/;
9 use IO::All;
10 use Archive::Tar;
11 use Module::Build;
12 use File::Temp qw/tempdir/;
13  
14 =head1 NAME
15  
16 hon-deploy-mirror.pl
17  
18 =head1 DESCRIPTION
19  
20 deploy the mirror perl module + bin + cgi
21  
22 =head1 SYNOPSIS
23  
24 ./hon-deploy-perl-distrib.pl --dist=path/to/HON-Http-Mirror.tar.gz --dir-bin=/path/to/bin --dir-lib=/path/to/lib --dir-cgi=/path/to/cgi
25
26 ./hon-deploy-perl-distrib.pl --dist=http://znverdi.hcuge.ch/~hondev/perl/dist/HON-Http-Mirror-latest.tar.gz --dir-bin=/tmp/mirror-dist/bin --dir-lib=/tmp/mirror-dist/lib
27
28 ./hon-deploy-perl-distrib.pl --dist=http://znverdi.hcuge.ch/~hondist/perl/dist/HON-Utils-latest.tar.gz,http://znverdi.hcuge.ch/~hondist/perl/dist/HON-Http-Mirror-latest.tar.gz --dir-base=$HOME/perl --dir-cgi=$HOME/public_html/cgi-bin --perl-interpreter=$(which perl)
29
30 =head1 ARGUMENTS
31  
32 =over 2
33  
34 =item --dist=/path/to/HON-Http-Mirror-x.yy.tar.gz
35  
36 Either file or url
37  
38 =item --dir-base=/path/to/base
39  
40 Where the default per is to be deployed are to be installed
41  
42  
43 =back
44  
45 =head1 OPTIONS
46  
47 =over 2
48  
49 =item --dir-cgi=/path/to/cgi
50  
51 Where the CGI scripts are to be installed
52  
53 =back
54  
55 =cut
56  
57 my ($help);
58 my ( $pDistSrc, $pDirBase, $pDirCgi, $perlInterpeter );
59  
60 GetOptions(
61 "dist=s" => \$pDistSrc,
62 "dir-base=s" => \$pDirBase,
63 "dir-cgi=s" => \$pDirCgi,
64 "perl-interpreter=s" => \$perlInterpeter,
65 "help" => \$help,
66 )
67 || pod2usage(2);
68  
69 if ( $help || !$pDirBase || !$pDistSrc ) {
70 pod2usage(1);
71 exit(0);
72 }
73  
74 foreach my $dSrc ( split( /,/, $pDistSrc ) ) {
75 installDistrib( src => $dSrc, base => $pDirBase, cgi => $pDirCgi );
76 }
77  
78 sub installDistrib {
79 my %args = @_;
80 my $distSrc = $args{src};
81 my $dirBase = $args{base};
82 my $dirCgi = $args{cgi};
83  
84 my $tmpdir = tempdir(TEMPLATE=>'hon-deploy-XXXXXXXX', CLEANUP => 1 );
85  
86 my $distGz = "$tmpdir/dist.tgz";
87 warn "mirroring: $distSrc\n";
88 if ( $distSrc =~ /^(https?|ftp):\/\// ) {
89 mirror( $distSrc, $distGz );
90 }
91 else {
92 io($distSrc) > io($distGz);
93 }
94 my $tar = Archive::Tar->new;
95  
96 $tar->read($distGz);
97 $tar->setcwd($tmpdir);
98 $tar->extract();
99 my $distTmpir = "$tmpdir/" . ( split( /\//, ( $tar->list_files() )[0] ) )[0];
100 warn "working dir: $distTmpir\n";
101 chdir($distTmpir);
102  
103 if($perlInterpeter){
104 my @scripts;
105 @scripts= grep {"$_" =~/\.pl$/i} io('bin')->all() if -d 'bin';
106
107 push @scripts, grep {"$_" =~/\.(pl|cgi)$/i} io('cgi')->all() if -d "cgi";
108 foreach my $s (@scripts){
109 system "chmod +w $s";
110 my $txt = io($s)->slurp;
111 $txt=~s/^#!.*?\n/#!$perlInterpeter\n/s;
112 io($s)<$txt;
113 system "chmod -w $s";
114 }
115 }
116  
117 my @cmd = ( 'perl Build.PL', './Build test', "./Build install --install_base $dirBase" );
118 $cmd[2] .= " --install_path cgi=$dirCgi" if $dirCgi;
119  
120 foreach my $cmd (@cmd) {
121 warn "$cmd\n";
122 system($cmd) && die "cannot execute";
123 }
124 chdir( $ENV{HOME} );
125 }