package base;
use overload
'""' => sub { shift->as_string },
# '""' => \&as_string,
fallback => 1;
sub as_string { "this is a base class" }
package child;
@ISA = qw(base);
sub as_string { "this is a child class" }
package main;
$obj = bless {}, "child";
print "\$obj=$obj\n";
Try both versions. Do you see the difference? The original version calls the as_string method of the object (which may be either an instance of the base class or a child) while the second calls always the as_string subroutine in the base class.
Jenda
XML sucks. Badly. SOAP on the other hand is the most powerfull vacuum pump ever invented. |