Front page | perl.perl5.porters |
Postings from April 2000
'=' in Overload Question
From:
jpeacock
Date:
April 20, 2000 06:44
Subject:
'=' in Overload Question
Message ID:
0004209562.AA956238926@univpress.com
I have a question regarding the Overload module and why the '=' does not
overload the assignment operator. There is mention that this would 'rub the
Camel hair the wrong way' but not why Tie is allowed to do that exact thing.
I would like to bless an object and then have the option of overloading the
assigment operator so that I could do something like this:
Datatype::Date->format("MMM-DD-YYYY");
$mydate = Datatype::Date->new();
..
$mydate = '12/31/98'; # Does not alter $mydate's bless'dness
..
print $mydate; # prints Dec-31-1998
Tie'd objects get the STORE method where they can interpret the incoming data in
the appropriate way for that object. Why is this not available to Overload? If
I go to the effort of blessing an object into a class, why can't I decide for
myself whether I want to let Perl trump my blessing and stomp on my object?
Obviously if I do not chose to overload the assignment, the fallback would be
the current behavior.
The example above is obviously trivial; what I really want to do is tag several
scalars as special and then assign to a group of scalars from a DBI query all at
once. With the existing code, I need to re-bless each special scalar after the
assignment (this is actual code):
( $po_number, $original_amt, $discount_1, $payments, $credit_amt,
$last_pay_date, $transaction_dt, $closed ) = $COI->fetchrow_array;
$original_amt = Money($original_amt);
$discount_1 = Money($discount_1);
$payments = Money($payments);
$credit_amt = Money($credit_amt);
$last_pay_date = Date($last_pay_date);
$transaction_dt = Date($transaction_dt);
Please enlighten me as to the error of my ways, or point me at a FAQ that might
cover this.
Thanks in Advance
John Peacock