| 1 | package DBD::Mock; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # --------------------------------------------------------------------------- # | ||||||||||||||||||||||||||||
| 4 | # Copyright (c) 2004-2007 Stevan Little, Chris Winters | ||||||||||||||||||||||||||||
| 5 | # (spawned from original code Copyright (c) 1994 Tim Bunce) | ||||||||||||||||||||||||||||
| 6 | # --------------------------------------------------------------------------- # | ||||||||||||||||||||||||||||
| 7 | # You may distribute under the terms of either the GNU General Public | ||||||||||||||||||||||||||||
| 8 | # License or the Artistic License, as specified in the Perl README file. | ||||||||||||||||||||||||||||
| 9 | # --------------------------------------------------------------------------- # | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 41 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 41 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 41 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 41 | ▶ | use DBI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 41 | ▶ | use DBD::Mock::dr; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 41 | ▶ | use DBD::Mock::db; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 41 | ▶ | use DBD::Mock::st; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 41 | ▶ | use DBD::Mock::StatementTrack; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 41 | ▶ | use DBD::Mock::StatementTrack::Iterator; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 41 | ▶ | use DBD::Mock::Session; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 41 | ▶ | use DBD::Mock::Pool; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 41 | ▶ | use DBD::Mock::Pool::db; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 34 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 28 | 34 | shift; | |||||||||||||||||||||||||||
| 29 | 34 | ▶ | $DBI::connect_via = "DBD::Mock::Pool::connect" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and lc $_[0] eq "pool"
MC/DC50%1/2
@_ and lc $_[0] eq "pool"
@_
lc $_[0] eq "pool"
Truth table66%2/3
A and B
A= @_B= lc $_[0] eq "pool"
| |||||||||||||||||||||||||||||
| 30 | if ( @_ && lc( $_[0] ) eq "pool" ); | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 41 | our $VERSION = '1.60'; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 41 | our $drh = undef; # will hold driver handle | |||||||||||||||||||||||||||
| 36 | 41 | our $err = 0; # will hold any error codes | |||||||||||||||||||||||||||
| 37 | 41 | our $errstr = ''; # will hold any error messages | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # Defaulting a result set's fields to undef changes the way DBD::Mock responds, so we default it to off | ||||||||||||||||||||||||||||
| 40 | 41 | our $DefaultFieldsToUndef = 0; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 38 | ▶ | sub driver { | ||||||||||||||||||||||||||
|
Subroutine
driver: called CC=4 SCAR=15.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 38 | ▶ | return $drh if defined $drh; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 38 | my ( $class, $attributes ) = @_; | |||||||||||||||||||||||||||
| 46 | 38 | ▶ | $attributes = {} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $attributes and ref $attributes eq "HASH"
MC/DC0%0/2
defined $attributes and ref $attributes eq "HASH"
defined $attributes
ref $attributes eq "HASH"
Truth table33%1/3
A and B
A= defined $attributesB= ref $attributes eq "HASH"
| |||||||||||||||||||||||||||||
| 47 | unless ( defined($attributes) && ( ref($attributes) eq 'HASH' ) ); | ||||||||||||||||||||||||||||
| 48 | $drh = DBI::_new_drh( | ||||||||||||||||||||||||||||
| 49 | "${class}::dr", | ||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||
| 51 | Name => 'Mock', | ||||||||||||||||||||||||||||
| 52 | Version => $DBD::Mock::VERSION, | ||||||||||||||||||||||||||||
| 53 | Attribution => | ||||||||||||||||||||||||||||
| 54 | 'DBD Mock driver by Chris Winters & Stevan Little (orig. from Tim Bunce)', | ||||||||||||||||||||||||||||
| 55 | Err => \$DBD::Mock::err, | ||||||||||||||||||||||||||||
| 56 | Errstr => \$DBD::Mock::errstr, | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # mock attributes | ||||||||||||||||||||||||||||
| 59 | mock_connect_fail => 0, | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # and pass in any extra attributes given | ||||||||||||||||||||||||||||
| 62 | 38 | %{$attributes} | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | 38 | return $drh; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub CLONE { undef $drh } | ||||||||||||||||||||||||||
|
Subroutine
CLONE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # NOTE: | ||||||||||||||||||||||||||||
| 71 | # this feature is still quite experimental. It is defaulted to | ||||||||||||||||||||||||||||
| 72 | # be off, but it can be turned on by doing this: | ||||||||||||||||||||||||||||
| 73 | # $DBD::Mock::AttributeAliasing++; | ||||||||||||||||||||||||||||
| 74 | # and then turned off by doing: | ||||||||||||||||||||||||||||
| 75 | # $DBD::Mock::AttributeAliasing = 0; | ||||||||||||||||||||||||||||
| 76 | # we shall see how this feature works out. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 41 | our $AttributeAliasing = 0; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | my %AttributeAliases = ( | ||||||||||||||||||||||||||||
| 81 | mysql => { | ||||||||||||||||||||||||||||
| 82 | db => { | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # aliases can either be a string which is obvious | ||||||||||||||||||||||||||||
| 85 | mysql_insertid => 'mock_last_insert_id' | ||||||||||||||||||||||||||||
| 86 | }, | ||||||||||||||||||||||||||||
| 87 | st => { | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # but they can also be a subroutine reference whose | ||||||||||||||||||||||||||||
| 90 | # first argument will be either the $dbh or the $sth | ||||||||||||||||||||||||||||
| 91 | # depending upon which context it is aliased in. | ||||||||||||||||||||||||||||
| 92 | mysql_insertid => | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub { (shift)->{Database}->{'mock_last_insert_id'} } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | }, | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | mariadb => { | ||||||||||||||||||||||||||||
| 98 | db => { | ||||||||||||||||||||||||||||
| 99 | mariadb_insertid => 'mock_last_insert_id' | ||||||||||||||||||||||||||||
| 100 | }, | ||||||||||||||||||||||||||||
| 101 | st => { | ||||||||||||||||||||||||||||
| 102 | mariadb_insertid => | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub { (shift)->{Database}->{'mock_last_insert_id'} } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 41 | ); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 7 | ▶ | sub _get_mock_attribute_aliases { | ||||||||||||||||||||||||||
|
Subroutine
_get_mock_attribute_aliases: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 109 | 7 | my ($dbname) = @_; | |||||||||||||||||||||||||||
| 110 | 7 | ▶ | ( exists $AttributeAliases{ lc($dbname) } ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | || die "Attribute aliases not available for '$dbname'"; | ||||||||||||||||||||||||||||
| 112 | 6 | return $AttributeAliases{ lc($dbname) }; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub _set_mock_attribute_aliases { | ||||||||||||||||||||||||||
|
Subroutine
_set_mock_attribute_aliases: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 116 | 0 | my ( $dbname, $dbh_or_sth, $key, $value ) = @_; | |||||||||||||||||||||||||||
| 117 | 0 | return $AttributeAliases{ lc($dbname) }->{$dbh_or_sth}->{$key} = $value; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | ## Some useful constants | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 41 | ▶ | use constant NULL_RESULTSET => [ [] ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 41 | 1; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | __END__ | ||||||||||||||||||||||||||||