Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Local tied methods refering to others

by herby1620 (Monk)
on Jan 23, 2006 at 22:38 UTC ( [id://525069]=perlquestion: print w/replies, xml ) Need Help??

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

Well, now I've done it. Using Perl/Tk, I have found out how to 'tie' STDOUT to a package. Normally this is the 'Text' module, as it supplies FILEHANDLE, PRINT, PRINTF. Now I want to intercede and do some magic of my own after Text's function with my own 'package'. The normal 'tie' is:
tie *STDOUT, Tk::Text, $text; # '$text' is a Text widgit.
What do I need to write in my own 'package' to refer to these actions? I've played around, and it seems very confusing! I guess I want to do something like:
tie *STDOUT, MyMagic, $text;
Which sounds OK to me, but what should I do after 'package MyMagic' to effect calls to the original methods? Thanks!

Replies are listed 'Best First'.
Re: Local tied methods refering to others
by davido (Cardinal) on Jan 24, 2006 at 07:16 UTC

    I was hooked on playing with tie for awhile a year or so ago, and implemented a few tied filehandle classes to see what I could make of it all. There is some good information in perltie, where it states: "A class implementing a tied filehandle should define the following methods: TIEHANDLE, at least one of PRINT, PRINTF, WRITE, READLINE, GETC, READ, and possibly CLOSE, UNTIE and DESTROY."

    Also, a generic tied-handle class from which you can learn as well as derive your own tied handle classes comes with the standard Perl distribution as Tie::Handle (and Tie::StdHandle). It's documented here: Tie::Handle. I found it helpful to read through its framework to gather tips on how to write my own tied filehandle class. But it's also useful to know that Tie::Handle defines all of the necessary methods for a tied handle class. The idea is that you can make your own handle class a subclass of Tie::Handle, and then only go the work of overriding those methods that you wish to customize for your own purposes.


    Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://525069]
Approved by Paladin
Front-paged by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 07:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found