13 has 'first_name' => (is => 'ro', isa => 'Str');
14 has 'last_name' => (is => 'ro', isa => 'Str');
21 isa => 'ArrayRef[Record]',
22 default => sub { [] },
35 return $self->data->[$i];
38 package RecordSetIterator;
46 # list the fields you want to
47 # fetch from the current record
48 my @fields = Record->meta->get_attribute_list;
50 has 'current_record' => (
56 $self->record_set->next() # grab the first one
60 # whenever this attribute is
61 # updated, it will clear all
63 $self->$_() for map { '_clear_' . $_ } @fields;
67 # define the attributes
69 for my $field (@fields) {
76 # fetch the value from
78 $self->current_record->$field();
80 # make sure they have a clearer ..
81 clearer => ('_clear_' . $field)
87 $self->current_record($self->record_set->next());
91 my $rs = RecordSet->new(
93 Record->new(first_name => 'Bill', last_name => 'Smith'),
94 Record->new(first_name => 'Bob', last_name => 'Jones'),
95 Record->new(first_name => 'Jim', last_name => 'Johnson'),
98 isa_ok($rs, 'RecordSet');
100 my $rsi = RecordSetIterator->new(record_set => $rs);
101 isa_ok($rsi, 'RecordSetIterator');
103 is($rsi->first_name, 'Bill', '... got the right first name');
104 is($rsi->last_name, 'Smith', '... got the right last name');
106 $rsi->get_next_record;
108 is($rsi->first_name, 'Bob', '... got the right first name');
109 is($rsi->last_name, 'Jones', '... got the right last name');
111 $rsi->get_next_record;
113 is($rsi->first_name, 'Jim', '... got the right first name');
114 is($rsi->last_name, 'Johnson', '... got the right last name');