DBI/st_deep.pm

filter: Statementstmt 70.7% 58 / 82 Branchbran 65.6% 21 / 32 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 60.0% 9 / 15 Podpod 11.1% 1 / 9 totaltotal 63.1% 89 / 141 SCAR 33.5
CC
18
Cov
68%
tr_hash
13.1
fetchrow_hashref
12.0
execute
12.0
CRAP 28.5
« DBI/db.pm ↑ Summary DBI.pm »
1  
2 package Tao::DBI::st_deep;
3  
4 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 require Exporter;
9  
10 2 our @ISA = qw(Tao::DBI::st);
11 2 our @EXPORT = qw();
12  
13 2 our $VERSION = '0.01';
14  
15 2 ▶use Tao::DBI::st;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # instance variables:
19 # META
20  
21 # initiates a Tao::DBI::st_deep object
22 # { dbh => , sql => , meta => , }
23 sub initialize {
24 0 ▶ my ($self, $args) = @_;
Subroutine initialize: not called CC=1 SCAR=6.9
Pod undocumented
25 0 $self->SUPER::initialize($args);
26 0 $self->{META} = $args->{meta};
27 0 return $self
28 }
29  
30 ###############
31  
32 sub to_perl {
33 1 ▶ require Data::Dumper;
Subroutine to_perl: called CC=1 SCAR=0.0
Pod undocumented
34 1 return Data::Dumper::Dumper(shift);
35 }
36  
37 sub to_yaml {
38 0 ▶ require YAML;
Subroutine to_yaml: not called CC=1 SCAR=6.9
Pod undocumented
39 0 return YAML::Dump(shift);
40 }
41  
42 sub from_perl {
43 2 ▶ no strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶ my $data = eval shift; # oops! that's DANGEROUS!
Subroutine from_perl: called CC=2 SCAR=7.1
Pod undocumented
45 1 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
46 1 return $data;
47 }
48  
49 sub from_yaml {
50 0 ▶ require YAML;
Subroutine from_yaml: not called CC=1 SCAR=6.9
Pod undocumented
51 0 return YAML::Load(shift);
52 }
53  
54 2 my %tr_functions = (
55 ddumper => \&to_perl,
56 yaml => \&to_yaml,
57 );
58  
59 2 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 ▶ my $h = shift;
Subroutine tr_hash: called CC=13 SCAR=25.7
Pod undocumented
71 4 ▶ return undef unless defined $h;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h 0 4 4
72  
73 4 my $ctl = shift;
74 4 my $inv = shift;
75  
76 4 my %h = %$h;
77 4 my %g; # the result
78 my %m; # the visited keys
79 4 my @ctl = @$ctl;
80  
81 4 ▶ while (@ctl) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ctl) 12 4 16
82 12 my ($k, $fk) = split ':', shift @ctl;
83 12 my ($v, $fv) = split ':', shift @ctl;
84  
85 12 ▶ if ($inv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inv) 6 6 12
86 6 ($k, $v) = ($v, $k);
87 6 ($fk, $fv) = ($fv, $fk);
88 }
89  
90 12 ▶ if ($k eq '*') { # h{*} -> g{$k}
Branch: 2 branches
BranchTrueFalseTotal
if ($k eq '*') { } 2 10 12
elsif ($v eq '*') { } 2 8 10
91 2 ▶ while (my ($a, $b) = each %h) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %h) 10 2 12
92 10 ▶ $g{$v}{$a} = $b, $m{$a}++ unless $m{$a};
Branch: 1 branch
BranchTrueFalseTotal
unless $m{$a} 6 4 10
93 }
94 2 ▶ if ($fv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fv) 1 1 2
95 1 $g{$v} = &{ $tr_functions{$fv} }($g{$v});
96 }
97 } elsif ($v eq '*') { # h{$k} -> g{*}
98 2 ▶ if ($fk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fk) 1 1 2
99 1 $h{$k} = &{ $i_tr_functions{$fk} }($h{$k});
100 }
101 2 ▶ croak "val at '$k' (", (ref $h{$k} || 'non-ref scalar'), ") should be hashref" unless ref $h{$k} eq 'HASH'; # FIXME:
Branch: 1 branch
BranchTrueFalseTotal
unless ref $h{$k} eq "HASH" 0 2 2
Condition0%0/2
ref $h{$k} || 'non-ref scalar'
l!l
00
MC/DC0%0/1
ref $h{$k} || 'non-ref scalar'
ref $h{$k}
Truth table0%0/2
A
A= ref $h{$k}
Aresult
11
00
102 2 ▶ while (my ($a, $b) = each %{$h{$k}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$h{$k};}) 6 2 8
103 6 $g{$a} = $b;
104 }
105 2 $m{$k}++;
106 } else {
107 8 $g{$v} = $h{$k};
108 8 $m{$k}++;
109 }
110  
111 }
112  
113 4 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 ▶ my $self = shift;
Subroutine trace: not called CC=1 SCAR=6.9
Pod undocumented
125 0 return 0; # FIXME: $self->{TRACE} || $self->{DBH}->{TRACE}
126 }
127  
128 sub fetchrow_hashref {
129 0 ▶ my $self = shift;
Subroutine fetchrow_hashref: not called CC=3 SCAR=24.8
Pod undocumented
130 0 my $raw = $self->SUPER::fetchrow_hashref(@_);
131 0 ▶ return undef unless defined $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw 0 0 0
132 0 ▶ if ($self->trace) { require YAML; warn YAML::Dump({ RAW => $raw }) };
Branch: 1 branch
BranchTrueFalseTotal
if ($self->trace) 0 0 0
133 0 my $row = tr_hash($raw, $self->{META}, 1);
134 }
135  
136 sub execute {
137 0 ▶ my $self = shift;
Subroutine execute: not called CC=3 SCAR=24.8
Pod documented
138 0 my $bind_values = shift;
139 0 ▶ if (ref $bind_values) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $bind_values) { } 0 0 0
140 0 my $raw = {};
141 0 ▶ $raw = tr_hash($bind_values, $self->{META}) if $bind_values;
Branch: 1 branch
BranchTrueFalseTotal
if $bind_values 0 0 0
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__
« DBI/db.pm ↑ Summary DBI.pm »