AlzaboWrapper/Cursor.pm

filter: Statementstmt 25.0% 11 / 44 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 30.0% 3 / 10 Podpod 100% 5 / 5 totaltotal 24.0% 19 / 79 CC 11 SCAR 26.6
CC
11
Cov
17%
next
30.0
_new_from_row
20.0
all
12.0
CRAP 14.3
« AlzaboWrapper.pm ↑ Summary
1 package Class::AlzaboWrapper::Cursor;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Class::AlzaboWrapper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Params::Validate qw( validate_with SCALAR ARRAYREF );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 Params::Validate::validation_options
9 ( on_fail =>
10 0 ▶ sub { Class::AlzaboWrapper::Exception::Params->throw
Subroutine __ANON__: not called CC=1 SCAR=6.9
11 1 ( message => join '', @_ ) } );
12  
13 sub new
14 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
15 0 my $class = shift;
16  
17 0 my %p = validate_with( params => \@_,
18 spec =>
19 { cursor => { can => 'next' },
20 args => { type => ARRAYREF, default => [] },
21 constructor_method => { type => SCALAR, default => 'new' },
22 },
23 allow_extra => 1,
24 );
25  
26 0 my $self = bless { %p,
27 }, $class;
28  
29 0 return $self;
30 }
31  
32 sub _new_from_row
33 0 ▶{
Subroutine _new_from_row: not called CC=4 SCAR=30.0
34 0 my $self = shift;
35 0 my $row = shift;
36  
37 0 ▶ return undef unless defined $row;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $row 0 0 0
38 0 ▶ return $row if $row->isa( 'Class::AlzaboWrapper' );
Branch: 1 branch
BranchTrueFalseTotal
if $row->isa("Class::AlzaboWrapper") 0 0 0
39  
40 0 my $class = Class::AlzaboWrapper->TableToClass( $row->table );
41 0 ▶ Class::AlzaboWrapper::Exception->throw
Branch: 1 branch
BranchTrueFalseTotal
unless $class 0 0 0
42 ( error => "Cannot find a class for " . $row->table->name . " table" )
43 unless $class;
44  
45 0 my $meth = $self->{constructor_method};
46  
47 return
48 $class->$meth
49 ( object => $row,
50 0 @{ $self->{args} },
51 );
52 }
53  
54 sub next
55 0 ▶{
Subroutine next: not called CC=5 SCAR=34.0
Pod documented
56 0 my $self = shift;
57  
58 0 my @things;
59 0 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
60 {
61 @things = $self->{cursor}->next
62 0 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
@things = $self->{"cursor"}->next or return 0 0 0
63 }
64 else
65 {
66 $things[0] = $self->{cursor}->next
67 0 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
$things[0] = $self->{"cursor"}->next or return 0 0 0
68 }
69  
70 0 my @r = map { $self->_new_from_row($_) } @things;
71  
72 0 ▶ return wantarray ? @r : $r[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
73 }
74  
75 sub next_as_hash
76 0 ▶{
Subroutine next_as_hash: not called CC=2 SCAR=17.9
Pod documented
77 0 my $self = shift;
78  
79 0 ▶ my %hash = $self->{cursor}->next_as_hash or return;
Branch: 1 branch
BranchTrueFalseTotal
my(%hash) = $self->{"cursor"}->next_as_hash or return 0 0 0
80 0 map { $hash{$_} = $self->_new_from_row($hash{$_}) } keys %hash;
81  
82 0 return %hash;
83 }
84  
85 sub all
86 0 ▶{
Subroutine all: not called CC=3 SCAR=24.8
Pod documented
87 0 my $self = shift;
88  
89 0 my @all;
90 0 ▶ while ( my @a = $self->next )
Branch: 1 branch
BranchTrueFalseTotal
if (my(@a) = $self->next) 0 0 0
91 {
92 0 ▶ push @all, @a == 1 ? $a[0] : \@a;
Branch: 1 branch
BranchTrueFalseTotal
@a == 1 ? : 0 0 0
93 }
94  
95 0 return @all;
96 }
97  
98 0 ▶sub count { $_[0]->{cursor}->count }
Subroutine count: not called CC=1 SCAR=6.9
Pod documented
99  
100  
101 1 1;
102  
103 __END__
« AlzaboWrapper.pm ↑ Summary