http://qs321.pair.com?node_id=198854

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

Hello,

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