in reply to class inheritance and new(constructor)

Directly from perlbot:
An inheritable constructor should use the second form of bless() which allows blessing directly into a specified class. Notice in this example that the object will be a BAR not a FOO, even though the constructor is in class FOO.
package FOO; sub new { my $type = shift; my $self = {}; bless $self, $type; } sub baz { print "in FOO::baz()\n"; } package BAR; @ISA = qw(FOO); sub baz { print "in BAR::baz()\n"; } package main; $a = BAR->new; $a->baz;
There is IMO nothing to add :) Re-using constructors is generally a good idea, as it makes the code more maintainable.

     s;;Just-me-not-h-Ni-m-P-Ni-lm-I-ar-O-Ni;;tr?IerONim-?HAcker ?d;print

Replies are listed 'Best First'.
Re^2: class inheritance and new(constructor)
by nmerriweather (Friar) on Jul 16, 2006 at 19:57 UTC
    ok. sweet.
    my system is pretty much set up just like that. i tested it out and it worked before having posted here
    since its in perlbot, i figure thats a good sign that its a safe coding practice and not just something that works.