File Coverage

blib/lib/HTML/EP/Install.pm
Criterion Covered Total %
statement 21 39 53.8
branch 0 18 0.0
condition 0 2 0.0
subroutine 7 11 63.6
pod 0 3 0.0
total 28 73 38.3


line stmt bran cond sub pod time code
1             # -*- perl -*-
2              
3 1     1   1306 use strict;
  1         3  
  1         37  
4 1     1   6 use File::Path ();
  1         2  
  1         15  
5 1     1   5 use File::Find ();
  1         1  
  1         22  
6 1     1   1037 use File::Copy ();
  1         2882  
  1         27  
7 1     1   8 use File::Spec ();
  1         2  
  1         15  
8 1     1   6 use Cwd();
  1         3  
  1         34  
9              
10              
11             package HTML::EP::Install;
12              
13 1     1   21 use vars qw($VERSION $install_files $install_cgi_files);
  1         2  
  1         473  
14              
15             $VERSION = '0.02';
16             $install_files = '\.(?:html?|ep|gif|jpe?g)$';
17             $install_cgi_files = '\.(?:cgi|pl)$';
18              
19              
20             sub InstallFiles {
21 0 0   0 0   my($fromDir, $toDir, $extension, $mode) = @_ ? @_ : @ARGV;
22 0 0         $mode = 0644 unless $mode;
23 0           my $current_dir = Cwd::cwd();
24 0 0         chdir $fromDir || die "Failed to change directory to $fromDir: $!";
25             my $copySub = sub {
26 0 0   0     return unless $_ =~ /$extension/;
27 0           my $file = $_;
28 0           my $target_dir = File::Spec->catdir($toDir, $File::Find::dir);
29 0 0 0       (File::Path::mkpath($target_dir, 0, 0755)
30             or die "Failed to create $target_dir: $!")
31             unless -d $target_dir;
32 0           my $target_file = File::Spec->catfile($target_dir, $file);
33 0 0         File::Copy::copy($file, $target_file)
34             || die "Failed to copy $File::Find::name to $target_file: $!";
35 0           chmod($mode, $target_file);
36 0           };
37 0           File::Find::find($copySub, ".");
38 0 0         chdir $current_dir || die "Failed to change directory to $current_dir: $!";
39             }
40              
41             sub InstallHtmlFiles {
42 0 0   0 0   my($fromDir, $toDir) = @_ ? @_ : @ARGV;
43 0           InstallFiles($fromDir, $toDir, $install_files);
44             }
45              
46             sub InstallCgiFiles {
47 0 0   0 0   my($fromDir, $toDir) = @_ ? @_ : @ARGV;
48 0           InstallFiles($fromDir, $toDir, $install_cgi_files, 0755);
49             }