[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] Class::Date - change once set



On Nov 11, 2005, at 3:06 AM, Balázs Szabó (dLux) wrote:
   $x = $_[0];

$x is created, a new obj in year 2000. (via clone() inside Class::Date)

Not correct.  $_[0] is always points to the same object as $a, $_[1]
always points to the same object as $b; In this case, we have a new
object, $x, which is also points to the same as $a and $_[0];

Oh. At a glance inside the guts of your class and not knowing "overload" well I thought Class::Date was doing operator overloading on the assignment operator (=), invoking clone().

Now I've read up a little (perldoc overload) and may understand your guts better. Your explanation above explains that the assigment above is a vanilla Perl reference assignment, not some deep overloaded magic...

This part of "perldoc overload" wigs me out:

SPECIAL SYMBOLS FOR "use overload"

...

       Copy Constructor

The value for "=" is a reference to a function with three arguments, i.e., it looks like the other values in "use overload". However, it does not overload the Perl assignment operator. This would go against
       Camel hair.

"would go against camel hair?" lol! Jay swoons w/ bemused incomprehension. I thought NOTHING was sacred inside overload. -laugh-

Debugging your class objects always trips me up because of your (very useful)

use overload
  '""'     => "string",

I'm used to debugging and seeing this:

  DB<1> p $x
main=HASH(0x8d3a28)

But on your objects I get this:

  DB<2> p $a
2000-11-11 00:00:00

So when I'm trying to understand what happens during/after an assignment operation I fail. -grin- Now that I know there's no magic going on I can understand it, but I won't know for sure when I'm looking at it in the debugger.

Is there any way to get the "main=HASH(0x8d3a28)" to kick out on your objects? (So I can SEEE if its the same obj or some new one?)

So, it does not copy OBJECTS, it just increasing and decreasing
reference counters to objects (since perl is a reference-counting language).

Please see the perlobj and perlref (or perlreftut) manual to get what I
had talked about.

Yes. I understand that default behavior. I thought Class::Date was being sneakier than the default.

Thanks again for the help, you mad scientist genius you,  -grin-

j