FM gives you good advice. mk_accessorsneed to run before other code. In addition, you usually add Critterto a separate file and use Critterto load the module.
, use . use Critter; BEGIN { require Critter; Critter->import; } , , .
. , , . , .
- , , , - BEGIN , . , :
my $a = Critter->new;
$a->color("blue");
$a->display;
BEGIN {
package Critter;
use base qw(Class::Accessor );
use strict;
use warnings;
Critter->mk_accessors ("color" );
sub display {
my $self = shift;
printf "i am a %s %s whatever this word means\n", $self->color, ref $self;
print "i am a ", $self->color, ref $self, "whatever this word means\n";
}
1;
}