If a method isn't found AUTOLOAD is called, if provided.
> If you call a method that doesn't exist in a class, Perl will throw an error. However, if that class or any of its parent classes defines an AUTOLOAD method, that AUTOLOAD method is called instead.
Please instead of torturing us with Java speak try out some Perl code and post snippets.
update
This $obj->meth() is only evaluated at runtime and "meth" is just a string used to resolve the corresponding sub in the possible packages.
IoW you can try to call everything everywhere without compilation error.
you can even do
$str="meth";
$obj->$str();
update
DB<104> sub meth {
$self=shift @_;
print "calling ",$self->{name},"->meth(@_)";
}
DB<106> $obj = bless {name=>"obj"}, main;
=> bless({ name => "obj" }, "main")
DB<107> $str="meth"
=> "meth"
DB<108> $obj->$str("bla")
calling obj->meth(bla)
Update
Also keep in mind that a package is basically a hash which can be altered anytime, i.e. subs can be dynamically added or deleted at runtime.
|