Magic [Slightly Off-Topic... please point me to documentation]Garrett Goebel wrote: > 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". > Only blessed objects can be overloaded, not references. Only a class can have overloading behaviour, and a plain reference belongs to no class, so it should have no overloading behaviour. Contrast this use of \$key with having [1,2,3]. Do you think this array reference should have any overloading behaviour? Or else, try to define a method in package bar and try to call it from $bar, like $bar->foo. Won't work either, you have to ${$bar}->foo. Overloading should loose the magic in the same sense that the method should not be called. > package bar; > @ISA = qw(foo); > sub new { bless \my $key; \$key } You return a reference to the object... > package main; > my ($bar, $baz); > $bar = bar::->new(); > $baz = baz::->new(); > > print "bar $bar\n"; > print "baz $baz\n"; Try printing $$bar, it will work... - Branden