blib/lib/DBIx/NamedBinding.pm

filter: Statementstmt 77.1% 27 / 35 Branchbran 20.0% 2 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 64.4% 38 / 59 CC 7 SCAR 23.3
CC
7
Cov
62%
bind_param
23.7
prepare
2.0
execute
2.0
CRAP 10.3
↑ Summary
1 package DBIx::NamedBinding;
2  
3 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 our $VERSION = '0.02';
9 3 our @ISA = 'DBI';
10  
11 package DBIx::NamedBinding::db;
12 3 ▶BEGIN { our @ISA = ('DBI::db') }
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶sub prepare {
Subroutine prepare: called CC=2 SCAR=6.9
15 1 my ($dbh, $statement, @args) = @_;
16 1 my @parameters = $statement =~ m/ : (\w+) \b /gx; # get param names
17 1 my $position = 1;
18 1 my $param_pos = { map { $_ => $position++ } @parameters };
19 1 $statement =~ s/ : \w+ \b /?/gx; # replace names w/ ?'s
20 1 ▶ my $sth = $dbh->SUPER::prepare($statement, @args)
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->SUPER::prepare($statement, @args) or return 1 0 1
21 or return;
22 1 $sth->{private_namedbinding_pos} = $param_pos;
23 1 return $sth;
24 }
25  
26 package DBIx::NamedBinding::st;
27 3 ▶BEGIN { our @ISA = ('DBI::st') }
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 ▶sub bind_param {
Subroutine bind_param: called CC=6 SCAR=31.7
30 1 my ($sth, $param, $value, $attr) = @_;
31 1 ▶ return $sth->set_err($DBI::stderr, "Missing named binding parameter", undef, "bind_param")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $param and $param 1 0 1
Condition33%1/3
defined $param and $param
!ll&&!rl&&r
100
MC/DC0%0/2
defined $param and $param
defined $param $param
Truth table33%1/3
A and B
A= defined $paramB= $param
ABresult
0X0
100
111
32 if !defined $param || !$param;
33 0 ▶ return $sth->set_err($DBI::stderr, "Invalid named binding parameter", undef, "bind_param")
Branch: 1 branch
BranchTrueFalseTotal
if $param =~ /\W/ 0 0 0
34 if $param =~ /\W/;
35 0 my $param_pos = $sth->{private_namedbinding_pos};
36 0 ▶ if ($param !~ /^\d+\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($param =~ /^\d+\Z/) 0 0 0
37 return $sth->set_err($DBI::stderr, "Named binding identifier '$param' was not used in preparing this statement handle",
38 undef, "bind_param")
39 0 ▶ if ! exists $param_pos->{$param};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $param_pos->{$param} 0 0 0
40 0 $param = $param_pos->{$param};
41 }
42 0 $sth->SUPER::bind_param($param, $value, $attr);
43 }
44  
45 0 ▶sub execute {
Subroutine execute: not called CC=1 SCAR=6.9
46 0 my ($sth, @params) = @_;
47 # I want to optionally handle named parameters via the execute method too
48 0 $sth->SUPER::execute(@params);
49 }
50  
51 3 1;
52  
53 __END__
↑ Summary