blib/lib/DBIx/QuickDB/Driver/DuckDB.pm

filter: Statementstmt 47.2% 34 / 72 Branchbran 22.2% 4 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 9 / 18 Podpod 100% 9 / 9 totaltotal 44.0% 56 / 127 CC 14 SCAR 27.5
CC
14
Cov
40%
version_string
56.0
init
12.0
connect_string
6.0
CRAP 15.7
« lib/DBIx/QuickDB/Driver.pm ↑ Summary blib/lib/Test2/Tools/QuickDB.pm »
1 package DBIx::QuickDB::Driver::DuckDB;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use Scalar::Util qw/reftype/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use DBIx::QuickDB::Util qw/find_bin/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = '0.000066';
9  
10 4 ▶use parent 'DBIx::QuickDB::Driver';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶use DBIx::QuickDB::Util::HashBase qw{-duckdb -started};
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 my ($DUCKDB, $DBDDUCKDB);
15  
16 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.1
17 4 local $@;
18  
19 4 $DUCKDB = find_bin('duckdb');
20 0 $DBDDUCKDB = eval { require DBD::DuckDB; 'DBD::DuckDB' };
21 }
22  
23 0 ▶sub version_string {
Subroutine version_string: not called CC=7 SCAR=40.3
Pod documented
24 0 my $binary;
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
BranchTrueFalseTotal
my $type = builtin::reftype($arg) or next 0 0 0
29 0 ▶ next unless $type eq 'HASH'; # We have a hashref, possibly blessed
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "HASH" 0 0 0
30  
31 # If we find a launcher we are done looping, we want to use this binary.
32 0 ▶ $binary = $arg->{+DUCKDB} and last;
Branch: 1 branch
BranchTrueFalseTotal
$binary = $arg->{"duckdb"} and last 0 0 0
33 }
34  
35 # If no args provided one to use we fallback to the default from $PATH
36 0 ▶ $binary ||= $DUCKDB;
Condition0%0/3
$binary ||= $DUCKDB
l!l&&r!l&&!r
000
MC/DC0%0/2
$binary ||= $DUCKDB
$binary $DUCKDB
Truth table0%0/3
A ||= B
A= $binaryB= $DUCKDB
ABresult
1X1
011
000
37  
38 0 ▶ return 'unknown' unless $binary;
Branch: 1 branch
BranchTrueFalseTotal
unless $binary 0 0 0
39  
40 # Call the binary with '--version', capturing and returning the output using backticks.
41 0 return `$binary --version`;
42 }
43  
44 6 ▶sub _default_paths { return (duckdb => $DUCKDB) }
Subroutine _default_paths: called CC=1 SCAR=0.0
45  
46 6 ▶sub viable {
Subroutine viable: called CC=5 SCAR=16.8
Pod documented
47 6 my $this = shift;
48 6 my ($spec) = @_;
49  
50 6 ▶ my %check = (ref($this) ? %$this : (), $this->_default_paths, %$spec);
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 0 6 6
51  
52 6 my @bad;
53 6 ▶ push @bad => "'DBD::DuckDB' module could not be loaded, needed for connecting" unless $DBDDUCKDB;
Branch: 1 branch
BranchTrueFalseTotal
unless $DBDDUCKDB 6 0 6
54 6 ▶ push @bad => "'duckdb' command is missing, needed for loading SQL" unless $check{+DUCKDB};
Branch: 1 branch
BranchTrueFalseTotal
unless $check{"duckdb"} 6 0 6
55  
56 6 ▶ return (1, undef) unless @bad;
Branch: 1 branch
BranchTrueFalseTotal
unless @bad 0 6 6
57 6 return (0, join "\n" => @bad);
58 }
59  
60 0 ▶sub init {
Subroutine init: not called CC=3 SCAR=24.8
Pod documented
61 0 my $self = shift;
62 0 $self->SUPER::init();
63  
64 0 my %defaults = $self->_default_paths;
65 0 ▶ $self->{$_} ||= $defaults{$_} for keys %defaults;
Condition0%0/3
$self->{$_} ||= $defaults{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{$_} ||= $defaults{$_}
$self->{$_} $defaults{$_}
Truth table0%0/3
A ||= B
A= $self->{$_}B= $defaults{$_}
ABresult
1X1
011
000
66  
67 0 $self->{+STARTED} = 1;
68  
69 0 return;
70 }
71  
72 0 ▶sub bootstrap { return }
Subroutine bootstrap: not called CC=1 SCAR=6.9
73 0 ▶sub start { return }
Subroutine start: not called CC=1 SCAR=6.9
Pod documented
74 0 ▶sub stop { return }
Subroutine stop: not called CC=1 SCAR=6.9
Pod documented
75  
76 0 ▶sub clone {
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
77 0 my $self = shift;
78  
79 0 local $self->{+STARTED} = 0;
80  
81 0 return $self->SUPER::clone(@_);
82 }
83  
84 0 ▶sub connect_string {
Subroutine connect_string: not called CC=2 SCAR=17.9
Pod documented
85 0 my $self = shift;
86 0 my ($db_name) = @_;
87 0 ▶ $db_name = 'quickdb' unless defined $db_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $db_name 0 0 0
88  
89 0 my $dir = $self->{+DIR};
90 0 my $path = "$dir/$db_name";
91  
92 0 require DBD::DuckDB;
93 0 return "dbi:DuckDB:dbname=$path";
94 }
95  
96 0 ▶sub load_sql {
Subroutine load_sql: not called CC=1 SCAR=6.9
Pod documented
97 0 my $self = shift;
98 0 my ($db_name, $file) = @_;
99  
100 0 my $dir = $self->{+DIR};
101 0 my $path = "$dir/$db_name";
102  
103 # DBD::DuckDB cannot prepare multiple statements in one do(); the CLI reads
104 # statements from STDIN, so pipe the file through it.
105 0 $self->run_command([$self->{+DUCKDB}, $path], {stdin => $file});
106 }
107  
108 0 ▶sub shell_command {
Subroutine shell_command: not called CC=1 SCAR=6.9
Pod documented
109 0 my $self = shift;
110 0 my ($db_name) = @_;
111  
112 0 my $dir = $self->{+DIR};
113 0 my $path = "$dir/$db_name";
114  
115 0 return ($self->{+DUCKDB}, $path);
116 }
117  
118 4 1;
119  
120 __END__
« lib/DBIx/QuickDB/Driver.pm ↑ Summary blib/lib/Test2/Tools/QuickDB.pm »