Mango/Cursor.pm

filter: Statementstmt 95.3% 41 / 43 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 7 totaltotal 86.1% 62 / 72 CC 7 SCAR 7.8
CC
7
Cov
96%
all
3.0
next
3.0
count
3.0
CRAP 2.2
« Mango/DB.pm ↑ Summary Mango.pm »
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
BranchTrueFalseTotal
if (defined $Test::Mock::Mango::error) { } 2 2 4
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
BranchTrueFalseTotal
if $cb 2 2 4
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
BranchTrueFalseTotal
if (defined $Test::Mock::Mango::error) { } 2 12 14
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
BranchTrueFalseTotal
if $cb 7 7 14
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
BranchTrueFalseTotal
if (defined $Test::Mock::Mango::error) { } 2 2 4
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
BranchTrueFalseTotal
if $cb 2 2 4
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
« Mango/DB.pm ↑ Summary Mango.pm »