blib/lib/VFSsimple/Drv/Iso.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 83 CC 5 SCAR 20.4
CC
5
Cov
0%
drv_copy
20.0
drv_new
6.0
drv_stat
2.0
CRAP 7.7
1 package VFSsimple::Drv::Iso;
2  
3 use strict;
4 use warnings;
5 use Device::Cdio::ISO9660;
6 use Device::Cdio::ISO9660::IFS ();
7 use File::Temp qw(tempfile);
8 use POSIX;
9 use base qw(VFSsimple::Base);
10  
11 our $VERSION = '0.03';
12  
13 =head1 NAME
14  
15 VFSsimple::Drv::Iso - A VFSsimple implementation over ISO9660 fs
16  
17 =head1 DESCRIPTION
18  
19 This module provide access method for VFSsimple module to access to files
20 inside ISO9660 CD image.
21  
22 Access is provide using L<Device::Cdio::ISO9660> module.
23  
24 =cut
25  
26 sub drv_new {
27 my ($self) = @_;
28 my $iso = Device::Cdio::ISO9660::IFS->new(-source => $self->archive_path);
29 $self->{iso} = $iso or return;
30 $self->{prefix} = $self->archive_subpath || '';
31  
32 return $iso ? $self : ();
33 }
34  
35 sub drv_copy {
36 my ($self, $src, $dest) = @_;
37 open(my $fh, '>', $dest) or return;
38 my $iso = $self->{iso};
39 my $stat = $iso->stat("$self->{prefix}/$src", 0) or return;
40 if ($stat) {
41 my $blocks = POSIX::ceil($stat->{size} / $perlcdio::ISO_BLOCKSIZE);
42 for (my $i = 0; $i < $blocks; $i++) {
43 my $lsn = $stat->{LSN} + $i;
44 my $buf = $iso->seek_read ($lsn);
45 if (defined($buf)) {
46 print $fh (($i + 1) * $perlcdio::ISO_BLOCKSIZE > $stat->{size}) ?
47 substr($buf, 0, $stat->{size} - ($i + 1) * $perlcdio::ISO_BLOCKSIZE) :
48 $buf;
49  
50 } else {
51 return;
52 }
53 }
54 }
55 close($fh);
56 return $dest;
57 }
58  
59 sub drv_stat {
60 my ($self, $file) = @_;
61 my $iso = $self->{iso};
62 return(defined($iso->stat("$self->{prefix}/$file", 0)));
63 }
64  
65 1;
66  
67 __END__