| 1 | # $Id$ | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Data::ObjectDriver; | ||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use 5.006_001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Class::Accessor::Fast; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use base qw( Class::Accessor::Fast ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Data::ObjectDriver::Iterator; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | __PACKAGE__->mk_accessors(qw( pk_generator txn_active )); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | our $VERSION = '0.27'; | |||||||||||||||||||||||||||
| 15 | 1 | ▶ | our $DEBUG = $ENV{DOD_DEBUG} || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'DOD_DEBUG'} || 0
MC/DC0%0/1
$ENV{'DOD_DEBUG'} || 0
$ENV{'DOD_DEBUG'}
Truth table50%1/2
A
A= $ENV{'DOD_DEBUG'}
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | our $PROFILE = $ENV{DOD_PROFILE} || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'DOD_PROFILE'} || 0
MC/DC0%0/1
$ENV{'DOD_PROFILE'} || 0
$ENV{'DOD_PROFILE'}
Truth table50%1/2
A
A= $ENV{'DOD_PROFILE'}
| |||||||||||||||||||||||||||||
| 17 | 1 | our $PROFILER; | |||||||||||||||||||||||||||
| 18 | 1 | our $LOGGER; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 22 | 0 | my $driver = bless {}, $class; | |||||||||||||||||||||||||||
| 23 | 0 | $driver->init(@_); | |||||||||||||||||||||||||||
| 24 | 0 | $driver; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub logger { | ||||||||||||||||||||||||||
|
Subroutine
logger: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 0 | return $LOGGER = shift; | |||||||||||||||||||||||||||
| 31 | } else { | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | return $LOGGER ||= sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 33 | 0 | print STDERR @_; | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | }; | ||||||||||||||||||||||||||
|
Condition0%0/3
$Data::ObjectDriver::LOGGER ||= sub {
print STDERR @_;
}
MC/DC0%0/2
$Data::ObjectDriver::LOGGER ||= sub {
print STDERR @_;
}
$Data::ObjectDriver::LOGGER
sub {
print STDERR @_;
}
Truth table0%0/3
A ||= B
A= $Data::ObjectDriver::LOGGERB= sub {
print STDERR @_;
}
| |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 0 | my $driver = shift; | |||||||||||||||||||||||||||
| 40 | 0 | my %param = @_; | |||||||||||||||||||||||||||
| 41 | 0 | $driver->pk_generator($param{pk_generator}); | |||||||||||||||||||||||||||
| 42 | 0 | $driver->txn_active(0); | |||||||||||||||||||||||||||
| 43 | 0 | $driver; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # Alias record_query to start_query | ||||||||||||||||||||||||||||
| 47 | 1 | *record_query = \*start_query; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub start_query { | ||||||||||||||||||||||||||
|
Subroutine
start_query: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | 0 | my $driver = shift; | |||||||||||||||||||||||||||
| 51 | 0 | my($sql, $bind) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $driver->debug($sql, $bind) if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $driver->profiler($sql) if $PROFILE; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | return; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub end_query { } | ||||||||||||||||||||||||||
|
Subroutine
end_query: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub begin_work { | ||||||||||||||||||||||||||
|
Subroutine
begin_work: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 0 | my $driver = shift; | |||||||||||||||||||||||||||
| 63 | 0 | $driver->txn_active(1); | |||||||||||||||||||||||||||
| 64 | 0 | $driver->debug(sprintf("%14s", "BEGIN_WORK") . ": driver=$driver"); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub commit { | ||||||||||||||||||||||||||
|
Subroutine
commit: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 0 | my $driver = shift; | |||||||||||||||||||||||||||
| 69 | 0 | _end_txn($driver, 'commit'); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub rollback { | ||||||||||||||||||||||||||
|
Subroutine
rollback: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 0 | my $driver = shift; | |||||||||||||||||||||||||||
| 74 | 0 | _end_txn($driver, 'rollback'); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub _end_txn { | ||||||||||||||||||||||||||
|
Subroutine
_end_txn: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 78 | 0 | my $driver = shift; | |||||||||||||||||||||||||||
| 79 | 0 | my $method = shift; | |||||||||||||||||||||||||||
| 80 | 0 | $driver->txn_active(0); | |||||||||||||||||||||||||||
| 81 | 0 | $driver->debug(sprintf("%14s", uc($method)) . ": driver=$driver"); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub debug { | ||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 0 | my $driver = shift; | |||||||||||||||||||||||||||
| 86 | 0 | ▶ | return unless $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $class = ref $driver || $driver; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $driver || $driver
MC/DC0%0/2
ref $driver || $driver
ref $driver
$driver
Truth table0%0/3
A || B
A= ref $driverB= $driver
| |||||||||||||||||||||||||||||
| 89 | 0 | my @caller; | |||||||||||||||||||||||||||
| 90 | 0 | my $i = 0; | |||||||||||||||||||||||||||
| 91 | 0 | while (1) { | |||||||||||||||||||||||||||
| 92 | 0 | @caller = caller($i++); | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | last if $caller[0] !~ /^(Data::ObjectDriver|$class)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | my $where = " in file $caller[1] line $caller[2]\n"; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if (@_ == 1 && !ref($_[0])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 and not ref $_[0]
MC/DC0%0/2
@_ == 1 and not ref $_[0]
@_ == 1
not ref $_[0]
Truth table0%0/3
A and not(B)
A= @_ == 1B= not ref $_[0]
| |||||||||||||||||||||||||||||
| 99 | 0 | $driver->logger->( @_, $where ); | |||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||
| 101 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||
| 102 | 0 | local $Data::Dumper::Indent = 1; | |||||||||||||||||||||||||||
| 103 | 0 | $driver->logger->( Data::Dumper::Dumper(@_), $where ); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub profiler { | ||||||||||||||||||||||||||
|
Subroutine
profiler: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 108 | 0 | my $driver = shift; | |||||||||||||||||||||||||||
| 109 | 0 | my ($sql) = @_; | |||||||||||||||||||||||||||
| 110 | 0 | local $@; | |||||||||||||||||||||||||||
| 111 | 0 | ▶ | $PROFILER ||= eval { | ||||||||||||||||||||||||||
|
Condition0%0/3
$Data::ObjectDriver::PROFILER ||= eval {
do {
require Data::ObjectDriver::Profiler;
"Data::ObjectDriver::Profiler"->new
}
}
MC/DC0%0/2
$Data::ObjectDriver::PROFILER ||= eval {
do {
require Data::ObjectDriver::Profiler;
"Data::ObjectDriver::Profiler"->new
}
}
$Data::ObjectDriver::PROFILER
eval {
do {
require Data::ObjectDriver::Profiler;
"Data::ObjectDriver::Profiler"->new
}
}
Truth table0%0/3
A ||= B
A= $Data::ObjectDriver::PROFILERB= eval {
do {
require Data::ObjectDriver::Profiler;
"Data::ObjectDriver::Profiler"->new
}
}
| |||||||||||||||||||||||||||||
| 112 | 0 | require Data::ObjectDriver::Profiler; | |||||||||||||||||||||||||||
| 113 | 0 | Data::ObjectDriver::Profiler->new; | |||||||||||||||||||||||||||
| 114 | }; | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | return $PROFILE = 0 if $@ || !$PROFILER; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ or not $Data::ObjectDriver::PROFILER
MC/DC0%0/2
$@ or not $Data::ObjectDriver::PROFILER
$@
not $Data::ObjectDriver::PROFILER
Truth table0%0/3
A or not(B)
A= $@B= not $Data::ObjectDriver::PROFILER
| |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | return $PROFILER unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | $PROFILER->record_query($driver, $sql); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub list_or_iterator { | ||||||||||||||||||||||||||
|
Subroutine
list_or_iterator: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 121 | 0 | my $driver = shift; | |||||||||||||||||||||||||||
| 122 | 0 | my($objs) = @_; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | ## Emulate the standard search behavior of returning an | ||||||||||||||||||||||||||||
| 125 | ## iterator in scalar context, and the full list in list context. | ||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | return @{$objs}; | |||||||||||||||||||||||||||
| 128 | } else { | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | my $iter = sub { shift @{$objs} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 130 | 0 | return Data::ObjectDriver::Iterator->new($iter); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub cache_object { } | ||||||||||||||||||||||||||
|
Subroutine
cache_object: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub uncache_object { } | ||||||||||||||||||||||||||
|
Subroutine
uncache_object: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 1 | 1; | |||||||||||||||||||||||||||
| 138 | __END__ | ||||||||||||||||||||||||||||