develooper Front page | perl.perl5.porters | Postings from July 2005

Creating your own FH interface -- intended behavour?

Thread Next
From:
Jos I. Boumans
Date:
July 25, 2005 03:55
Subject:
Creating your own FH interface -- intended behavour?
Message ID:
3ed48534ca94bfe95a937538841a32aa@xs4all.net
Hi,

i was happily programming along, and in the course of events found the 
need to have
an FH like interface, with a custom backend. I found that these two 
invocations, on
the same object do not produce the same result:

	$obj->readline vs <$obj>

It only does what i expect in the former case, not the latter:

     sub X::readline { 1 };
     $x = bless {}, 'X';
     print "rl ". $x->readline . $/;
     print "<> ". <$x> . $/;
     rl 1
     Not a GLOB reference at - line 4.

As it seems, it calls the builtin readline() on <>, rather than the 
class' readline():

     BEGIN { *CORE::GLOBAL::readline = sub { 2 }; }
     sub X::readline { 1 };
     $x = bless {}, 'X';
     print "rl ". $x->readline . $/;
     print "<> ". <$x> . $/;
     rl 1
     <> 2

This doens't seem to DWIM. And although i've now found how i can make 
happen what
i want, it seems an inelegant solution at best.

Any thoughts?

--

Jos Boumans

	I won't insult your intelligence by suggesting that you
	really believe what you just said.
            --William Buckley, Jr.

	CPANPLUS	http://cpanplus.sf.net

Thread Next


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