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

filter: Statementstmt 0.0% 0 / 80 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 123 CC 7 SCAR 31.9
CC
7
Cov
0%
installDistrib
56.0
BEGIN
2.0
BEGIN
2.0
CRAP 24.2
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4  
5 use charnames ':full';
6 use Getopt::Long;
7 use Pod::Usage;
8  
9 use LWP::Simple qw/mirror/;
10 use IO::All;
11 use Archive::Tar;
12 use Module::Build;
13 use File::Temp qw/tempdir/;
14  
15 =head1 NAME
16  
17 hon-deploy-perl-distrib.pl
18  
19 =head1 DESCRIPTION
20  
21 Deploy perl module + bin + cgi
22  
23 =head1 VERSION
24  
25 Version 0.03
26  
27 =head1 USAGE
28  
29 hon-deploy-perl-distrib.pl --dist=path/to/HON-Deploy.tar.gz --dir-base=/path/to/base
30  
31 hon-deploy-perl-distrib.pl --dist=http://znverdi.hcuge.ch/~hondist/perl/dist/HON-Deploy.tar.gz --dir-base=/path/to/base
32  
33 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)
34  
35 =head1 REQUIRED ARGUMENTS
36  
37 =over 2
38  
39 =item --dist=/path/to/HON-Deploy.tar.gz
40  
41 Either file or url
42  
43 =item --dir-base=/path/to/base
44  
45 An absolute path where the module is to be installed
46  
47 =back
48  
49 =head1 OPTIONS
50  
51 =over 2
52  
53 =item --dir-cgi=/path/to/cgi
54  
55 An absolute path where the CGI scripts are to be installed
56  
57 =item --perl-interpreter=/path/to/perl
58  
59 Where the perl interpreter is installed
60  
61 =item --installdeps
62  
63 Install missing prerequisites
64  
65 =back
66  
67 =cut
68  
69 our $VERSION = '0.03';
70  
71 my ($help);
72 my ( $pDistSrc, $pDirBase, $pDirCgi, $perlInterpeter );
73 my ($installdeps);
74  
75 GetOptions(
76 'dist=s' => \$pDistSrc,
77 'dir-base=s' => \$pDirBase,
78 'dir-cgi=s' => \$pDirCgi,
79 'perl-interpreter=s' => \$perlInterpeter,
80 'installdeps' => \$installdeps,
81 'help' => \$help,
82 ) || pod2usage(2);
83  
84 if ( $help || !$pDirBase || !$pDistSrc ) {
85 pod2usage(1);
86 exit 0;
87 }
88  
89 foreach my $dSrc ( split /,/xms, $pDistSrc ) {
90 installDistrib(
91 src => $dSrc,
92 base => $pDirBase,
93 cgi => $pDirCgi,
94 installdeps => $installdeps
95 );
96 }
97  
98 sub installDistrib {
99 my %args = @_;
100 my $distSrc = $args{src};
101 my $dirBase = $args{base};
102 my $dirCgi = $args{cgi};
103  
104 my $tmpdir = tempdir( TEMPLATE => 'hon-deploy-XXXXXXXX', CLEANUP => 1 );
105  
106 my $distGz = "$tmpdir/dist.tgz";
107 warn "mirroring: $distSrc\n";
108 if ( $distSrc =~ /^(https?|ftp):\/\//xms ) {
109 mirror( $distSrc, $distGz );
110 }
111 else {
112 io($distSrc) > io($distGz);
113 }
114 my $tar = Archive::Tar->new;
115  
116 $tar->read($distGz);
117 $tar->setcwd($tmpdir);
118 $tar->extract();
119 my $distTmpir = "$tmpdir/" . ( split /\//xms, ( $tar->list_files() )[0] )[0];
120 warn "working dir: $distTmpir\n";
121 chdir $distTmpir;
122  
123 if ($perlInterpeter) {
124 my @scripts;
125 @scripts = grep { "$_" =~ /\N{ONE DOT LEADER}pl$/ixms } io('bin')->all()
126 if -d 'bin';
127  
128 push @scripts,
129 grep { "$_" =~ /\N{ONE DOT LEADER}(pl|cgi)$/ixms } io('cgi')->all()
130 if -d 'cgi';
131 foreach my $s (@scripts) {
132 system "chmod +w $s";
133 my $txt = io($s)->slurp;
134 $txt =~ s/^#!.*?\n/#!$perlInterpeter\n/xms;
135 io($s) < $txt;
136 system "chmod -w $s";
137 }
138 }
139  
140 my @cmd = ('perl Build.PL');
141 push @cmd, './Build installdeps' if $args{installdeps};
142 push @cmd, './Build test';
143  
144 my $installCmd = "./Build install --install_base $dirBase";
145 $installCmd .= " --install_path cgi=$dirCgi" if $dirCgi;
146 push @cmd, $installCmd;
147  
148 foreach my $cmd (@cmd) {
149 warn "$cmd\n";
150 system($cmd) && die 'cannot execute';
151 }
152 chdir $ENV{HOME};
153  
154 return;
155 }
156  
157 =head1 AUTHOR
158  
159 Alexandre Masselot, C<< <alexandre.masselot at gmail.com> >>
160  
161 William Belle, C<< <william.belle at gmail.com> >>
162  
163 =head1 BUGS AND LIMITATIONS
164  
165 Please report any bugs or feature requests to C<bug-hon-deploy at rt.cpan.org>, or through
166 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HON-Deploy>. I will be notified, and then you'll
167 automatically be notified of progress on your bug as I make changes.
168  
169 =head1 LICENSE AND COPYRIGHT
170  
171 This program is free software; you can redistribute it and/or modify it
172 under the terms of either: the GNU General Public License as published
173 by the Free Software Foundation; or the Artistic License.
174  
175 See http://dev.perl.org/licenses/ for more information.
176  
177 =cut