| 1 | package Test::Mock::Mango::Cursor; | ||||||||||
| 2 | |||||||||||
| 3 | 20 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 20 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 20 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 20 | our $VERSION = '0.03'; | |||||||||
| 8 | |||||||||||
| 9 | 13 | ▶ | sub new { bless {index=>0}, shift } | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 10 | |||||||||||
| 11 | 4 | ▶ | sub all { | ||||||||
|
Subroutine
all: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 12 | 4 | my ($self, $cb) = @_; | |||||||||
| 13 | |||||||||||
| 14 | 4 | my $docs = undef; | |||||||||
| 15 | 4 | my $err = undef; | |||||||||
| 16 | |||||||||||
| 17 | 4 | ▶ | if (defined $Test::Mock::Mango::error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 2 | $err = $Test::Mock::Mango::error; | |||||||||
| 19 | 2 | $Test::Mock::Mango::error = undef; | |||||||||
| 20 | } | ||||||||||
| 21 | else { | ||||||||||
| 22 | 2 | $docs = $Test::Mock::Mango::data->{collection}; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 4 | ▶ | return $cb->($self,$err,$docs) if $cb; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 2 | return $docs; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | # ------------------------------------------------------------------------------ | ||||||||||
| 30 | |||||||||||
| 31 | # Naive no-op. Just return the parent so it can chain. | ||||||||||
| 32 | 1 | ▶ | sub limit { shift } | ||||||||
|
Subroutine
limit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 33 | 1 | ▶ | sub sort { shift } | ||||||||
|
Subroutine
sort: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 34 | |||||||||||
| 35 | # ------------------------------------------------------------------------------ | ||||||||||
| 36 | |||||||||||
| 37 | # Naive "next" - simply iterate through the docs in the defined test data | ||||||||||
| 38 | 14 | ▶ | sub next { | ||||||||
|
Subroutine
next: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 39 | 14 | my ($self, $cb) = @_; | |||||||||
| 40 | |||||||||||
| 41 | 14 | my $doc = undef; | |||||||||
| 42 | 14 | my $err = undef; | |||||||||
| 43 | |||||||||||
| 44 | 14 | ▶ | if (defined $Test::Mock::Mango::error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 2 | $err = $Test::Mock::Mango::error; | |||||||||
| 46 | 2 | $Test::Mock::Mango::error = undef; | |||||||||
| 47 | } | ||||||||||
| 48 | else { | ||||||||||
| 49 | 12 | $doc = $Test::Mock::Mango::data->{collection}->[$self->{index}++]; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 14 | ▶ | return $cb->($self,$err,$doc) if $cb; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 7 | return $doc; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | # ------------------------------------------------------------------------------ | ||||||||||
| 57 | |||||||||||
| 58 | 4 | ▶ | sub count { | ||||||||
|
Subroutine
count: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 59 | 4 | my ($self,$cb) = @_; | |||||||||
| 60 | |||||||||||
| 61 | 4 | my $count = undef; | |||||||||
| 62 | 4 | my $err = undef; | |||||||||
| 63 | |||||||||||
| 64 | 4 | ▶ | if (defined $Test::Mock::Mango::error) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 2 | $err = $Test::Mock::Mango::error; | |||||||||
| 66 | 2 | $Test::Mock::Mango::error = undef; | |||||||||
| 67 | } | ||||||||||
| 68 | else { | ||||||||||
| 69 | 2 | $count = scalar @{$Test::Mock::Mango::data->{collection}}; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 4 | ▶ | return $cb->($self,$err,$count) if $cb; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 2 | return $count; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | # ------------------------------------------------------------------------------ | ||||||||||
| 77 | |||||||||||
| 78 | 0 | ▶ | sub backlog { | ||||||||
|
Subroutine
backlog: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 79 | 0 | my ($self) = @_; | |||||||||
| 80 | 0 | return 2; # Arbitary for a valid call | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 20 | 1; | |||||||||
| 84 | |||||||||||
| 85 | =encoding utf8 | ||||||||||
| 86 | |||||||||||
| 87 | =head1 NAME | ||||||||||
| 88 | |||||||||||
| 89 | Test::Mock::Mango::Cursor - fake Mango::Cursor | ||||||||||
| 90 | |||||||||||
| 91 | =head1 DESCRIPTION | ||||||||||
| 92 | |||||||||||
| 93 | Simulated mango cursor for unit testing as part of L<Test::Mock::Mango>. | ||||||||||
| 94 | |||||||||||
| 95 | =cut | ||||||||||