Mandel/Iterator.pm

filter: Statementstmt 50.0% 13 / 26 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 3 / 9 Podpod 100% 2 / 2 totaltotal 43.9% 18 / 41 CC 3 SCAR 11.1
CC
3
Cov
43%
__ANON__
6.0
rewind
6.0
next
2.0
CRAP 3.0
« Mandel/Model.pm ↑ Summary Mandel.pm »
1 package Mandel::Iterator;
2 20 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 20 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 20 require Mandel::Collection; # TODO: Fix ugly method call below
7  
8 0 ▶has cursor => sub { confess "cursor required in constructor" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
9 0 ▶has model => sub { confess "model required in constructor" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
10  
11 0 ▶sub next {
Subroutine next: not called CC=1 SCAR=6.9
Pod documented
12 0 my ($self, $cb) = @_;
13  
14 $self->cursor->next(
15 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
16 0 my ($cursor, $err, $doc) = @_;
17  
18 # TODO: Fix this ugly method call
19 0 ▶ $self->$cb($err, $doc ? $self->Mandel::Collection::_new_document($doc, 1) : undef);
Branch: 1 branch
BranchTrueFalseTotal
$doc ? : 0 0 0
20 }
21 0 );
22  
23 0 $self;
24 }
25  
26 0 ▶sub rewind {
Subroutine rewind: not called CC=2 SCAR=17.9
Pod documented
27 0 my ($self, $cb) = @_;
28  
29 0 ▶ if ($self->{cursor}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'cursor'}) { } 0 0 0
30 $self->cursor->rewind(
31 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 0 $self->$cb($_[1]);
33 }
34 0 );
35 }
36 else {
37 0 $self->$cb('');
38 }
39  
40 0 $self;
41 }
42  
43 20 1;
44  
45 =encoding utf8
46  
47 =head1 NAME
48  
49 Mandel::Iterator - An object iterating over a collection cursor
50  
51 =head1 SYNOPSIS
52  
53 =head1 DESCRIPTION
54  
55 =head1 ATTRIBUTES
56  
57 =head2 cursor
58  
59 An object we can do C<next()> on. Normally a L<Mango::Cursor> object.
60  
61 =head2 model
62  
63 An object that inherit from L<Mandel::Model>.
64  
65 =head1 METHODS
66  
67 =head2 next
68  
69 $self = $self->next(sub { my($self, $err, $obj) = @_; ... });
70  
71 Fetch next document.
72  
73 =head2 rewind
74  
75 $self = $self->rewind($cb);
76  
77 Rewind cursor and kill it on the server
78  
79 =head1 SEE ALSO
80  
81 L<Mojolicious>, L<Mango>, L<Mandel>
82  
83 =head1 AUTHOR
84  
85 Jan Henning Thorsen - C<jhthorsen@cpan.org>
86  
87 =cut
« Mandel/Model.pm ↑ Summary Mandel.pm »