rr has asked for the wisdom of the Perl Monks concerning the following question:
I have a class called 'Datum' that implements the tied scalar interface. This class's constructor returns a tied scalar ref at present. This means that in my code, the returned scalar object must be dereferenced as '$$scalar'.
The $$ dereferencing is the problem.
I would like to write a method, module, C extension, or whatever it takes to have the class's new method return an object that may be used exactly as if it were a scalar, but this new magic variable also accepts method invocation and and supports running my code on STORE FETCH etc. I guess this might even be considered a new variable type, based on scalar.
I know that I can tie the scalar to my Datum class all over my code, but that's very tedious as there are hundreds of them in my programs
eg.
use Datum; my $d = Datum->new(-type => date); $d = "Nov 25, 1971"; print STDOUT "\$d contains $d"; # "Nov 25, 1971" print STDOUT "\$d as unixtime:", $d->to_unixtime, "\n"; exit 0;
Is this possible in perl5? Would I have to write an XS module instead?
Thanks!
rr
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How might I return tied scalar that does not have to be dereferenced as $$scalar?
by chromatic (Archbishop) on Sep 18, 2002 at 15:59 UTC | |
(tye)Re: How might I return tied scalar that does not have to be dereferenced as $$scalar?
by tye (Sage) on Sep 18, 2002 at 16:14 UTC | |
Re: How might I return tied scalar that does not have to be dereferenced as $$scalar?
by fglock (Vicar) on Sep 18, 2002 at 16:22 UTC | |
Re: How might I return tied scalar that does not have to be dereferenced as $$scalar?
by dada (Chaplain) on Sep 20, 2002 at 12:12 UTC | |
by rr (Sexton) on Sep 23, 2002 at 17:01 UTC |