package MyCar;
use Data::Dumper;
use Moose;
has 'speed' => ( is => 'rw', isa => 'Int' );
sub BUILD {
my $self = shift;
$self->speed( 50 ) if !$self->speed;
}
no Moose;
my $super_car = MyCar->new( speed => 200 );
my $normal_car = MyCar->new;
print "=== Super Car ===\n". Dumper $super_car;
print "=== Normal Car ===\n". Dumper $normal_car;
結果
=== Super Car ===
$VAR1 = bless( {
'speed' => 200
}, 'MyCar' );
=== Normal Car ===
$VAR1 = bless( {
'speed' => 50
}, 'MyCar' );
0 件のコメント:
コメントを投稿