Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

How to make an IO::Uncompress::Bunzip2 look like a GLOB

by Pascal666 (Scribe)
on Aug 18, 2009 at 00:15 UTC ( #789312=perlquestion: print w/replies, xml ) Need Help??

Pascal666 has asked for the wisdom of the Perl Monks concerning the following question:

I would like to use a Perl Module that takes a file handle as a parameter. It verifies it is passed a file handle using the code "if (ref($file) eq 'GLOB')". Instead of passing it a file handle, I would like to pass it an object of type IO::Uncompress::Bunzip2. This object behaves like a file handle and works perfectly with the module, if I modify its code to bypass the GLOB check. Is there a way I can modify my object such that ref() will return "GLOB" instead of "IO::Uncompress::Bunzip2"? Thank you in advance for your assistance.
  • Comment on How to make an IO::Uncompress::Bunzip2 look like a GLOB

Replies are listed 'Best First'.
Re: How to make an IO::Uncompress::Bunzip2 look like a GLOB
by Anonymous Monk on Aug 18, 2009 at 01:08 UTC
      I believe your reply contains suggestions for modifying the "if" inside the Perl Module. My question was actually how to modify the object I am passing the module such that it would pass the existing "if" inside the module, so that I do not have to modify the third party module.
        The 3rd party module has a giant bug, it needs to be fixed. But
        { local @GLOB::ISA = ref $obj; bless $obj, 'GLOB'; broken_module($obj); bless $obj, @GLOB::ISA; }

      The statement:

      if(UNIVERSAL::can($file,'print')){...}

      does not appear to work. I have tried passing it both a string and a GLOB and it never seems to evaluate to true.

        Ouch, then  *{$file}{IO}, see *glob{FILEHANDLE}

        Probably the best idea is to simply try to use $file without checking what it is

        $file->print('asdf');

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2020-10-24 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (242 votes). Check out past polls.

    Notices?