in reply to RE: Re: opinions on the best way to inherit class data
in thread opinions on the best way to inherit class data

Oh, that's what you mean! Here's a sneaky way to do it:
#!/usr/bin/perl -w use strict; package Superclass; use vars qw ( $AUTOLOAD ); my $classdata = qq| { my \$self = shift; my \$invocations = 0; sub _increase { \$invocations++; } sub number { return \$invocations; } }|; sub new { my $class = shift; if ($class ne __PACKAGE__) { # he he he eval qq|package $class; $classdata |; } my $self = {}; bless($self, $class); $self->_increase(); return $self; } eval $classdata; package Subclass; use vars qw ( @ISA ); @ISA = qw ( Superclass ); package main; print Superclass->number(); my $one = Superclass->new(); print $one->number(); print Subclass->number(); my $two = Subclass->new(); print $two->number();
If your superclass is in a different module, you can play around with the import subroutine and do it a bit more cleanly.

This technique has the unfortunate effect of making Subclass->number() return 1 before you create any instance of Subclass. (Inheritance... oh well.)