File Coverage

blib/lib/Archive/Zip/DirectoryMember.pm
Criterion Covered Total %
statement 42 47 89.3
branch 8 12 66.6
condition 1 3 33.3
subroutine 9 11 81.8
pod 5 5 100.0
total 65 78 83.3


line stmt bran cond sub pod time code
1             package Archive::Zip::DirectoryMember;
2              
3 28     28   157 use strict;
  28         55  
  28         678  
4 28     28   129 use File::Path;
  28         49  
  28         1286  
5              
6 28     28   127 use vars qw( $VERSION @ISA );
  28         54  
  28         1248  
7              
8             BEGIN {
9 28     28   131 $VERSION = '1.67';
10 28         986 @ISA = qw( Archive::Zip::Member );
11             }
12              
13 28         13375 use Archive::Zip qw(
14             :ERROR_CODES
15             :UTILITY_METHODS
16 28     28   164 );
  28         47  
17              
18             sub _newNamed {
19 17     17   36 my $class = shift;
20 17         30 my $fileName = shift; # FS name
21 17         47 my $newName = shift; # Zip name
22 17 100       75 $newName = _asZipDirName($fileName) unless $newName;
23 17         145 my $self = $class->new(@_);
24 17         48 $self->{'externalFileName'} = $fileName;
25 17         89 $self->fileName($newName);
26              
27 17 100       278 if (-e $fileName) {
28              
29             # -e does NOT do a full stat, so we need to do one now
30 15 50       46 if (-d _ ) {
31 15         55 my @stat = stat(_);
32 15         71 $self->unixFileAttributes($stat[2]);
33 15         29 my $mod_t = $stat[9];
34 15 50 33     84 if ($^O eq 'MSWin32' and !$mod_t) {
35 0         0 $mod_t = time();
36             }
37 15         64 $self->setLastModFileDateTimeFromUnix($mod_t);
38              
39             } else { # hmm.. trying to add a non-directory?
40 0         0 _error($fileName, ' exists but is not a directory');
41 0         0 return undef;
42             }
43             } else {
44 2         22 $self->unixFileAttributes($self->DEFAULT_DIRECTORY_PERMISSIONS);
45 2         18 $self->setLastModFileDateTimeFromUnix(time());
46             }
47 17         56 return $self;
48             }
49              
50             sub externalFileName {
51 0     0 1 0 shift->{'externalFileName'};
52             }
53              
54             sub isDirectory {
55 37     37 1 83 return 1;
56             }
57              
58             sub extractToFileNamed {
59 12     12 1 25 my $self = shift;
60 12         20 my $name = shift; # local FS name
61 12         46 my $attribs = $self->unixFileAttributes() & 07777;
62 12         768 mkpath($name, 0, $attribs); # croaks on error
63 12         70 utime($self->lastModTime(), $self->lastModTime(), $name);
64 12         55 return AZ_OK;
65             }
66              
67             sub fileName {
68 320     320 1 1820 my $self = shift;
69 320         380 my $newName = shift;
70 320 100       695 $newName =~ s{/?$}{/} if defined($newName);
71 320         823 return $self->SUPER::fileName($newName);
72             }
73              
74             # So people don't get too confused. This way it looks like the problem
75             # is in their code...
76             sub contents {
77 0 0   0 1   return wantarray ? (undef, AZ_OK) : undef;
78             }
79              
80             1;