X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F200_examples%2F008_record_set_iterator.t;h=0ae80f38ef37b8e25a4b16b76157f7ccc6555e4c;hb=d03bd989b97597428b460d7f9a021e2931893fa0;hp=00eac6bde6513f7acc2ab82089c770dc6959064b;hpb=f6bee6fe1d579dc3d2ed2952cce9a1556040c8e5;p=gitmo%2FMoose.git diff --git a/t/200_examples/008_record_set_iterator.t b/t/200_examples/008_record_set_iterator.t index 00eac6b..0ae80f3 100644 --- a/t/200_examples/008_record_set_iterator.t +++ b/t/200_examples/008_record_set_iterator.t @@ -11,32 +11,32 @@ use Test::Exception; { package Record; use Moose; - + has 'first_name' => (is => 'ro', isa => 'Str'); - has 'last_name' => (is => 'ro', isa => 'Str'); - + has 'last_name' => (is => 'ro', isa => 'Str'); + package RecordSet; use Moose; - + has 'data' => ( is => 'ro', - isa => 'ArrayRef[Record]', + isa => 'ArrayRef[Record]', default => sub { [] }, ); - + has 'index' => ( is => 'rw', - isa => 'Int', + isa => 'Int', default => sub { 0 }, ); - + sub next { my $self = shift; my $i = $self->index; $self->index($i + 1); return $self->data->[$i]; } - + package RecordSetIterator; use Moose; @@ -45,13 +45,13 @@ use Test::Exception; isa => 'RecordSet', ); - # list the fields you want to + # list the fields you want to # fetch from the current record my @fields = Record->meta->get_attribute_list; has 'current_record' => ( is => 'rw', - isa => 'Record', + isa => 'Record', lazy => 1, default => sub { my $self = shift; @@ -59,23 +59,23 @@ use Test::Exception; }, trigger => sub { my $self = shift; - # whenever this attribute is - # updated, it will clear all + # whenever this attribute is + # updated, it will clear all # the fields for you. $self->$_() for map { '_clear_' . $_ } @fields; } ); - # define the attributes + # define the attributes # for all the fields. for my $field (@fields) { has $field => ( is => 'ro', - isa => 'Any', + isa => 'Any', lazy => 1, - default => sub { + default => sub { my $self = shift; - # fetch the value from + # fetch the value from # the current record $self->current_record->$field(); }, @@ -93,8 +93,8 @@ use Test::Exception; my $rs = RecordSet->new( data => [ Record->new(first_name => 'Bill', last_name => 'Smith'), - Record->new(first_name => 'Bob', last_name => 'Jones'), - Record->new(first_name => 'Jim', last_name => 'Johnson'), + Record->new(first_name => 'Bob', last_name => 'Jones'), + Record->new(first_name => 'Jim', last_name => 'Johnson'), ] ); isa_ok($rs, 'RecordSet');