line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Teng::ResultSet; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
978
|
use parent 'Teng::Iterator'; |
|
1
|
|
|
|
|
332
|
|
|
1
|
|
|
|
|
6
|
|
6
|
1
|
|
|
1
|
|
3854
|
use String::CamelCase (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
18
|
|
7
|
1
|
|
|
1
|
|
6
|
use Class::Load (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
8
|
1
|
|
|
1
|
|
1166
|
use Class::Method::Modifiers; |
|
1
|
|
|
|
|
1949
|
|
|
1
|
|
|
|
|
195
|
|
9
|
|
|
|
|
|
|
use Class::Accessor::Lite::Lazy 0.03 ( |
10
|
|
|
|
|
|
|
ro => [qw/teng table table_name row_class/], |
11
|
|
|
|
|
|
|
rw => [qw/where opt/], |
12
|
|
|
|
|
|
|
ro_lazy => { |
13
|
|
|
|
|
|
|
sth => sub { |
14
|
0
|
|
|
|
|
0
|
my $self = shift; |
15
|
0
|
|
|
|
|
0
|
my ($sql, @binds) = $self->teng->sql_builder->select( |
16
|
|
|
|
|
|
|
$self->table_name, |
17
|
|
|
|
|
|
|
$self->teng->_get_select_columns($self->table, $self->opt), |
18
|
|
|
|
|
|
|
$self->where, |
19
|
|
|
|
|
|
|
$self->opt |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
0
|
$self->teng->execute($sql, \@binds); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
}, |
25
|
1
|
|
|
1
|
|
1088
|
); |
|
1
|
|
|
|
|
1306
|
|
|
1
|
|
|
|
|
15
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
my %_CACHE; |
29
|
|
|
|
|
|
|
sub new { |
30
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
31
|
0
|
0
|
|
|
|
|
my %args = ref $_[0] ? %{$_[0]}: @_; |
|
0
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
$args{table} = $args{teng}->schema->get_table($args{table_name}) unless $args{table}; |
34
|
0
|
0
|
|
|
|
|
$args{row_class} = $args{teng}->schema->get_row_class($args{table_name}) unless $args{row_class}; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $rs_base_class = ref($args{teng}) . '::ResultSet'; |
37
|
0
|
|
0
|
|
|
|
my $sub_class = $_CACHE{$rs_base_class}{$args{table_name}} ||= do { |
38
|
0
|
|
|
|
|
|
my $pkg = $rs_base_class . '::' . String::CamelCase::camelize($args{table_name}); |
39
|
0
|
0
|
|
|
|
|
Class::Load::load_optional_class($pkg) or do { |
40
|
1
|
|
|
1
|
|
355
|
no strict 'refs'; @{"$pkg\::ISA"} = ($rs_base_class); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
323
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
}; |
42
|
0
|
|
|
|
|
|
$pkg; |
43
|
|
|
|
|
|
|
}; |
44
|
0
|
|
|
|
|
|
bless \%args, $sub_class; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub count { |
49
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
50
|
0
|
|
|
|
|
|
$self->teng->count($self->table_name, '*', $self->where, $self->opt); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
before [qw/all next/] => sub { |
54
|
|
|
|
|
|
|
my $self = shift; |
55
|
|
|
|
|
|
|
# surely assign sth |
56
|
|
|
|
|
|
|
$self->sth; |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub search { |
60
|
0
|
|
|
0
|
1
|
|
my ($self, $where, $opt) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
my $new_rs = (ref $self)->new( |
63
|
|
|
|
|
|
|
teng => $self->teng, |
64
|
|
|
|
|
|
|
table_name => $self->table_name, |
65
|
|
|
|
|
|
|
table => $self->table, |
66
|
|
|
|
|
|
|
row_class => $self->row_class, |
67
|
|
|
|
|
|
|
where => { |
68
|
0
|
0
|
|
|
|
|
%{ $self->where || {} }, |
69
|
0
|
0
|
|
|
|
|
%{ $where || {} }, |
70
|
|
|
|
|
|
|
}, |
71
|
|
|
|
|
|
|
opt => { |
72
|
0
|
0
|
|
|
|
|
%{ $self->opt || {} }, |
73
|
0
|
|
|
|
|
|
%{ $opt || {} }, |
74
|
|
|
|
|
|
|
}, |
75
|
|
|
|
|
|
|
); |
76
|
0
|
0
|
|
|
|
|
wantarray ? $new_rs->all : $new_rs; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
for my $method (qw/find_or_create insert bulk_insert fast_insert/) { |
80
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
81
|
|
|
|
|
|
|
*{__PACKAGE__."::$method"} = sub { |
82
|
1
|
|
|
1
|
|
4
|
use strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
102
|
|
83
|
0
|
|
|
0
|
|
|
my $self = shift; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $teng = $self->teng; |
86
|
0
|
|
|
|
|
|
unshift @_, $teng, $self->table_name; |
87
|
0
|
|
|
|
|
|
goto $teng->can($method); |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
for my $method (qw/search_with_pager delete single/) { |
92
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
93
|
|
|
|
|
|
|
*{__PACKAGE__."::$method"} = sub { |
94
|
1
|
|
|
1
|
|
5
|
use strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
159
|
|
95
|
0
|
|
|
0
|
|
|
my ($self, $where, $opt) = @_; |
96
|
0
|
0
|
|
|
|
|
$where = +{ |
97
|
0
|
0
|
|
|
|
|
%{ $self->where || {} }, |
98
|
0
|
|
|
|
|
|
%{ $where || {} }, |
99
|
|
|
|
|
|
|
}; |
100
|
0
|
0
|
|
|
|
|
$opt = +{ |
101
|
0
|
0
|
|
|
|
|
%{ $self->opt || {} }, |
102
|
0
|
|
|
|
|
|
%{ $opt || {} }, |
103
|
|
|
|
|
|
|
}; |
104
|
0
|
|
|
|
|
|
my $teng = $self->teng; |
105
|
0
|
|
|
|
|
|
@_ = ($teng, $self->table_name, $where, $opt); |
106
|
0
|
|
|
|
|
|
goto $teng->can($method); |
107
|
|
|
|
|
|
|
}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |