| 1 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | $DBIx::Simple::VERSION = '1.37'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | $Carp::Internal{$_} = 1 | ||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | for qw(DBIx::Simple DBIx::Simple::Result DBIx::Simple::DeadObject); | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | my $no_raiseerror = $ENV{PERL_DBIX_SIMPLE_NO_RAISEERROR}; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | my $quoted = qr/(?:'[^']*'|"[^"]*")*/; # 'foo''bar' simply matches the (?:) twice | |||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | my $quoted_mysql = qr/(?:(?:[^\\']*(?:\\.[^\\']*)*)'|"(?:[^\\"]*(?:\\.[^\\"]*)*)")*/; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | my %statements; # "$db" => { "$st" => $st, ... } | |||||||||||||||||||||||||||||||||||||||||
| 16 | my %old_statements; # "$db" => [ [ $query, $st ], ... ] | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | my %keep_statements; # "$db" => $int | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | my $err_message = '%s no longer usable (because of %%s)'; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | my $err_cause = '%s at %s line %d'; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | package DBIx::Simple; | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | ### private helper subs | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub _dummy { bless \my $dummy, 'DBIx::Simple::Dummy' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dummy: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | sub _swap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_swap: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | my ($hash1, $hash2) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | my $tempref = ref $hash1; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | my $temphash = { %$hash1 }; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | %$hash1 = %$hash2; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | bless $hash1, ref $hash2; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | %$hash2 = %$temphash; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | bless $hash2, $tempref; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | ### constructor | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub connect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my ($class, @arguments) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $self = { lc_columns => 1, result_class => 'DBIx::Simple::Result' }; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if (defined $arguments[0] and UNIVERSAL::isa($arguments[0], 'DBI::db')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $arguments[0] and UNIVERSAL::isa($arguments[0], "DBI::db")
MC/DC0%0/2
defined $arguments[0] and UNIVERSAL::isa($arguments[0], "DBI::db")
defined $arguments[0]
UNIVERSAL::isa($arguments[0], "DBI::db")
Truth table0%0/3
A and B
A= defined $arguments[0]B= UNIVERSAL::isa($arguments[0], "DBI::db")
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $self->{dont_disconnect} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $self->{dbh} = shift @arguments; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | Carp::carp("Additional arguments for $class->connect are ignored") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | if @arguments; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | $arguments[3]->{PrintError} = 0 | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | unless defined $arguments[3] and exists $arguments[3]{PrintError}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $arguments[3] and exists $arguments[3]{"PrintError"}
MC/DC0%0/2
defined $arguments[3] and exists $arguments[3]{"PrintError"}
defined $arguments[3]
exists $arguments[3]{"PrintError"}
Truth table0%0/3
A and B
A= defined $arguments[3]B= exists $arguments[3]{"PrintError"}
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | $arguments[3]->{RaiseError} = 1 | ||||||||||||||||||||||||||||||||||||||||||
| 51 | unless $no_raiseerror | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | or defined $arguments[3] and exists $arguments[3]{RaiseError}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$no_raiseerror or defined $arguments[3] and exists $arguments[3]{"RaiseError"}
defined $arguments[3] and exists $arguments[3]{"RaiseError"}
MC/DC0%0/3
$no_raiseerror or defined $arguments[3] and exists $arguments[3]{"RaiseError"}
$no_raiseerror
defined $arguments[3]
exists $arguments[3]{"RaiseError"}
Truth table0%0/4
A or B and C
A= $no_raiseerrorB= defined $arguments[3]C= exists $arguments[3]{"RaiseError"}
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $self->{dbh} = DBI->connect(@arguments); | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | return undef unless $self->{dbh}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $self->{dbd} = $self->{dbh}->{Driver}->{Name}; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $statements{$self} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $old_statements{$self} = []; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $keep_statements{$self} = 16; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my ($class) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $class->connect(@_); | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | ### properties | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub keep_statements : lvalue { $keep_statements{ $_[0] } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keep_statements: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub lc_columns : lvalue { $_[0]->{lc_columns} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lc_columns: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub result_class : lvalue { $_[0]->{result_class} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
result_class: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub abstract : lvalue { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
abstract: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | require SQL::Abstract; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $_[0]->{abstract} ||= SQL::Abstract->new; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_[0]{"abstract"} ||= "SQL::Abstract"->new
MC/DC0%0/2
$_[0]{"abstract"} ||= "SQL::Abstract"->new
$_[0]{"abstract"}
"SQL::Abstract"->new
Truth table0%0/3
A ||= B
A= $_[0]{"abstract"}B= "SQL::Abstract"->new
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | return 'DBI error: ' . (ref $self ? $self->{dbh}->errstr : $DBI::errstr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub dbh { $_[0]->{dbh} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dbh: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | ### private methods | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | # Replace (??) with (?, ?, ?, ...) | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub _replace_omniholder { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_replace_omniholder: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my ($self, $query, $binds) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | return if $$query !~ /\(\?\?\)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $omniholders = 0; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | my $q = $self->{dbd} =~ /mysql/ ? $quoted_mysql : $quoted; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $$query =~ s[($q|\(\?\?\))] { | |||||||||||||||||||||||||||||||||||||||||
| 100 | $1 eq '(??)' | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | ? do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | Carp::croak('There can be only one omniholder') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | if $omniholders++; | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | '(' . join(', ', ('?') x @$binds) . ')' | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | : $1 | ||||||||||||||||||||||||||||||||||||||||||
| 107 | }eg; | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | # Invalidate and clean up | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub _die { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_die: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my ($self, $cause) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | defined and $_->_die($cause, 0) | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | for values %{ $statements{$self} }, | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | map $$_[1], @{ $old_statements{$self} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | delete $statements{$self}; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | delete $old_statements{$self}; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | delete $keep_statements{$self}; | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | unless ($self->{dont_disconnect}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | # Conditional, because destruction order is not guaranteed | ||||||||||||||||||||||||||||||||||||||||||
| 123 | # during global destruction. | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | $self->{dbh}->disconnect() if defined $self->{dbh}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | _swap( | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | $self, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | bless { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | what => 'Database object', | ||||||||||||||||||||||||||||||||||||||||||
| 131 | cause => $cause | ||||||||||||||||||||||||||||||||||||||||||
| 132 | }, 'DBIx::Simple::DeadObject' | ||||||||||||||||||||||||||||||||||||||||||
| 133 | ) unless $cause =~ /DESTROY/; # Let's not cause infinite loops :) | ||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | ### public methods | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my ($self, $query, @binds) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $self->{success} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $self->_replace_omniholder(\$query, \@binds); | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $st; | |||||||||||||||||||||||||||||||||||||||||
| 145 | my $sth; | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my $old = $old_statements{$self}; | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if (defined( my $i = (grep $old->[$_][0] eq $query, 0..$#$old)[0] )) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $st = splice(@$old, $i, 1)->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $sth = $st->{sth}; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | eval { $sth = $self->{dbh}->prepare($query) } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $@ =~ s/ at \S+ line \d+\.\n\z//; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | Carp::croak($@); | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $self->{reason} = "Prepare failed ($DBI::errstr)"; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | return _dummy; | |||||||||||||||||||||||||||||||||||||||||
| 160 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | # $self is quoted on purpose, to pass along the stringified version, | ||||||||||||||||||||||||||||||||||||||||||
| 163 | # and avoid increasing reference count. | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $st = bless { | |||||||||||||||||||||||||||||||||||||||||
| 165 | db => "$self", | ||||||||||||||||||||||||||||||||||||||||||
| 166 | sth => $sth, | ||||||||||||||||||||||||||||||||||||||||||
| 167 | query => $query | ||||||||||||||||||||||||||||||||||||||||||
| 168 | }, 'DBIx::Simple::Statement'; | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $statements{$self}{$st} = $st; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | eval { $sth->execute(@binds) } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | $@ =~ s/ at \S+ line \d+\.\n\z//; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | Carp::croak($@); | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $self->{reason} = "Execute failed ($DBI::errstr)"; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | return _dummy; | |||||||||||||||||||||||||||||||||||||||||
| 180 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $self->{success} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | return bless { st => $st, lc_columns => $self->{lc_columns} }, $self->{result_class}; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | sub begin_work { $_[0]->{dbh}->begin_work } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
begin_work: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | sub begin { $_[0]->begin_work } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
begin: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | sub commit { $_[0]->{dbh}->commit } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
commit: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub rollback { $_[0]->{dbh}->rollback } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rollback: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | sub func { shift->{dbh}->func(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
func: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | sub last_insert_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last_insert_id: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | ($self->{dbi_version} ||= DBI->VERSION) >= 1.38 or Carp::croak( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"dbi_version"} ||= "DBI"->VERSION
MC/DC0%0/2
$self->{"dbi_version"} ||= "DBI"->VERSION
$self->{"dbi_version"}
"DBI"->VERSION
Truth table0%0/3
A ||= B
A= $self->{"dbi_version"}B= "DBI"->VERSION
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | "DBI v1.38 required for last_insert_id" . | ||||||||||||||||||||||||||||||||||||||||||
| 198 | "--this is only $self->{dbi_version}, stopped" | ||||||||||||||||||||||||||||||||||||||||||
| 199 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | return shift->{dbh}->last_insert_id(@_); | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub disconnect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $self->_die(sprintf($err_cause, "$self->disconnect", (caller)[1, 2])); | |||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $self->_die(sprintf($err_cause, "$self->DESTROY", (caller)[1, 2])); | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | ### public methods wrapping SQL::Abstract | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | for my $method (qw/select insert update delete/) { | |||||||||||||||||||||||||||||||||||||||||
| 218 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | *$method = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | return $self->query($self->abstract->$method(@_)); | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 8 | } | |||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | ### public method wrapping SQL::Interp | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | sub iquery { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iquery: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | require SQL::Interp; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | return $self->query( SQL::Interp::sql_interp(@_) ); | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | package DBIx::Simple::Dummy; | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | use overload | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | '""' => sub { shift }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | bool => sub { 0 }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | sub new { bless \my $dummy, shift } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | sub AUTOLOAD { return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | package DBIx::Simple::DeadObject; | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | sub _die { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_die: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 246 | Carp::croak( | ||||||||||||||||||||||||||||||||||||||||||
| 247 | sprintf( | ||||||||||||||||||||||||||||||||||||||||||
| 248 | "(This should NEVER happen!) " . | ||||||||||||||||||||||||||||||||||||||||||
| 249 | sprintf($err_message, $self->{what}), | ||||||||||||||||||||||||||||||||||||||||||
| 250 | $self->{cause} | ||||||||||||||||||||||||||||||||||||||||||
| 251 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 257 | Carp::croak( | ||||||||||||||||||||||||||||||||||||||||||
| 258 | sprintf( | ||||||||||||||||||||||||||||||||||||||||||
| 259 | sprintf($err_message, $self->{what}), | ||||||||||||||||||||||||||||||||||||||||||
| 260 | $self->{cause} | ||||||||||||||||||||||||||||||||||||||||||
| 261 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub DESTROY { } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | package DBIx::Simple::Statement; | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub _die { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_die: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my ($self, $cause, $save) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | $self->{sth}->finish() if defined $self->{sth}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | $self->{dead} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $stringy_db = "$self->{db}"; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $stringy_self = "$self"; | |||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my $foo = bless { | |||||||||||||||||||||||||||||||||||||||||
| 278 | what => 'Statement object', | ||||||||||||||||||||||||||||||||||||||||||
| 279 | cause => $cause | ||||||||||||||||||||||||||||||||||||||||||
| 280 | }, 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | DBIx::Simple::_swap($self, $foo); | |||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my $old = $old_statements{ $foo->{db} }; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $keep = $keep_statements{ $foo->{db} }; | |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | if ($save and $keep) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$save and $keep
MC/DC0%0/2
$save and $keep
$save
$keep
Truth table0%0/3
A and B
A= $saveB= $keep
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $foo->{dead} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | shift @$old until @$old + 1 <= $keep; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | push @$old, [ $foo->{query}, $foo ]; | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | delete $statements{ $stringy_db }{ $stringy_self }; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | # This better only happen during global destruction... | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | return if $_[0]->{dead}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $_[0]->_die('Ehm', 0); | |||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | package DBIx::Simple::Result; | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | sub _die { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_die: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my ($self, $cause) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if ($cause) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | $self->{st}->_die($cause, 1); | |||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | DBIx::Simple::_swap( | |||||||||||||||||||||||||||||||||||||||||
| 309 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 310 | bless { | ||||||||||||||||||||||||||||||||||||||||||
| 311 | what => 'Result object', | ||||||||||||||||||||||||||||||||||||||||||
| 312 | cause => $cause, | ||||||||||||||||||||||||||||||||||||||||||
| 313 | }, 'DBIx::Simple::DeadObject' | ||||||||||||||||||||||||||||||||||||||||||
| 314 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 315 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | $cause = $self->{st}->{cause}; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | DBIx::Simple::_swap( | |||||||||||||||||||||||||||||||||||||||||
| 318 | $self, | ||||||||||||||||||||||||||||||||||||||||||
| 319 | bless { | ||||||||||||||||||||||||||||||||||||||||||
| 320 | what => 'Result object', | ||||||||||||||||||||||||||||||||||||||||||
| 321 | cause => $cause | ||||||||||||||||||||||||||||||||||||||||||
| 322 | }, 'DBIx::Simple::DeadObject' | ||||||||||||||||||||||||||||||||||||||||||
| 323 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 324 | Carp::croak( | ||||||||||||||||||||||||||||||||||||||||||
| 325 | sprintf( | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | sprintf($err_message, $self->{what}), | |||||||||||||||||||||||||||||||||||||||||
| 327 | $cause | ||||||||||||||||||||||||||||||||||||||||||
| 328 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 329 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | sub func { shift->{st}->{sth}->func(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
func: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | sub attr { my $dummy = $_[0]->{st}->{sth}->{$_[1]} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attr: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | sub columns { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
columns: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | my $c = $_[0]->{st}->{sth}->{ $_[0]->{lc_columns} ? 'NAME_lc' : 'NAME' }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | return wantarray ? @$c : $c; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | sub bind { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $_[0]->{st}->{sth}->bind_columns(\@_[1..$#_]); | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | ### Single | ||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | sub fetch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | return $_[0]->{st}->{sth}->fetch; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | sub into { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
into: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my $sth = $_[0]->{st}->{sth}; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | $sth->bind_columns(\@_[1..$#_]) if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | return $sth->fetch; | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | sub list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | return $_[0]->{st}->{sth}->fetchrow_array if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | return($_[0]->{st}->{sth}->fetchrow_array)[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | sub array { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
array: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | my $row = $_[0]->{st}->{sth}->fetchrow_arrayref or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | return [ @$row ]; | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | sub hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hash: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | return $_[0]->{st}->{sth}->fetchrow_hashref( | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | $_[0]->{lc_columns} ? 'NAME_lc' : 'NAME' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | sub kv_list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
kv_list: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | my @keys = $_[0]->columns; | |||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | my $values = $_[0]->array or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | Carp::croak("Different numbers of column names and values") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | if @keys != @$values; | ||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | return map { $keys[$_], $values->[$_] } 0 .. $#keys if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | return [ map { $keys[$_], $values->[$_] } 0 .. $#keys ]; | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | sub kv_array { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
kv_array: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | scalar shift->kv_list(@_); | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | sub object { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
object: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | my $class = shift || ':RowObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || ':RowObject'
MC/DC0%0/1
shift() || ':RowObject'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $class =~ s/^:/DBIx::Simple::Result::/; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | if (not $class->can('new_from_dbix_simple') || $class->can('new')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$class->can("new_from_dbix_simple") or $class->can("new")
MC/DC0%0/2
$class->can("new_from_dbix_simple") or $class->can("new")
$class->can("new_from_dbix_simple")
$class->can("new")
Truth table0%0/3
A or B
A= $class->can("new_from_dbix_simple")B= $class->can("new")
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | (my $filename = "$class.pm") =~ s[::][/]g; | |||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | require $filename; | |||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | if ($class->can('new_from_dbix_simple')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | return scalar $class->new_from_dbix_simple($self, @_); | |||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | if ($class->can('new')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | return $class->new( $self->kv_list ); | |||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | Carp::croak( | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | qq(Can't locate object method "new_from_dbix_simple" or "new" ) . | |||||||||||||||||||||||||||||||||||||||||
| 413 | qq(via package "$class".) | ||||||||||||||||||||||||||||||||||||||||||
| 414 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | ### Slurp | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | sub flat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flat: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | return map @$_, $_[0]->arrays if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | return [ map @$_, $_[0]->arrays ]; | |||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | sub arrays { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
arrays: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | return @{ $_[0]->{st}->{sth}->fetchall_arrayref } if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | return $_[0]->{st}->{sth}->fetchall_arrayref; | |||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | sub hashes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hashes: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | my @return; | |||||||||||||||||||||||||||||||||||||||||
| 434 | my $dummy; | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | push @return, $dummy while $dummy = $_[0]->hash; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | return wantarray ? @return : \@return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | sub kv_flat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
kv_flat: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | return map @$_, $_[0]->kv_arrays if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | return [ map @$_, $_[0]->kv_arrays ]; | |||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | sub kv_arrays { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
kv_arrays: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | my @return; | |||||||||||||||||||||||||||||||||||||||||
| 448 | my $dummy; | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | push @return, $dummy while $dummy = $_[0]->kv_array; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | return wantarray ? @return : \@return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | sub objects { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
objects: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | my $class = shift || ':RowObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || ':RowObject'
MC/DC0%0/1
shift() || ':RowObject'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $class =~ s/^:/DBIx::Simple::Result::/; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | if (not $class->can('new_from_dbix_simple') || $class->can('new')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$class->can("new_from_dbix_simple") or $class->can("new")
MC/DC0%0/2
$class->can("new_from_dbix_simple") or $class->can("new")
$class->can("new_from_dbix_simple")
$class->can("new")
Truth table0%0/3
A or B
A= $class->can("new_from_dbix_simple")B= $class->can("new")
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | (my $package = "$class.pm") =~ s[::][/]g; | |||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | require $package; | |||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | if ($class->can('new_from_dbix_simple')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | return $class->new_from_dbix_simple($self, @_) if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | return [ $class->new_from_dbix_simple($self, @_) ]; | |||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | if ($class->can('new')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | ▶ | return map { $class->new( @$_ ) } $self->kv_arrays if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | return [ map { $class->new( @$_ ) } $self->kv_arrays ]; | |||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | Carp::croak( | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | qq(Can't locate object method "new_from_dbix_simple" or "new" ) . | |||||||||||||||||||||||||||||||||||||||||
| 472 | qq(via package "$class" (perhaps you forgot to load "$class"?)) | ||||||||||||||||||||||||||||||||||||||||||
| 473 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | sub _map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_map: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | my ($keys, $values) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | my %return; | |||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | @return{@$keys} = @$values; | |||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | return wantarray ? %return : \%return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | sub _group { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_group: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | my ($keys, $values) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | my %return; | |||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | push @{ $return{shift @$keys} }, shift @$values while @$values; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | return wantarray ? %return : \%return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | sub _keys_and_hashes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_keys_and_hashes: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my ($self, $keyname) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | Carp::croak('Key column name not optional') if not defined $keyname; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | my @rows = $self->hashes; | |||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | my @keys; | |||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | push @keys, delete $_->{$keyname} for @rows; | |||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | return \@keys, \@rows; | |||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | sub _keys_and_arrays { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_keys_and_arrays: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | my ($self, $keyindex) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | $keyindex += 0; | |||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | my @rows = $self->arrays; | |||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | my @keys; | |||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | push @keys, splice @$_, $keyindex, 1 for @rows; | |||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | return \@keys, \@rows; | |||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | sub group_hashes { return _group shift->_keys_and_hashes(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
group_hashes: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | sub map_hashes { return _map shift->_keys_and_hashes(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map_hashes: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | sub group_arrays { return _group shift->_keys_and_arrays(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
group_arrays: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | sub map_arrays { return _map shift->_keys_and_arrays(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map_arrays: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | sub map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | return map @$_, @{ $_[0]->{st}->{sth}->fetchall_arrayref } if wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | return { map @$_, @{ $_[0]->{st}->{sth}->fetchall_arrayref } }; | |||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | sub group { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
group: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | my %return; | |||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | ▶ | while (my $row = $_[0]->fetch) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | push @{ $return{ $row->[0] } }, $row->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | ▶ | return wantarray ? %return : \%return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | sub rows { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rows: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | $_[0]->{st}->{sth}->rows; | |||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | ▶ | sub xto { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xto: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | require DBIx::XHTML_Table; | |||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | ▶ | my $attr = ref $_[0] ? $_[0] : { @_ }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | # Old DBD::SQLite (.29) spits out garbage if done *after* fetching. | ||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | my $columns = $self->{st}->{sth}->{NAME}; | |||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | return DBIx::XHTML_Table->new( | |||||||||||||||||||||||||||||||||||||||||
| 545 | scalar $self->arrays, | ||||||||||||||||||||||||||||||||||||||||||
| 546 | $columns, | ||||||||||||||||||||||||||||||||||||||||||
| 547 | $attr | ||||||||||||||||||||||||||||||||||||||||||
| 548 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | sub html { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
html: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | ▶ | my $attr = ref $_[0] ? $_[0] : { @_ }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | return $self->xto($attr)->output($attr); | |||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | ▶ | sub text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 561 | my $text_table = defined $type && length $type | ||||||||||||||||||||||||||||||||||||||||||
| 562 | ? 0 | ||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | ▶ | : eval { require Text::Table; $type = 'table'; 1 }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $type and length $type
MC/DC0%0/2
defined $type and length $type
defined $type
length $type
Truth table0%0/3
A and B
A= defined $typeB= length $type
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | $type ||= 'neat'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$type ||= "neat"
MC/DC0%0/1
$type ||= "neat"
$type
Truth table0%0/2
A
A= $type
| |||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | if ($type eq 'box' or $type eq 'table') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type eq "box" or $type eq "table"
MC/DC0%0/2
$type eq "box" or $type eq "table"
$type eq "box"
$type eq "table"
Truth table0%0/3
A or B
A= $type eq "box"B= $type eq "table"
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | my $box = $type eq 'box'; | |||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | $text_table or require Text::Table; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | my @columns = map +{ title => $_, align_title => 'center' }, | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | @{ $self->{st}->{sth}->{NAME} }; | |||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | my $c = 0; | |||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | splice @columns, $_ + $c++, 0, \' | ' for 1 .. $#columns; | |||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | my $table = Text::Table->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 573 | ($box ? \'| ' : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 574 | @columns, | ||||||||||||||||||||||||||||||||||||||||||
| 575 | ($box ? \' |' : ()) | ||||||||||||||||||||||||||||||||||||||||||
| 576 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | $table->load($self->arrays); | |||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | my $rule = $table->rule(qw/- +/); | |||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | return join '', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | ($box ? $rule : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 581 | $table->title, $rule, $table->body, | ||||||||||||||||||||||||||||||||||||||||||
| 582 | ($box ? $rule : ()); | ||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | Carp::carp("Unknown type '$type'; using 'neat'") if $type ne 'neat'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | return join '', map DBI::neat_list($_) . "\n", $self->arrays; | |||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | ▶ | sub finish { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finish: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | ▶ | $_[0]->_die if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | $self->_die( | |||||||||||||||||||||||||||||||||||||||||
| 592 | sprintf($err_cause, "$self->finish", (caller)[1, 2]) | ||||||||||||||||||||||||||||||||||||||||||
| 593 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | ▶ | return if ref $_[0]->{st} eq 'DBIx::Simple::DeadObject'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | $self->_die( | |||||||||||||||||||||||||||||||||||||||||
| 600 | sprintf($err_cause, "$self->DESTROY", (caller)[1, 2]) | ||||||||||||||||||||||||||||||||||||||||||
| 601 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||
| 604 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||
| 606 | __END__ | ||||||||||||||||||||||||||||||||||||||||||