| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Teng::Schema::Table; |
|
2
|
69
|
|
|
69
|
|
48554
|
use strict; |
|
|
69
|
|
|
|
|
137
|
|
|
|
69
|
|
|
|
|
1532
|
|
|
3
|
69
|
|
|
69
|
|
289
|
use warnings; |
|
|
69
|
|
|
|
|
132
|
|
|
|
69
|
|
|
|
|
2222
|
|
|
4
|
|
|
|
|
|
|
use Class::Accessor::Lite |
|
5
|
69
|
|
|
|
|
487
|
rw => [ qw( |
|
6
|
|
|
|
|
|
|
name |
|
7
|
|
|
|
|
|
|
primary_keys |
|
8
|
|
|
|
|
|
|
columns |
|
9
|
|
|
|
|
|
|
escaped_columns |
|
10
|
|
|
|
|
|
|
sql_types |
|
11
|
|
|
|
|
|
|
row_class |
|
12
|
|
|
|
|
|
|
base_row_class |
|
13
|
|
|
|
|
|
|
) ] |
|
14
|
69
|
|
|
69
|
|
782
|
; |
|
|
69
|
|
|
|
|
928
|
|
|
15
|
69
|
|
|
69
|
|
7653
|
use Carp (); |
|
|
69
|
|
|
|
|
137
|
|
|
|
69
|
|
|
|
|
844
|
|
|
16
|
69
|
|
|
69
|
|
1495
|
use Class::Load (); |
|
|
69
|
|
|
|
|
44436
|
|
|
|
69
|
|
|
|
|
4991
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
|
19
|
244
|
|
|
244
|
1
|
2988
|
my ($class, %args) = @_; |
|
20
|
244
|
|
|
|
|
1697
|
my $self = bless { |
|
21
|
|
|
|
|
|
|
deflators => [], |
|
22
|
|
|
|
|
|
|
inflators => [], |
|
23
|
|
|
|
|
|
|
escaped_columns => {}, |
|
24
|
|
|
|
|
|
|
base_row_class => 'Teng::Row', |
|
25
|
|
|
|
|
|
|
%args |
|
26
|
|
|
|
|
|
|
}, $class; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# load row class |
|
29
|
244
|
|
|
|
|
899
|
my $row_class = $self->row_class; |
|
30
|
244
|
100
|
|
|
|
1682
|
Class::Load::load_optional_class($row_class) or do { |
|
31
|
|
|
|
|
|
|
# make row class automatically |
|
32
|
239
|
|
|
|
|
90357
|
Class::Load::load_class($self->base_row_class); |
|
33
|
69
|
|
|
69
|
|
356
|
no strict 'refs'; @{"$row_class\::ISA"} = ($self->base_row_class); |
|
|
69
|
|
|
|
|
136
|
|
|
|
69
|
|
|
|
|
3498
|
|
|
|
239
|
|
|
|
|
16676
|
|
|
|
239
|
|
|
|
|
3026
|
|
|
34
|
|
|
|
|
|
|
}; |
|
35
|
244
|
|
|
|
|
987
|
for my $col (@{$self->columns}) { |
|
|
244
|
|
|
|
|
633
|
|
|
36
|
69
|
|
|
69
|
|
364
|
no strict 'refs'; |
|
|
69
|
|
|
|
|
149
|
|
|
|
69
|
|
|
|
|
31546
|
|
|
37
|
725
|
100
|
|
|
|
5273
|
unless ($row_class->can($col)) { |
|
38
|
721
|
|
|
|
|
2215
|
*{"$row_class\::$col"} = $row_class->generate_column_accessor($col); |
|
|
721
|
|
|
|
|
2405
|
|
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
} |
|
41
|
244
|
|
|
|
|
842
|
$self->row_class($row_class); |
|
42
|
|
|
|
|
|
|
|
|
43
|
244
|
|
|
|
|
2204
|
return $self; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get_sql_type { |
|
47
|
336
|
|
|
336
|
1
|
2845
|
my ($self, $column_name) = @_; |
|
48
|
336
|
|
|
|
|
942
|
$self->sql_types->{ $column_name }; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub add_deflator { |
|
52
|
0
|
|
|
0
|
1
|
0
|
my ($self, $rule, $code) = @_; |
|
53
|
0
|
0
|
|
|
|
0
|
if ( ref $rule ne 'Regexp' ) { |
|
54
|
0
|
|
|
|
|
0
|
$rule = qr/^\Q$rule\E$/; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
0
|
0
|
|
|
|
0
|
unless (ref($code) eq 'CODE') { |
|
57
|
0
|
|
|
|
|
0
|
Carp::croak('deflate code must be coderef.'); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
0
|
|
|
|
|
0
|
push @{ $self->{deflators} }, ( $rule, $code ); |
|
|
0
|
|
|
|
|
0
|
|
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub add_inflator { |
|
63
|
0
|
|
|
0
|
1
|
0
|
my ($self, $rule, $code) = @_; |
|
64
|
0
|
0
|
|
|
|
0
|
if ( ref $rule ne 'Regexp' ) { |
|
65
|
0
|
|
|
|
|
0
|
$rule = qr/^\Q$rule\E$/; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
0
|
0
|
|
|
|
0
|
unless (ref($code) eq 'CODE') { |
|
68
|
0
|
|
|
|
|
0
|
Carp::croak('inflate code must be coderef.'); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
0
|
|
|
|
|
0
|
push @{ $self->{inflators} }, ( $rule, $code ); |
|
|
0
|
|
|
|
|
0
|
|
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub call_deflate { |
|
74
|
340
|
|
|
340
|
1
|
760
|
my ($self, $col_name, $col_value) = @_; |
|
75
|
340
|
|
|
|
|
659
|
my $rules = $self->{deflators}; |
|
76
|
340
|
|
|
|
|
515
|
my $i = 0; |
|
77
|
340
|
|
|
|
|
577
|
my $max = @$rules; |
|
78
|
340
|
|
|
|
|
916
|
while ( $i < $max ) { |
|
79
|
53
|
|
|
|
|
103
|
my ($rule, $code) = @$rules[ $i, $i + 1 ]; |
|
80
|
53
|
100
|
|
|
|
218
|
if ($col_name =~ /$rule/) { |
|
81
|
22
|
|
|
|
|
70
|
return $code->($col_value); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
31
|
|
|
|
|
70
|
$i += 2; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
318
|
|
|
|
|
985
|
return $col_value; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub call_inflate { |
|
89
|
222
|
|
|
222
|
1
|
573
|
my ($self, $col_name, $col_value) = @_; |
|
90
|
222
|
|
|
|
|
392
|
my $rules = $self->{inflators}; |
|
91
|
222
|
|
|
|
|
406
|
my $i = 0; |
|
92
|
222
|
|
|
|
|
456
|
my $max = @$rules; |
|
93
|
222
|
|
|
|
|
690
|
while ( $i < $max ) { |
|
94
|
42
|
|
|
|
|
90
|
my ($rule, $code) = @$rules[ $i, $i + 1 ]; |
|
95
|
42
|
100
|
|
|
|
215
|
if ($col_name =~ /$rule/) { |
|
96
|
27
|
|
|
|
|
89
|
return $code->($col_value); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
15
|
|
|
|
|
42
|
$i += 2; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
195
|
|
|
|
|
666
|
return $col_value; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub has_deflators { |
|
104
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
105
|
0
|
|
|
|
|
0
|
return scalar @{ $self->{deflators} }; |
|
|
0
|
|
|
|
|
0
|
|
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub has_inflators { |
|
109
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
110
|
0
|
|
|
|
|
0
|
return scalar @{ $self->{inflators} }; |
|
|
0
|
|
|
|
|
0
|
|
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub prepare_from_dbh { |
|
114
|
468
|
|
|
468
|
0
|
6256
|
my ($self, $dbh) = @_; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$self->escaped_columns->{$dbh->{Driver}->{Name}} ||= [ |
|
117
|
696
|
|
|
|
|
15507
|
map { \$dbh->quote_identifier($_) } |
|
118
|
468
|
|
100
|
|
|
1209
|
@{$self->columns} |
|
|
230
|
|
|
|
|
2931
|
|
|
119
|
|
|
|
|
|
|
]; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 NAME |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Teng::Schema::Table - Teng table class. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 METHODS |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=over 4 |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item $table = Teng::Schema::Table->new |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
create new Teng::Schema::Table's object. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item $table->get_sql_type |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
get column SQL type. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item $table->add_deflator($column_rule, $code) |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
add deflate code reference. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item $table->add_inflator($column_rule, $code) |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
add inflate code reference. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item $table->call_deflate |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
execute deflate. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item $table->call_inflate |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
execute inflate. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item $table->has_deflators() |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Returns true if there are any deflators |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item $table->has_inflators(); |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Returns true if there are any inflators |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=back |