14 has 'first_name' => (is => 'ro', isa => 'Str');
15 has 'last_name' => (is => 'ro', isa => 'Str');
22 isa => 'ArrayRef[Record]',
23 default => sub { [] },
36 return $self->data->[$i];
39 package RecordSetIterator;
47 # list the fields you want to
48 # fetch from the current record
49 my @fields = Record->meta->get_attribute_list;
51 has 'current_record' => (
57 $self->record_set->next() # grab the first one
61 # whenever this attribute is
62 # updated, it will clear all
64 $self->$_() for map { '_clear_' . $_ } @fields;
68 # define the attributes
70 for my $field (@fields) {
77 # fetch the value from
79 $self->current_record->$field();
81 # make sure they have a clearer ..
82 clearer => ('_clear_' . $field)
88 $self->current_record($self->record_set->next());
92 my $rs = RecordSet->new(
94 Record->new(first_name => 'Bill', last_name => 'Smith'),
95 Record->new(first_name => 'Bob', last_name => 'Jones'),
96 Record->new(first_name => 'Jim', last_name => 'Johnson'),
99 isa_ok($rs, 'RecordSet');
101 my $rsi = RecordSetIterator->new(record_set => $rs);
102 isa_ok($rsi, 'RecordSetIterator');
104 is($rsi->first_name, 'Bill', '... got the right first name');
105 is($rsi->last_name, 'Smith', '... got the right last name');
107 $rsi->get_next_record;
109 is($rsi->first_name, 'Bob', '... got the right first name');
110 is($rsi->last_name, 'Jones', '... got the right last name');
112 $rsi->get_next_record;
114 is($rsi->first_name, 'Jim', '... got the right first name');
115 is($rsi->last_name, 'Johnson', '... got the right last name');