| 1 | package DBIx::QuickDB::Driver::SQLite; | ||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 5 | ▶ | use IPC::Cmd qw/can_run/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 5 | ▶ | use Scalar::Util qw/reftype/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 5 | our $VERSION = '0.000047'; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 5 | ▶ | use parent 'DBIx::QuickDB::Driver'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 5 | ▶ | use DBIx::QuickDB::Util::HashBase qw{-sqlite -started}; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 5 | my ($SQLITE, $DBDSQLITE); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | BEGIN { | ||||||||||||||||||||
| 17 | 5 | ▶ | local $@; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 5 | $SQLITE = can_run('sqlite3'); | |||||||||||||||||||
| 20 | 5 | $DBDSQLITE = eval { require DBD::SQLite; 'DBD::SQLite' }; | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | sub version_string { | ||||||||||||||||||||
| 24 | 0 | ▶ | my $binary; | ||||||||||||||||||
|
Subroutine
version_string: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | # Go in reverse order assuming the last param hash provided is most important | ||||||||||||||||||||
| 27 | 0 | for my $arg (reverse @_) { | |||||||||||||||||||
| 28 | 0 | ▶ | my $type = reftype($arg) or next; # skip if not a ref | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 0 | ▶ | next unless $type eq 'HASH'; # We have a hashref, possibly blessed | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | # If we find a launcher we are done looping, we want to use this binary. | ||||||||||||||||||||
| 32 | 0 | ▶ | $binary = $arg->{+SQLITE} and last; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | # If no args provided one to use we fallback to the default from $PATH | ||||||||||||||||||||
| 36 | 0 | ▶ | $binary ||= $SQLITE; | ||||||||||||||||||
|
Condition0%0/3
$binary ||= $SQLITE
MC/DC0%0/2
$binary ||= $SQLITE
$binary
$SQLITE
Truth table0%0/3
A ||= B
A= $binaryB= $SQLITE
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | ▶ | return 'unknown' unless $binary; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | # Call the binary with '-V', capturing and returning the output using backticks. | ||||||||||||||||||||
| 41 | 0 | return `$binary -version`; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 7 | ▶ | sub _default_paths { return (sqlite => $SQLITE) } | ||||||||||||||||||
|
Subroutine
_default_paths: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | sub viable { | ||||||||||||||||||||
| 47 | 7 | ▶ | my $this = shift; | ||||||||||||||||||
|
Subroutine
viable: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||
| 48 | 7 | my ($spec) = @_; | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 7 | ▶ | my %check = (ref($this) ? %$this : (), $this->_default_paths, %$spec); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 7 | my @bad; | |||||||||||||||||||
| 53 | 7 | ▶ | push @bad => "'DBD::SQLite' module could not be loaded, needed for everything" unless $DBDSQLITE; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 7 | ▶ | return (1, undef) unless @bad; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 7 | return (0, join "\n" => @bad); | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | sub init { | ||||||||||||||||||||
| 60 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
init: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 61 | 0 | $self->SUPER::init(); | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | my %defaults = $self->_default_paths; | |||||||||||||||||||
| 64 | 0 | ▶ | $self->{$_} ||= $defaults{$_} for keys %defaults; | ||||||||||||||||||
|
Condition0%0/3
$self->{$_} ||= $defaults{$_}
MC/DC0%0/2
$self->{$_} ||= $defaults{$_}
$self->{$_}
$defaults{$_}
Truth table0%0/3
A ||= B
A= $self->{$_}B= $defaults{$_}
| |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 0 | $self->{+STARTED} = 1; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 0 | return; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | ▶ | sub bootstrap { return } | ||||||||||||||||||
|
Subroutine
bootstrap: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 72 | 0 | ▶ | sub start { return } | ||||||||||||||||||
|
Subroutine
start: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 73 | 0 | ▶ | sub stop { return } | ||||||||||||||||||
|
Subroutine
stop: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | sub clone { | ||||||||||||||||||||
| 76 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 0 | local $self->{+STARTED} = 0; | |||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | return $self->SUPER::clone(@_); | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | sub connect_string { | ||||||||||||||||||||
| 84 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
connect_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 85 | 0 | my ($db_name) = @_; | |||||||||||||||||||
| 86 | 0 | ▶ | $db_name = 'quickdb' unless defined $db_name; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | my $dir = $self->{+DIR}; | |||||||||||||||||||
| 89 | 0 | my $path = "$dir/$db_name"; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | require DBD::SQLite; | |||||||||||||||||||
| 92 | 0 | return "dbi:SQLite:dbname=$path"; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | sub load_sql { | ||||||||||||||||||||
| 96 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
load_sql: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 97 | 0 | my ($db_name, $file) = @_; | |||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 0 | my $dbh = $self->connect($db_name, sqlite_allow_multiple_statements => 1, RaiseError => 1, AutoCommit => 1); | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | ▶ | open(my $fh, '<', $file) or die "Could not open file '$file': $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | 0 | my $sql = join "" => <$fh>; | |||||||||||||||||||
| 103 | 0 | close($fh); | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | ▶ | $dbh->do($sql) or die $dbh->errstr; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | sub shell_command { | ||||||||||||||||||||
| 109 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
shell_command: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 110 | 0 | my ($db_name) = @_; | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 0 | my $dir = $self->{+DIR}; | |||||||||||||||||||
| 113 | 0 | my $path = "$dir/$db_name"; | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 0 | return ($self->{+SQLITE}, $path); | |||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 5 | 1; | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||