http://www.perlmonks.org?node_id=329362

bakunin has asked for the wisdom of the Perl Monks concerning the following question:

Hello all!

Yesterday, I decided to use Class::Multimethods to overload my class methods which have endlessly changing argument lists.
As usual, I got my hands dirty right away without carefully reading the excellent tutorial. A surprise, with full of spite, was awaiting:
## in file Foo.pm: package Foo; use strict; use Class::Multimethods; multimethod new => ('$') => sub { print "I'm the constructor for Foo\n"; bless {},$_[0]; }; 1; ##in file Foo2.pm: package Foo2; use strict; use Class::Multimethods; multimethod new => ('$') => sub { print "I'm the constructor for Foo2\n"; bless {},$_[0]; }; 1; ## in main.pl: package main; use strict; use Foo; use Foo2; Foo->new(); Foo2->new(); ## ==== OUTPUT ==== ## #I'm the constructor for Foo2 #I'm the constructor for Foo2

When I read the tutorial, this line caught my eye:

"...all multimethod variants share a common namespace that is independent of their individual package namespaces."

Meaning, do not use different class constructors with the same name!!
Well, I came up with the following, but again as usual I want to ask the other monks before putting it into the assembly line:
package Foo; use strict; use Class::Multimethods; *Foo::new = \&_newFoo; multimethod _newFoo => ('$') => sub { print "I'm constructor for Foo\n"; bless {},$_[0]; }; 1; ## Foo.2pm package Foo2; use strict; use Class::Multimethods; *Foo2::new = \&_newFoo2; multimethod _newFoo2 => ('$') => sub { print "I'm constructor for Foo2\n"; bless {},$_[0]; }; 1; ## Now, it works as it should be. Of course with also other ## overloaded methods like _newFoo('$','HASH'),_newFoo2('$','$')
Here are my questions: Am I missing something in Multimethods?
If not, is my method useful? Any side effects that you might think of, esp. with inheritance? How would you solve this?

Thanks !!