Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Cannot overload ++ when the object is accessed via Attribute -> Tie -> Class

by Anno (Deacon)
on Oct 03, 2007 at 13:19 UTC ( [id://642396]=note: print w/replies, xml ) Need Help??


in reply to Cannot overload ++ when the object is accessed via Attribute -> Tie -> Class

My, my my. Overload, wrapped in a tie, wrapped in an attribute. That doesn't make debugging easier. If you have trouble with such a setup, you need to peel back the various layers and test each one separately, first overloading, then the tie interface, then the attribute wrapper.

I wonder whether there is a way to overload the ++ operator or not.

The increment operator *is* overloaded as systematic testing shows. The problem is that the TieStringifiableInteger::STORE method is called with the stringified version of the new value instead of the numeric one. (No, I don't know offhand why that happens.) Change it to

sub STORE { my ($self, $value) = @_; $$self->set(0 + $value); }
That forces the numeric value and fixes the error.

As a side note, is there a reason why two of the overloading functions ('""' and '0+') are named methods but '++' is implemented anonymously?

What is your opinion on such a module? Is it worth uploading to CPAN? A note; I am designing to module to add stringification for different languages.

In my view, the module has an overly involved interface to call a function automatically that would better be called explicitly from case to case. The basic function (converting numbers to strings) is already covered by CPAN modules for various langiages, including Turkish (Lingua::TR::Numbers)

Anno

Replies are listed 'Best First'.
Re^2: Cannot overload ++ when the object is accessed via Attribute -> Tie -> Class
by mayaTheCat (Scribe) on Oct 03, 2007 at 13:59 UTC
    Thanks for the solution; it worked.

    Reply for the side note: the function being anonymous was just temporary. Since there is a solution now, the function has the right to have a name :)

    Finally, thanks for the CPAN alternatives.

    My motive in developing this module is to play with Attributes.

    Oguz

    ---------------------------------
    life is ... $mutation = sub { $_[0] =~ s/(.)/rand()<0.1?1-$1:$1/ge };

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-20 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found