Skip to content

Instantly share code, notes, and snippets.

@omega
Created March 17, 2009 08:56
Show Gist options
  • Save omega/80411 to your computer and use it in GitHub Desktop.
Save omega/80411 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
package Role;
use Moose::Role;
has '_default_rows' => (is => 'rw', isa => 'Int');
after 'BUILD' => sub {
my $self = shift;
$self->_default_rows($self->rows);
};
sub BUILD {}
1;
package BaseClass;
use Moose;
with 'Role';
has 'rows' => (is => 'rw', isa => 'Int', default => 10);
1;
package MyClass;
use Moose;
extends 'BaseClass';
sub BUILD {};
1;
package main;
use strict;
use Test::More tests => 4;
my $o = MyClass->new();
is($o->rows, 10);
is($o->_default_rows, 10);
my $b = BaseClass->new(rows => 1);
is($b->rows, 1);
is($b->_default_rows, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment