Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Do Storable and IO::Zlib like to play together?

by sauoq (Abbot)
on Nov 03, 2005 at 19:32 UTC ( #505487=note: print w/replies, xml ) Need Help??


in reply to Do Storable and IO::Zlib like to play together?

Solving this is going to take some effort. Here is a small piece of code that reproduces the error:

#!/usr/bin/perl use Storable qw(nstore_fd fd_retrieve); use IO::Zlib; use Data::Dumper; my $test = { foo => "bar" }; my $fh = IO::Zlib->new("out.gz", "wb"); nstore_fd($test, $fh); $fh->close; my $fh2 = IO::Zlib->new("out.gz", "rb"); my $href = fd_retrieve($fh2); $fh2->close; print Dumper $href;

The error (message) is the same but I'm not positive the error itself is. In particular, $AUTOLOAD in this instance is IO::Zlib::FILENO (not READ) and it is being called from Storable::_store_fd (which is in _store_fd.al) which is in turn being called by Storable::nstore_fd (in nstore_fd.al)... But, going back and printing the argument when in each of those functions shows it to be IO::Zlib=GLOB(0x81242f8) which is a glob ref as desired. It is only when we get to Zlib's AUTOLOAD that it prints as IO::Zlib=HASH(0x81b84b8). So, it looks like the call to fileno() in _store_fd() is where things are breaking.

And, sure enough...

perl -MIO::Zlib -e '$fh = IO::Zlib->new("test.gz", "wb"); print fileno +($fh)'
That's a minimal demonstration of the problem. (So, you can stop looking at Storable as the real problem, anyway.)

Adding some quick prints to see what's going on...

sub AUTOLOAD { print "AUTOLOAD(@_)\n"; my $self = shift; print $self, " $AUTOLOAD\n@{[caller]}\n"; $AUTOLOAD =~ s/.*:://; $AUTOLOAD =~ tr/a-z/A-Z/; return tied(*{$self})->$AUTOLOAD(@_); }
And running that:
$ perl -MIO::Zlib -e '$fh = IO::Zlib->new("test.gz", "wb"); print file +no($fh)' AUTOLOAD(IO::Zlib=HASH(0x81e8b30)) IO::Zlib=HASH(0x81e8b30) IO::Zlib::FILENO main -e 1 Not a GLOB reference at /usr/lib/perl5/site_perl/5.8.0/IO/Zlib.pm line + 566.
Changing fileno($fh) to $fh->fileno results in:
$ perl -MIO::Zlib -e '$fh = IO::Zlib->new("test.gz", "wb"); print $fh- +>fileno' AUTOLOAD(IO::Zlib=GLOB(0x8124538)) IO::Zlib=GLOB(0x8124538) IO::Zlib::fileno main -e 1 AUTOLOAD(IO::Zlib=HASH(0x81e8b3c)) IO::Zlib=HASH(0x81e8b3c) IO::Zlib::ILENO IO::Zlib /usr/lib/perl5/site_perl/5.8.0/IO/Zlib.pm 566 Not a GLOB reference at /usr/lib/perl5/site_perl/5.8.0/IO/Zlib.pm line + 566.
Ick! Where's that "IO::Zlib::ILENO" coming from?

Oh well, that's where I'm at now. I've got to set it down for a bit as I have real paying work to do. :-) Maybe you or someone else would like to pick up there. I'll look deeper later on if no one else nails it.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re^2: Do Storable and IO::Zlib like to play together?
by fokat (Deacon) on Nov 03, 2005 at 19:52 UTC

    Thanks sauoq.

    That's a minimal demonstration of the problem.

    Yep. I guess we arrived to the problem quite close. IO::Zlib does not seem to implement fileno. But even after faking it (as shown in my Updated node), there is something else going bad.

    (So, you can stop looking at Storable as the real problem, anyway.)

    Well, I don't understand why Storable wants to verify that it got a real handle. It should try to do its thing with whatever it got as an argument.

    But in this case, this does not look like the cause.

    Best regards

    -lem, but some call me fokat

      IO::Zlib does not seem to implement fileno.

      That's not really the problem, I don't think. At least, not the first one. We are never getting out of AUTOLOAD routine (and not because a method is missing.) The problem is that a call to fileno() doesn't play well with the tied handle provided by IO::Zlib.

      It should try to do its thing with whatever it got as an argument.

      That's debatable. I'd be inclined to do it Storable's way.

      -sauoq
      "My two cents aren't worth a dime.";
      

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://505487]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2020-11-30 14:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?