line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::AlzaboWrapper::Cursor; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use Class::AlzaboWrapper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use Params::Validate qw( validate_with SCALAR ARRAYREF ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
553
|
|
8
|
|
|
|
|
|
|
Params::Validate::validation_options |
9
|
|
|
|
|
|
|
( on_fail => |
10
|
|
|
|
|
|
|
sub { Class::AlzaboWrapper::Exception::Params->throw |
11
|
|
|
|
|
|
|
( message => join '', @_ ) } ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new |
14
|
|
|
|
|
|
|
{ |
15
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
{ |
34
|
0
|
|
|
0
|
|
|
my $self = shift; |
35
|
0
|
|
|
|
|
|
my $row = shift; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
return undef unless defined $row; |
38
|
0
|
0
|
|
|
|
|
return $row if $row->isa( 'Class::AlzaboWrapper' ); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $class = Class::AlzaboWrapper->TableToClass( $row->table ); |
41
|
0
|
0
|
|
|
|
|
Class::AlzaboWrapper::Exception->throw |
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
|
0
|
|
|
|
|
|
$class->$meth |
49
|
|
|
|
|
|
|
( object => $row, |
50
|
0
|
|
|
|
|
|
@{ $self->{args} }, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub next |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my @things; |
59
|
0
|
0
|
|
|
|
|
if (wantarray) |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
0
|
|
|
|
|
@things = $self->{cursor}->next |
62
|
|
|
|
|
|
|
or return; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else |
65
|
|
|
|
|
|
|
{ |
66
|
0
|
0
|
|
|
|
|
$things[0] = $self->{cursor}->next |
67
|
|
|
|
|
|
|
or return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my @r = map { $self->_new_from_row($_) } @things; |
|
0
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
return wantarray ? @r : $r[0]; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub next_as_hash |
76
|
|
|
|
|
|
|
{ |
77
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
my %hash = $self->{cursor}->next_as_hash or return; |
80
|
0
|
|
|
|
|
|
map { $hash{$_} = $self->_new_from_row($hash{$_}) } keys %hash; |
|
0
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return %hash; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub all |
86
|
|
|
|
|
|
|
{ |
87
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my @all; |
90
|
0
|
|
|
|
|
|
while ( my @a = $self->next ) |
91
|
|
|
|
|
|
|
{ |
92
|
0
|
0
|
|
|
|
|
push @all, @a == 1 ? $a[0] : \@a; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return @all; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
0
|
1
|
|
sub count { $_[0]->{cursor}->count } |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |