6 use Test::More tests => 8;
15 has 'first_name' => (is => 'ro', isa => 'Str');
16 has 'last_name' => (is => 'ro', isa => 'Str');
23 isa => 'ArrayRef[Record]',
24 default => sub { [] },
37 return $self->data->[$i];
40 package RecordSetIterator;
48 # list the fields you want to
49 # fetch from the current record
50 my @fields = Record->meta->get_attribute_list;
52 has 'current_record' => (
58 $self->record_set->next() # grab the first one
62 # whenever this attribute is
63 # updated, it will clear all
65 $self->$_() for map { '_clear_' . $_ } @fields;
69 # define the attributes
71 for my $field (@fields) {
78 # fetch the value from
80 $self->current_record->$field();
82 # make sure they have a clearer ..
83 clearer => ('_clear_' . $field)
89 $self->current_record($self->record_set->next());
93 my $rs = RecordSet->new(
95 Record->new(first_name => 'Bill', last_name => 'Smith'),
96 Record->new(first_name => 'Bob', last_name => 'Jones'),
97 Record->new(first_name => 'Jim', last_name => 'Johnson'),
100 isa_ok($rs, 'RecordSet');
102 my $rsi = RecordSetIterator->new(record_set => $rs);
103 isa_ok($rsi, 'RecordSetIterator');
105 is($rsi->first_name, 'Bill', '... got the right first name');
106 is($rsi->last_name, 'Smith', '... got the right last name');
108 $rsi->get_next_record;
110 is($rsi->first_name, 'Bob', '... got the right first name');
111 is($rsi->last_name, 'Jones', '... got the right last name');
113 $rsi->get_next_record;
115 is($rsi->first_name, 'Jim', '... got the right first name');
116 is($rsi->last_name, 'Johnson', '... got the right last name');