From: Dan Sugalski [mailto:[EMAIL PROTECTED]]
>
> No, you attach the magic to a value. Perl just doesn't copy
> magic when it copies data. Whether this is a good thing or
> not is up in the air. (Half the time I want it to, the other
> half I don't...)
Is there a good discussion of magic, copying magic etc. in the core perl
documentation? Or elsewhere for that matter? Any documentation, pointers,
general tips, etc. would be greatly appreciated.
I was recently bit by overloading magic in the Class::Context generic
constructor which the following code illustrates. If you return "another"
reference to a scalar which was blessed, instead of the blessed reference,
then you loose your magic. I'm trying to keep Class::Contract (which I'm
maintaining for Damian) overload friendly... But Perl magic on my map is
labelled "there be dragons".
package foo;
use overload '""' => 'asString';
sub asString { 'Hello World' }
package bar;
@ISA = qw(foo);
sub new { bless \my $key; \$key }
package baz;
@ISA = qw(foo);
sub new { my $ref = \ my $key; bless $ref; $ref }
package main;
my ($bar, $baz);
$bar = bar::->new();
$baz = baz::->new();
print "bar $bar\n";
print "baz $baz\n";
Results In:
bar bar=SCALAR(0x1bbfc9c)
baz Hello World