Skip Menu |

This queue is for tickets about the PAR CPAN distribution.

Report information
The Basics
Id: 35821
Status: stalled
Priority: 0/
Queue: PAR

People
Owner: Nobody in particular
Requestors: jettero [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



I have a blib/lib that contains an XML DTD file that I'd like to include in a .par archive. It'd be darned convenient if I could return a filehandle to XML::Parser directly from the PAR:: namespace without having to grab the par and zip handles. It'd probably look something like this. (An alternate more flexible version might be get_member() and then I could just call fh() on that. sub get_filehandle { my $file = pop; foreach my $zip (@LibCache) { my $member = _first_member($zip, $file) or next; return $member->fh(); } return; } I'd put it right above this function. sub read_file { my $file = pop; foreach my $zip (@LibCache) { my $member = _first_member($zip, $file) or next; return scalar $member->contents; } return; }
Your proposed function will be in the next PAR release. Cheers, Steffen
Hi again, On Mon May 12 16:00:57 2008, http://voltar.org/jet/ wrote: Show quoted text
> I have a blib/lib that contains an XML DTD file that I'd like to include > in a .par archive. It'd be darned convenient if I could return a > filehandle to XML::Parser directly from the PAR:: namespace without > having to grab the par and zip handles. It'd probably look something > like this. (An alternate more flexible version might be get_member() > and then I could just call fh() on that. > > sub get_filehandle { > my $file = pop; > > foreach my $zip (@LibCache) { > my $member = _first_member($zip, $file) or next; > return $member->fh(); > } > > return; > }
Unfortunately, it turns out that this doesn't work. Archive::Zip is kind of broken. $member->fh() returns a file handle to the zip file... So what one could do is add the following function: sub find_zip_member { my $file = pop; foreach my $zip (@LibCache) { my $member = _first_member($zip, $file) or next; return $member; } return; } And given the member, one can: my $memberRead = PAR::find_zip_member("my/file.txt")->readFileHandle(); # $memberRead is now an Archive::Zip::MemberRead # object, not a FileHandle object! while (defined($_ = $memberRead->getline()) { # do stuff } Now, I know that's not what you want. You want a real file handle for XML::Parser to process, but that's, as far as I know, not possible with Archive::Zip as it stands. I think in principle, you could modify The Archive::Zip::MemberRead class (which is already a bit of a special case in Archive::Zip) so that the object acts as a tied filehandle. But that's out of scope of PAR. Let me know whether you'd want such a function find_zip_member. If Archive::Zip::MemberRead objects were tied file handles, you could have your get_filehandle or find_filehandle or similar function, of course. Best regards, Steffen