develooper Front page | perl.perl5.porters | Postings from August 2008

Re: Near-FMTEYEWTK instructorial on ties, handles, and methods (was: How to tell whether readline got an error or EOF)

Thread Previous
From:
Ben Morrow
Date:
August 2, 2008 15:48
Subject:
Re: Near-FMTEYEWTK instructorial on ties, handles, and methods (was: How to tell whether readline got an error or EOF)
Message ID:
uc4fm5-t821.ln1@osiris.mauzo.dyndns.org

Quoth tchrist@perl.com (Tom Christiansen):
> 
[snippety: tied handles vs IO::Handle]
>
> Just because I can say 
> 
>     print CALC "$sum\n"
> 
> with the object in dative position, and thanks to the tie, get the sub
> Tie::Open2::PRINT invoked on the tied(CALC) object, does *NOT* mean I can
> also turn around and call CALC->error() or CALC->clearerr() and expect
> *that* to (miraculously) get at the IO::Handle methods of those names.
> Why?  Lots of reasons, but for one, it's because *that* compiles into
> "CALC"->error(), and there's not even a CALC class to be found, that's why.

No, it doesn't; not if there's a *CALC{IO} filehandle in scope and no
CALC:: package or &CALC sub. Otherwise STDIN->error() wouldn't work
either.

You can override what CALC->error() returns by reblessing *CALC{IO} into
a new subclass of IO::Handle (well, it doesn't have to be a subclass,
but it's probably a good idea if it is).

Ben

-- 
#!/bin/sh
quine="echo 'eval \$quine' >> \$0; echo quined"
eval $quine
#                                                        [ben@morrow.me.uk]

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About