Object/Iterator/FromArray.pm

filter: Statementstmt 87.1% 27 / 31 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 100% 1 / 1 totaltotal 85.3% 35 / 41 SCAR 0.0
CC
1
Cov
87%
_get_next_result
2.0
reset
2.0
BEGIN
1.0
CRAP 1.0
« ORM/Types/Internal.pm ↑ Summary ORM/Schema.pm »
1 package Fey::Object::Iterator::FromArray;
2 {
3 1 $Fey::Object::Iterator::FromArray::VERSION = '0.46';
4 }
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Fey::ORM::Types qw( IterableArrayRef );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use MooseX::SemiAffordanceAccessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 with 'Fey::ORM::Role::Iterator';
17  
18 1 has '_objects' => (
19 is => 'ro',
20 isa => IterableArrayRef,
21 coerce => 1,
22 required => 1,
23 init_arg => 'objects',
24 );
25  
26 sub _get_next_result {
27 0 ▶ my $self = shift;
Subroutine _get_next_result: not called CC=1 SCAR=6.9
28  
29 0 return $self->_objects()->[ $self->index() ];
30 }
31  
32 sub reset {
33 0 ▶ my $self = shift;
Subroutine reset: not called CC=1 SCAR=6.9
Pod documented
34  
35 0 $self->_reset_index();
36 }
37  
38 1 __PACKAGE__->meta()->make_immutable();
39  
40 1 1;
41  
42 # ABSTRACT: An iterator which iterates over an array of objects
43  
44 __END__
45  
46 =pod
47  
48 =head1 NAME
49  
50 Fey::Object::Iterator::FromArray - An iterator which iterates over an array of objects
51  
52 =head1 VERSION
53  
54 version 0.46
55  
56 =head1 SYNOPSIS
57  
58 use Fey::Object::Iterator::FromArray;
59  
60 my $iter = Fey::Object::Iterator::FromArray->new(
61 classes => 'MyApp::User',
62 objects => \@users,
63 );
64  
65 my $iter2 = Fey::Object::Iterator::FromArray->new(
66 classes => [ 'MyApp::User', 'MyApp::Group' ],
67 objects => [ [ $user1, $group1 ], [ $user2, $group1 ] ],
68 );
69  
70 print $iter->index(); # 0
71  
72 while ( my $user = $iter->next() ) {
73 print $iter->index(); # 1, 2, 3, ...
74 print $user->username();
75 }
76  
77 # will return cached objects now
78 $iter->reset();
79  
80 =head1 DESCRIPTION
81  
82 This class provides an object which does the
83 C<Fey::ORM::Role::Iterator> role, but gets its data from an array
84 reference. This lets you provide a single API that accepts data from
85 L<Fey::ORM>-created iterators, or existing data sets.
86  
87 =head1 METHODS
88  
89 This class provides the following methods:
90  
91 =head2 $iterator->new()
92  
93 The constructor requires two parameters, C<classes> and
94 C<objects>. The C<classes> parameter can be a single class name, or an
95 array reference of names.
96  
97 The C<objects> parameter should be an array reference. That reference
98 can contain a list of objects, or an a list of array references, each
99 of which contains objects.
100  
101 In either case, the objects must be subclasses of
102 L<Fey::Object::Table>.
103  
104 =head2 $iterator->reset()
105  
106 Resets the iterator so that the next call to C<< $iterator->next() >>
107 returns the first object(s).
108  
109 =head1 ROLES
110  
111 This class does the L<Fey::ORM::Role::Iterator> role.
112  
113 =head1 AUTHOR
114  
115 Dave Rolsky <autarch@urth.org>
116  
117 =head1 COPYRIGHT AND LICENSE
118  
119 This software is copyright (c) 2011 by Dave Rolsky.
120  
121 This is free software; you can redistribute it and/or modify it under
122 the same terms as the Perl 5 programming language system itself.
123  
124 =cut
« ORM/Types/Internal.pm ↑ Summary ORM/Schema.pm »