| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Tao::DBI::st_deep; |
|
3
|
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
751
|
use 5.006; |
|
|
2
|
|
|
|
|
6
|
|
|
5
|
2
|
|
|
2
|
|
10
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
41
|
|
|
6
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
157
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Tao::DBI::st); |
|
11
|
|
|
|
|
|
|
our @EXPORT = qw(); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
515
|
use Tao::DBI::st; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
71
|
|
|
16
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
336
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# instance variables: |
|
19
|
|
|
|
|
|
|
# META |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# initiates a Tao::DBI::st_deep object |
|
22
|
|
|
|
|
|
|
# { dbh => , sql => , meta => , } |
|
23
|
|
|
|
|
|
|
sub initialize { |
|
24
|
0
|
|
|
0
|
0
|
0
|
my ($self, $args) = @_; |
|
25
|
0
|
|
|
|
|
0
|
$self->SUPER::initialize($args); |
|
26
|
0
|
|
|
|
|
0
|
$self->{META} = $args->{meta}; |
|
27
|
0
|
|
|
|
|
0
|
return $self |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
############### |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub to_perl { |
|
33
|
1
|
|
|
1
|
0
|
5
|
require Data::Dumper; |
|
34
|
1
|
|
|
|
|
5
|
return Data::Dumper::Dumper(shift); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub to_yaml { |
|
38
|
0
|
|
|
0
|
0
|
0
|
require YAML; |
|
39
|
0
|
|
|
|
|
0
|
return YAML::Dump(shift); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub from_perl { |
|
43
|
2
|
|
|
2
|
|
11
|
no strict 'vars'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
1382
|
|
|
44
|
1
|
|
|
1
|
0
|
78
|
my $data = eval shift; # oops! that's DANGEROUS! |
|
45
|
1
|
50
|
|
|
|
5
|
die $@ if $@; |
|
46
|
1
|
|
|
|
|
3
|
return $data; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub from_yaml { |
|
50
|
0
|
|
|
0
|
0
|
0
|
require YAML; |
|
51
|
0
|
|
|
|
|
0
|
return YAML::Load(shift); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my %tr_functions = ( |
|
55
|
|
|
|
|
|
|
ddumper => \&to_perl, |
|
56
|
|
|
|
|
|
|
yaml => \&to_yaml, |
|
57
|
|
|
|
|
|
|
); |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my %i_tr_functions = ( |
|
60
|
|
|
|
|
|
|
ddumper => \&from_perl, |
|
61
|
|
|
|
|
|
|
yaml => \&from_yaml, |
|
62
|
|
|
|
|
|
|
); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# $g = tr_hash($h, $ctl) converts hashrefs to hashrefs |
|
65
|
|
|
|
|
|
|
# $g = tr_hash($h, $ctl, 1) does the reverse convertion |
|
66
|
|
|
|
|
|
|
# |
|
67
|
|
|
|
|
|
|
# requires: |
|
68
|
|
|
|
|
|
|
# $ctl is an array ref with an even number of elements |
|
69
|
|
|
|
|
|
|
sub tr_hash { |
|
70
|
4
|
|
|
4
|
0
|
3531
|
my $h = shift; |
|
71
|
4
|
50
|
|
|
|
11
|
return undef unless defined $h; |
|
72
|
|
|
|
|
|
|
|
|
73
|
4
|
|
|
|
|
5
|
my $ctl = shift; |
|
74
|
4
|
|
|
|
|
5
|
my $inv = shift; |
|
75
|
|
|
|
|
|
|
|
|
76
|
4
|
|
|
|
|
19
|
my %h = %$h; |
|
77
|
4
|
|
|
|
|
7
|
my %g; # the result |
|
78
|
|
|
|
|
|
|
my %m; # the visited keys |
|
79
|
4
|
|
|
|
|
10
|
my @ctl = @$ctl; |
|
80
|
|
|
|
|
|
|
|
|
81
|
4
|
|
|
|
|
12
|
while (@ctl) { |
|
82
|
12
|
|
|
|
|
28
|
my ($k, $fk) = split ':', shift @ctl; |
|
83
|
12
|
|
|
|
|
24
|
my ($v, $fv) = split ':', shift @ctl; |
|
84
|
|
|
|
|
|
|
|
|
85
|
12
|
100
|
|
|
|
30
|
if ($inv) { |
|
86
|
6
|
|
|
|
|
12
|
($k, $v) = ($v, $k); |
|
87
|
6
|
|
|
|
|
10
|
($fk, $fv) = ($fv, $fk); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
12
|
100
|
|
|
|
30
|
if ($k eq '*') { # h{*} -> g{$k} |
|
|
|
100
|
|
|
|
|
|
|
91
|
2
|
|
|
|
|
20
|
while (my ($a, $b) = each %h) { |
|
92
|
10
|
100
|
|
|
|
45
|
$g{$v}{$a} = $b, $m{$a}++ unless $m{$a}; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
2
|
100
|
|
|
|
7
|
if ($fv) { |
|
95
|
1
|
|
|
|
|
2
|
$g{$v} = &{ $tr_functions{$fv} }($g{$v}); |
|
|
1
|
|
|
|
|
3
|
|
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} elsif ($v eq '*') { # h{$k} -> g{*} |
|
98
|
2
|
100
|
|
|
|
12
|
if ($fk) { |
|
99
|
1
|
|
|
|
|
3
|
$h{$k} = &{ $i_tr_functions{$fk} }($h{$k}); |
|
|
1
|
|
|
|
|
3
|
|
|
100
|
|
|
|
|
|
|
} |
|
101
|
2
|
50
|
0
|
|
|
7
|
croak "val at '$k' (", (ref $h{$k} || 'non-ref scalar'), ") should be hashref" unless ref $h{$k} eq 'HASH'; # FIXME: |
|
102
|
2
|
|
|
|
|
2
|
while (my ($a, $b) = each %{$h{$k}}) { |
|
|
8
|
|
|
|
|
27
|
|
|
103
|
6
|
|
|
|
|
13
|
$g{$a} = $b; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
2
|
|
|
|
|
7
|
$m{$k}++; |
|
106
|
|
|
|
|
|
|
} else { |
|
107
|
8
|
|
|
|
|
18
|
$g{$v} = $h{$k}; |
|
108
|
8
|
|
|
|
|
23
|
$m{$k}++; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
4
|
|
|
|
|
145
|
return \%g; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# sub comp_map_h { |
|
117
|
|
|
|
|
|
|
# } |
|
118
|
|
|
|
|
|
|
# returns a sub which does the same map_h |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
############### |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub trace { |
|
124
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
125
|
0
|
|
|
|
|
|
return 0; # FIXME: $self->{TRACE} || $self->{DBH}->{TRACE} |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub fetchrow_hashref { |
|
129
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
130
|
0
|
|
|
|
|
|
my $raw = $self->SUPER::fetchrow_hashref(@_); |
|
131
|
0
|
0
|
|
|
|
|
return undef unless defined $raw; |
|
132
|
0
|
0
|
|
|
|
|
if ($self->trace) { require YAML; warn YAML::Dump({ RAW => $raw }) }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
my $row = tr_hash($raw, $self->{META}, 1); |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub execute { |
|
137
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
138
|
0
|
|
|
|
|
|
my $bind_values = shift; |
|
139
|
0
|
0
|
|
|
|
|
if (ref $bind_values) { |
|
140
|
0
|
|
|
|
|
|
my $raw = {}; |
|
141
|
0
|
0
|
|
|
|
|
$raw = tr_hash($bind_values, $self->{META}) if $bind_values; |
|
142
|
0
|
|
|
|
|
|
return $self->SUPER::execute($raw, @_); |
|
143
|
|
|
|
|
|
|
} else { # single non-ref arg - we don't try transformations |
|
144
|
0
|
|
|
|
|
|
return $self->SUPER::execute($bind_values, @_); |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
__END__ |