2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
17 has 'first_name' => (is => 'ro', isa => 'Str');
18 has 'last_name' => (is => 'ro', isa => 'Str');
25 isa => 'ArrayRef[Record]',
26 default => sub { [] },
39 return $self->data->[$i];
42 package RecordSetIterator;
50 # list the fields you want to
51 # fetch from the current record
52 my @fields = Record->meta->get_attribute_list;
54 has 'current_record' => (
60 $self->record_set->next() # grab the first one
64 # whenever this attribute is
65 # updated, it will clear all
67 $self->$_() for map { '_clear_' . $_ } @fields;
71 # define the attributes
73 for my $field (@fields) {
80 # fetch the value from
82 $self->current_record->$field();
84 # make sure they have a clearer ..
85 clearer => ('_clear_' . $field)
91 $self->current_record($self->record_set->next());
95 my $rs = RecordSet->new(
97 Record->new(first_name => 'Bill', last_name => 'Smith'),
98 Record->new(first_name => 'Bob', last_name => 'Jones'),
99 Record->new(first_name => 'Jim', last_name => 'Johnson'),
102 isa_ok($rs, 'RecordSet');
104 my $rsi = RecordSetIterator->new(record_set => $rs);
105 isa_ok($rsi, 'RecordSetIterator');
107 is($rsi->first_name, 'Bill', '... got the right first name');
108 is($rsi->last_name, 'Smith', '... got the right last name');
110 $rsi->get_next_record;
112 is($rsi->first_name, 'Bob', '... got the right first name');
113 is($rsi->last_name, 'Jones', '... got the right last name');
115 $rsi->get_next_record;
117 is($rsi->first_name, 'Jim', '... got the right first name');
118 is($rsi->last_name, 'Johnson', '... got the right last name');