Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Tying objects

by shmem (Chancellor)
on Feb 08, 2009 at 11:29 UTC ( #742248=note: print w/replies, xml ) Need Help??

in reply to Tying objects

A tied scalar shadows an object whose class provides methods for creation, assignment and destruction. The tied scalar behaves like a scalar, so you can neither bless it into a package, nor call methods on it (would need to be blessed, first).

You are pretty out of luck if you want to use the same thingy as a scalar and an object at the same time. Your FETCH would need to know what the fetch is for - not just void/scalar/list context, but look ahead in the opstack to see whether the result it is about to return is for a method deref. I'm sure that can be done somehow (TheDamian, would you like to? ;-), but it probably would involve too much magic...

Use the object returned by tie to do method calls:

use Link; my $var_o = tie my $var,"Link",""; $var = ""; $var_o->print_method; print $var;

Or what Arunbear said.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2023-09-22 09:05 GMT
Find Nodes?
    Voting Booth?

    No recent polls found