5 use lib 't/cdbi/testlib';
8 my $it_class = "DBIx::Class::ResultSet";
11 Film->create({ Title => 'Film 1' }),
12 Film->create({ Title => 'Film 2' }),
13 Film->create({ Title => 'Film 3' }),
14 Film->create({ Title => 'Film 4' }),
15 Film->create({ Title => 'Film 5' }),
16 Film->create({ Title => 'Film 6' }),
20 my $it1 = Film->retrieve_all;
21 isa_ok $it1, $it_class;
23 my $it2 = Film->retrieve_all;
24 isa_ok $it2, $it_class;
26 while (my $from1 = $it1->next) {
27 my $from2 = $it2->next;
28 is $from1->id, $from2->id, "Both iterators get $from1";
33 my $it = Film->retrieve_all;
34 is $it->first->title, "Film 1", "Film 1 first";
35 is $it->next->title, "Film 2", "Film 2 next";
36 is $it->first->title, "Film 1", "First goes back to 1";
37 is $it->next->title, "Film 2", "With 2 still next";
39 is $it->next->title, "Film 1", "Reset brings us to film 1 again";
40 is $it->next->title, "Film 2", "And 2 is still next";
45 my $it = Film->retrieve_all;
46 my @slice = $it->slice(2,4);
47 is @slice, 3, "correct slice size (array)";
48 is $slice[0]->title, "Film 3", "Film 3 first";
49 is $slice[2]->title, "Film 5", "Film 5 last";
53 my $it = Film->retrieve_all;
54 my $slice = $it->slice(2,4);
55 isa_ok $slice, $it_class, "slice as iterator";
56 is $slice->count, 3,"correct slice size (array)";
57 is $slice->first->title, "Film 3", "Film 3 first";
58 is $slice->next->title, "Film 4", "Film 4 next";
59 is $slice->first->title, "Film 3", "First goes back to 3";
60 is $slice->next->title, "Film 4", "With 4 still next";
62 is $slice->next->title, "Film 3", "Reset brings us to film 3 again";
63 is $slice->next->title, "Film 4", "And 4 is still next";
65 # check if the original iterator still works
66 is $it->count, 6, "back to the original iterator, is of right size";
67 is $it->first->title, "Film 1", "Film 1 first";
68 is $it->next->title, "Film 2", "Film 2 next";
69 is $it->first->title, "Film 1", "First goes back to 1";
70 is $it->next->title, "Film 2", "With 2 still next";
71 is $it->next->title, "Film 3", "Film 3 is still in original Iterator";
73 is $it->next->title, "Film 1", "Reset brings us to film 1 again";
74 is $it->next->title, "Film 2", "And 2 is still next";
78 my $it = Film->retrieve_all;
79 is $it, $it->count, "iterator returns count as a scalar";
80 ok $it, "iterator returns true when there are results";
84 my $it = Film->search( Title => "something which does not exist" );
86 ok !$it, "iterator returns false when no results";