Hi Anonymous,
...to a module's method when two modules have the same method name...
But if there's a conflict of method names, is there a way to unambiguously call a module's method?...
Though you have been given a great answer, I consider it not over "stressed" to say your requirements taste like an Object-Oriented in IMHO.
Since, the first two principle stated in perlobj answers thus:
1. An object is simply a data structure that knows to which class it belongs.
2. A class is simply a package. A class provides methods that expect to operate on objects.
NOTE:package Module1; sub main { my $obj = shift; my $class = { name => __PACKAGE__, }; return bless $class, $obj; } package Module2; sub main { my $obj = shift; my $class = { name => __PACKAGE__, }; return bless $class, $obj; } package main; my $an1 = Module1->main(); print $an1->{name}, $/; my $an2 = Module2->main(); print $an2->{name}, $/; ## And if you must use your dispatch table ## you can do my %dispatch = ( main => Module1->main(), another_page => Module2->main(), ); print "Am in ", $dispatch{main}{name}, $/; print "Am in ", $dispatch{another_page}{name};
In reply to Re: Dispatcher to module's method
by 2teez
in thread Dispatcher to module's method
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |