line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::bind_param_inline; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
52012
|
use 5.008008; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
55
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
71
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
581
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub prepare_inline($$;$){ |
12
|
0
|
|
|
0
|
0
|
0
|
my $dbh = shift; |
13
|
0
|
|
|
|
|
0
|
my $SQL = shift; |
14
|
0
|
|
|
|
|
0
|
my @EPs; |
15
|
0
|
|
0
|
|
|
0
|
my $attrs = shift || {}; |
16
|
0
|
|
|
|
|
0
|
while($SQL =~ /[?]/){ |
17
|
0
|
|
|
|
|
0
|
my $explicit_placeholder; |
18
|
0
|
|
|
|
|
0
|
push @EPs, \$explicit_placeholder; |
19
|
0
|
|
|
|
|
0
|
$SQL =~ s/[?]/\$___explicit__wedfgh__placeholder___/; |
20
|
|
|
|
|
|
|
}; |
21
|
0
|
|
|
|
|
0
|
my $pkg = caller(); |
22
|
0
|
|
|
|
|
0
|
my $EPindex = 0; |
23
|
0
|
|
|
|
|
0
|
my @placeholder_refs = map { |
24
|
0
|
|
|
|
|
0
|
$_ eq '___explicit__wedfgh__placeholder___' |
25
|
|
|
|
|
|
|
? |
26
|
|
|
|
|
|
|
$EPs[$EPindex++] |
27
|
|
|
|
|
|
|
: |
28
|
0
|
0
|
|
|
|
0
|
\${"$pkg\::$_"} |
29
|
|
|
|
|
|
|
} ($SQL =~ /\$(\w+)/g) ; |
30
|
0
|
|
|
|
|
0
|
$SQL =~ s/\$(\w+)/ ? /g ; |
31
|
0
|
0
|
|
|
|
0
|
my $sth = ( |
32
|
|
|
|
|
|
|
defined($attrs) |
33
|
|
|
|
|
|
|
? |
34
|
|
|
|
|
|
|
$dbh->prepare($SQL,$attrs) : $dbh->prepare($SQL) |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
bless [$sth, \@EPs, @placeholder_refs] |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub import{ |
41
|
1
|
|
|
1
|
|
8
|
*{caller().'::prepare_inline'} = \&prepare_inline |
|
1
|
|
|
|
|
14
|
|
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub execute{ |
45
|
0
|
|
|
0
|
0
|
|
my $objref = shift; |
46
|
0
|
|
|
|
|
|
my @obj = @$objref; # a copy, so we can shift from it nondestructively |
47
|
0
|
|
|
|
|
|
my $sth = shift @obj; |
48
|
0
|
|
|
|
|
|
my $EPref = shift @obj; |
49
|
0
|
0
|
|
|
|
|
@$EPref == @_ or |
50
|
|
|
|
|
|
|
croak "Wrong number of explicit placeholders in execute of inline-bound statement handle: ". |
51
|
|
|
|
|
|
|
"need ".@$EPref." but got ".@_." parameters" ; |
52
|
0
|
|
|
|
|
|
for (@$EPref){ |
53
|
0
|
|
|
|
|
|
$$_ = shift; # load explicit placeholders |
54
|
|
|
|
|
|
|
}; |
55
|
0
|
|
|
|
|
|
my $pnum = 1; |
56
|
0
|
|
|
|
|
|
while (@obj){ |
57
|
0
|
|
|
|
|
|
$sth->bind_param($pnum++, ${shift @obj}); |
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
}; |
59
|
0
|
|
|
|
|
|
$sth->execute; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
our $AUTOLOAD; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub AUTOLOAD{ |
66
|
0
|
|
|
0
|
|
|
my $name = $AUTOLOAD; |
67
|
|
|
|
|
|
|
# uncomment the next line to see memoized autoloading in action |
68
|
|
|
|
|
|
|
# warn "AUTOLOADING $name"; |
69
|
0
|
|
|
|
|
|
$name =~ s/.*://; # strip fully-qualified portion |
70
|
0
|
|
|
|
|
|
eval 'sub '.$name.'{ |
71
|
|
|
|
|
|
|
my $objref = shift; |
72
|
|
|
|
|
|
|
my $sth = $objref->[0]; |
73
|
|
|
|
|
|
|
$sth->'.$name.'(@_) |
74
|
|
|
|
|
|
|
}'; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
goto &$name |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub DESTROY{ |
80
|
|
|
|
|
|
|
# autoloading this is poor form, considering it |
81
|
|
|
|
|
|
|
# is conceivable that we might have other references to the $sth |
82
|
0
|
|
|
0
|
|
|
@{$_[0]} = (); |
|
0
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
__END__ |