分かっててもたまにど忘れするので
- use時に実行
BEGIN {}
- メンバーの属性追加
package Animal;
use Moose;
has 'name' => ( is => 'rw', isa => 'Str' );
package Human;
use Moose; extends 'Animal';
has '+name' => ( default => 'Nanashi' );
- 継承クラスでのメソッドの挙動追加
before/afterを使う
package Point;
use Moose;
has 'x' => ( is => 'rw', isa => 'Int' );
has 'y' => ( is => 'rw', isa => 'Int' );
sub clear {
my $self = shift;
$self->x(0);
$self->y(0);
}
package Point3D;
use Moose; extends 'Point';
has 'z' => ( is => 'rw', isa => 'Int' );
after 'clear' => sub {
my $self = shift;
$self->z(0);
};