How can I define pre/post-increment behavior in Perl objects?

Posted by Zaid on Stack Overflow See other posts from Stack Overflow or by Zaid
Published on 2010-05-03T05:59:34Z Indexed on 2010/05/03 6:08 UTC
Read the original article Hit count: 334

Filed under:
|
|

Date::Simple objects display this behavior. In the case of Date::Simple objects, $date++ returns the next day's date.

Date::Simple objects are immutable. After assigning $date1 to $date2, no change to $date1 can affect $date2. This means, for example, that there is nothing like a set_year operation, and $date++ assigns a new object to $date.

How can one custom define the pre/post-incremental behavior of an object, such that ++$object or $object-- performs a particular action?

I've skimmed over perlboot, perltoot, perltooc and perlbot, but I don't see any examples showing how this can be done.

© Stack Overflow or respective owner

Related posts about perl

Related posts about object