| 1 | package DBIO::DuckDB; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: DuckDB-specific schema management for DBIO | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use base 'DBIO::Base'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use DBIO::DuckDB::Extension (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | __PACKAGE__->mk_classdata('_duckdb_extensions' => []); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | __PACKAGE__->mk_classdata('_duckdb_extension_classes' => {}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | sub connection { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connection: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | my ($self, @info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | $self->storage_type('+DBIO::DuckDB::Storage'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | $self->_register_extension_layers; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | return $self->next::method(@info); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # The classes are loaded and checked for their interface here, since the layer | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # has to be chosen before the storage is built; their driver assertion waits | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # for the first use of the connection. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | sub _register_extension_layers { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_register_extension_layers: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | my $list = DBIO::DuckDB::Extension->resolve_list($self, check_driver => 0) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | for my $entry ($list->entries) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | my $layer = $entry->{class}->storage_layer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | $self->register_storage_layer($layer) if defined $layer; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 30 | ▶ | sub duckdb_extensions { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
duckdb_extensions: called CC=16 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 30 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 30 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 17 | my (@names, %classes); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 17 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 17 | ▶ | while (@args) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 22 | my $name = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 22 | ▶ | Carp::croak(sprintf | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%6/6
not defined $name or ref $name or not length $name
not defined $name or ref $name
MC/DC100%3/3
not defined $name or ref $name or not length $name
not defined $name
ref $name
not length $name
Truth table100%4/4
not(A) or B or not(C)
A= not defined $nameB= ref $nameC= not length $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 'duckdb_extensions(): an extension name is expected, got %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | defined $name ? (ref $name ? 'a ' . ref($name) . ' reference' : "'$name'") : 'undef') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | if !defined $name || ref $name || !length $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 18 | push @names, $name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 18 | ▶ | next unless @args && ref $args[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@args and ref $args[0]
MC/DC100%2/2
@args and ref $args[0]
@args
ref $args[0]
Truth table100%3/3
A and B
A= @argsB= ref $args[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 12 | my $opts = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 12 | ▶ | Carp::croak("duckdb_extensions(): the options of extension '$name' are a hashref") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | unless ref $opts eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 12 | my @unknown = grep { $_ ne 'class' } sort keys %$opts; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | Carp::croak(sprintf | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | "duckdb_extensions(): extension '%s' has no option %s; the only option is 'class'", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 12 | ▶ | $name, join(', ', map { "'$_'" } @unknown)) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | if @unknown; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 11 | ▶ | Carp::croak("duckdb_extensions(): extension '$name' has an empty options hashref; give 'class'") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | unless keys %$opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 10 | my $extension_class = $opts->{class}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 10 | ▶ | Carp::croak("duckdb_extensions(): extension '$name' needs a 'class', a class name") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $extension_class and not ref $extension_class and $extension_class =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/
defined $extension_class and not ref $extension_class
MC/DC66%2/3
defined $extension_class and not ref $extension_class and $extension_class =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/
defined $extension_class
not ref $extension_class
$extension_class =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/
Truth table75%3/4
A and not(B) and C
A= defined $extension_classB= not ref $extension_classC= $extension_class =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | unless defined $extension_class && !ref $extension_class | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | && $extension_class =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 8 | $classes{$name} = $extension_class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 9 | $class->_duckdb_extensions(\@names); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 9 | $class->_duckdb_extension_classes(\%classes); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 22 | return @{ $class->_duckdb_extensions }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 14 | ▶ | sub duckdb_extension_classes { return { %{ $_[0]->_duckdb_extension_classes } } } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
duckdb_extension_classes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||