develooper Front page | perl.perl5.porters | Postings from May 2003

Re: Can I OVERLOAD the assignment operator? Please???

Thread Previous | Thread Next
Nick Ing-Simmons
May 24, 2003 12:48
Re: Can I OVERLOAD the assignment operator? Please???
Message ID:
John Peacock <> writes:
>Dan Sugalski wrote:
>> What I'm in favor of is getting overloading and tying working together. 
>> I still think the two should remain separate, with assignment living in 
>> the tie part. I don't have the tuits to throw at it, unfortunately.
>I'm not sure how that would work.  Would you tie the blessed object or bless the 

No ;-) - you tie the variable and bless the value.
What it means in practice (probably) is SV gets both kinds of magic.

>The OO interface (overloading) has to be dominant, so that the correct 
>method gets called with the correct object[s].

They are both OO interfaces.

>FETCH could naturally be mapped to numify()/stringify() based on context, 

But there is no context to a FETCH.

>suppose, but the overloading already does that now.  STORE is the only piece 
>missing from the possible overload methods.

No - they should remain distinct - they might be different packages:

tie $foo,'SomeThing'
$foo = OverLoaded->new;

What has to happen in the general case is that you need call mg_get() 
for the tie which will call FETCH and _then_ do the overload thing on the 
SV's magic at that point.
Finally do mg_set() to do STORE.

IIRC it nearly works. The FETCH happens - but the overloaded-ness of 
the FETCHed value is not honoured.

>Would you be more favorably inclined towards an overload::Tied module which 
>added a Tie-like interface to overloaded objects?

Not really.

Nick Ing-Simmons

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About