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 !!

In reply to Class::Multimethods namespace collusion by bakunin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.