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