line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## |
2
|
|
|
|
|
|
|
## File: DBIx/SimpleQuery/Object.pm |
3
|
|
|
|
|
|
|
## Author: Steve Simms |
4
|
|
|
|
|
|
|
## |
5
|
|
|
|
|
|
|
## Revision: $Revision$ |
6
|
|
|
|
|
|
|
## Date: $Date$ |
7
|
|
|
|
|
|
|
## |
8
|
|
|
|
|
|
|
## An object created by DBIx::SimpleQuery which holds the results of a |
9
|
|
|
|
|
|
|
## query. |
10
|
|
|
|
|
|
|
## |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package DBIx::SimpleQuery::Object; |
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
|
21
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
472
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use overload |
17
|
3
|
|
|
|
|
37
|
'""' => \&as_string, |
18
|
|
|
|
|
|
|
'0+' => \&as_integer, |
19
|
|
|
|
|
|
|
'bool' => \&as_boolean, |
20
|
|
|
|
|
|
|
'@{}' => \&as_arrayref, |
21
|
|
|
|
|
|
|
'<<' => \&left_shift, |
22
|
|
|
|
|
|
|
'>>' => \&right_shift, |
23
|
3
|
|
|
3
|
|
5298
|
'<>' => \&as_iterative; |
|
3
|
|
|
|
|
3389
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
26
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
27
|
0
|
|
|
|
|
|
my $params = shift; |
28
|
0
|
|
|
|
|
|
return bless $params, $class; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub as_string { |
32
|
0
|
|
|
0
|
0
|
|
my $self = shift(); |
33
|
0
|
|
|
|
|
|
my @results = @{$self->{"results"}}; |
|
0
|
|
|
|
|
|
|
34
|
0
|
0
|
0
|
|
|
|
if (not scalar @results and $self->{"field_count"} == 1) { |
|
|
0
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
return ""; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
elsif (scalar @results == 1) { |
38
|
0
|
|
|
|
|
|
my $first_result = $results[0]; |
39
|
0
|
0
|
|
|
|
|
if ($self->{"field_count"} == 1) { |
40
|
0
|
|
|
|
|
|
my @keys = keys %{$first_result}; |
|
0
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $key = shift(@keys); |
42
|
0
|
|
|
|
|
|
return $first_result->{$key}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
return $self->{"count"}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub as_integer { |
49
|
0
|
|
|
0
|
0
|
|
my $self = shift(); |
50
|
0
|
|
|
|
|
|
return $self->{"count"}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub as_boolean { |
54
|
0
|
|
|
0
|
0
|
|
my $self = shift(); |
55
|
0
|
0
|
|
|
|
|
return ($self->{"count"} ? 1 : 0); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub as_arrayref { |
59
|
0
|
|
|
0
|
0
|
|
my $self = shift(); |
60
|
0
|
|
|
|
|
|
return $self->{"results"}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub left_shift { |
64
|
0
|
|
|
0
|
0
|
|
my ($self, $i) = @_; |
65
|
0
|
0
|
|
|
|
|
$i = 1 unless defined $i; |
66
|
0
|
|
|
|
|
|
return $self->{"results"}->[$i-1]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub right_shift { |
70
|
0
|
|
|
0
|
0
|
|
my ($self, $i) = @_; |
71
|
0
|
0
|
|
|
|
|
$i = 1 unless defined $i; |
72
|
0
|
|
|
|
|
|
left_shift($self, $i*-1+1); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub as_iterative { |
76
|
0
|
|
|
0
|
0
|
|
my $self = shift(); |
77
|
0
|
|
|
|
|
|
return $self->{"results"}->[$self->{"iter"}++]; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |