01: my $_init_ = sub {
02: my $self = shift;
03: print STDERR ref($self) . "::_init_ called\n";
04: };
05:
06: sub new {
07: my $type = shift;
08: my $class = ref($type) || $type;
09: my $self = {
10: attribute1 => undef,
11: attribute2 => undef,
12: };
13: bless $self,$class;
14: $self->$_init_();
15: return $self;
16: }
####
sub new {
my $class = shift;
my $self = bless {}, $class;
$self->_init;
}
sub _init {
# instance initialization
}
####
07: my $type = shift;
08: my $class = ref($type) || $type;
####
$employee{Sally} = Employee->new;
$employee{Bob} = $employee{Sally}->new;
####
$employee{Sally} = Employee->new;
$employee{Bob} = $employee{Sally}->clone;
####
sub accessor_to_column {
my ($proto,$column) = @_;
my $class = ref $proto || $proto;
# note the lexical variable to store class data
my $found_column = 'id' eq $column
? $CLASS_DATA{$class}{id}
: $CLASS_DATA{$class}{accessor_to_column}{$column};
unless ($found_column) {
croak "No column found for ($column)";
}
return $found_column;
}