in reply to Multiple Prototypes for Object Constructor

Perl does not have a way to define more than one subroutine with the same name. There's no dispatch based on the signature. Not that Perl is doing anything with prototypes belonging to methods - after all, prototypes are a compile-time thing, and method lookup is done at runtime.

However, you are free to inspect the arguments to subroutines, and do different things based on the number of arguments. Arguments are found in @_, using an array in scalar context gives you the number of elements, and Perl has an if-then-elsif-else construct, which gives you all the building blocks to do what you want.

Abigail

Replies are listed 'Best First'.
Re: Re: Multiple Prototypes for Object Constructor
by mvc (Scribe) on May 22, 2003 at 16:50 UTC

    Or if you are lazy, just grab Class::Multimethods. It presents a solution that is more open-closed than using an if-then-elsif-else. For example: you can add multi methods to the subclass without touching the superclass.