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

I've got a class hierarchy where each class is built with Class::MethodMaker. In addition, some of the classes additionally inherit from other modules (e.g., various CPAN libraries). Has anybody figured out how to get Class::MethodMaker to call self->SUPER::new() in the generated constructors, or am I missing something obvious? Thanks in advance!
  • Comment on Calling SUPER::new from classes built with Class::MethodMaker?

Replies are listed 'Best First'.
Re: Calling SUPER::new from classes built with Class::MethodMaker?
by gjb (Vicar) on Feb 11, 2003 at 21:02 UTC

    I'd go with the init() function. One can call the superclass' $self->SUPER::init(@_) from that.

    Just my 2 cents, -gjb-

    For an example, see below:

      Interesting, thanks. Unfortunately, I've got some modules from CPAN which do important work in new() rather than init, like Exception::Class from CPAN. Calling SUPER::init misses all the secret sauce happening in the super class constructor. for the moment I'm bypassing Class::MethodMaker in those classes which need to call SUPER::new but it seem like a bit of a hack. It would be great to have an option to Class::MethodMaker to call SUPER::new in the generated constructor....

        (Commenting on a very old thread)

        I agree, it would be nice if MehodMaker were extended so that it could call SUPER::new().

        I found this thread because I'm trying to figure out how to get MethodMaker-derived classes to call *any* sort of SUPER::__() function. Right now I'm bugging the perl-beginners mailing list about why it doesn't work.

        -Dan