package Archive::Zip::MemberRead::FH; use strict; #use parent 'Tie::Handle'; use base 'Tie::Handle'; use Archive::Zip::MemberRead; =head1 NAME Archive::Zip::MemberRead::FH - readonly filehandle for zip members =head1 SYNOPSIS require Archive::Zip; require Archive::Zip::MemberRead::FH; my $ar = Archive::Zip->new(); my $file = 'test.zip'; $ar->read($file) == Archive::Zip::AZ_OK() or die "Couldn't read '$file': $!"; my @members = $ar->members(); print "Reading first file from '$file'\n"; $fh = Archive::Zip::MemberRead::FH->new($members[0]); while (<$fh>) { ... }; =head1 NOTES This is a very crude wrapper that tries to dress up a L as a read-only filehandle. =head1 METHODS =head2 C<< ->new ReadMember >> The C<< ->new >> constructor takes the same arguments as LC<< ->new >>, but returns a filehandle instead of an object. =cut sub new { my $class = shift; local *ZIPFH; tie *ZIPFH, $class, @_; return *ZIPFH }; =head2 C<< ->readmember >> The C<< ->readmember >> function allows access to the underlying L. =cut sub readmember { my ($glob) = @_; $$glob }; sub TIEHANDLE { my $class = shift; my $m = Archive::Zip::MemberRead->new(@_); return bless \$m, $class; }; sub reflect { my ($name,$args) = @_; my $glob = shift @$args; my $self = $glob->readmember; unshift @$args, $self; return $self->can($name); }; =head1 FUNCTIONALITY The following functionality is implemented for the filehandle: =cut =head2 C< read > Reading octets into a buffer, using the C<< ->read >> method of the underlying ReadMember object. =cut sub READ { goto &{ reflect('read', \@_) } }; =head2 C< readline > Reading lines into a buffer, using the C<< ->getline >> method of the underlying ReadMember object. No special provision for treating C<$/> properly is made, the default behaviour of the underlying ReadMember applies. =cut sub READLINE { goto &{ reflect('getline', \@_)} }; =head2 C< close > Closes the filehandle, using the C<< ->close >> method of the underlying ReadMember object. =cut sub CLOSE { goto &{ reflect('close', \@_)} }; =head2 C< binmode > Not implemented =cut #sub BINMODE { goto reflect('binmode', \@_) }; =head2 C< eof > Not implemented =cut #sub EOF { goto reflect('eof', \@_)}; 1; __END__ =head1 AUTHOR Max Maischein L =head1 COPYRIGHT This file is copyright (2009) Max Maischein L This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut