| 1 | package DBIO::SQLite; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: SQLite-specific schema management for DBIO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 42 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 42 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 42 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 42 | ▶ | use base 'DBIO::Base'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 42 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 42 | ▶ | use DBIO::SQLite::Extension (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 42 | __PACKAGE__->mk_classdata('_sqlite_extensions' => []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 42 | __PACKAGE__->mk_classdata('_sqlite_extension_options' => {}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 946 | ▶ | sub sqlite_extensions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sqlite_extensions: called CC=25 SCAR=32.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 946 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 946 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 43 | my (@names, %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 43 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 43 | ▶ | while (@args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 65 | my $name = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 65 | ▶ | Carp::croak(sprintf 'sqlite_extensions(): an extension name is expected, got %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition83%5/6
not defined $name or ref $name or not length $name
not defined $name or ref $name
MC/DC66%2/3
not defined $name or ref $name or not length $name
not defined $name
ref $name
not length $name
Truth table75%3/4
not(A) or B or not(C)
A= not defined $nameB= ref $nameC= not length $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ref $name ? 'a ' . ref($name) . ' reference' : defined $name ? "'$name'" : 'undef') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | if !defined $name || ref $name || !length $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 62 | ▶ | push @names, $name unless grep { $_ eq $name } @names; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 62 | ▶ | 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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 37 | my $opts = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 37 | ▶ | Carp::croak("sqlite_extensions(): the options of extension '$name' are a hashref") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | unless ref $opts eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 37 | ▶ | Carp::croak("sqlite_extensions(): extension '$name' has an empty options hashref; give 'library' or 'class'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | unless %$opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 36 | for my $key (sort keys %$opts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 38 | ▶ | Carp::croak(sprintf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "library" or $key eq "class"
MC/DC100%2/2
$key eq "library" or $key eq "class"
$key eq "library"
$key eq "class"
Truth table100%3/3
A or B
A= $key eq "library"B= $key eq "class"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | "sqlite_extensions(): extension '%s' has no option %s; the options are 'library' and 'class'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | $name, $key) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | unless $key eq 'library' || $key eq 'class'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | Carp::croak("sqlite_extensions(): extension '$name' needs a 'library', a plain non-empty string") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | if exists $opts->{library} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 35 | ▶ | && !(defined $opts->{library} && !ref $opts->{library} && length $opts->{library}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
exists $opts->{"library"} and not defined $opts->{"library"} && !ref($opts->{"library"}) && length $opts->{"library"}
defined $opts->{'library'} && !ref($opts->{'library'}) && length $opts->{'library'}
defined $opts->{"library"} and not ref $opts->{"library"}
MC/DC100%4/4
exists $opts->{"library"} and not defined $opts->{"library"} && !ref($opts->{"library"}) && length $opts->{"library"}
exists $opts->{"library"}
defined $opts->{"library"}
not ref $opts->{"library"}
length $opts->{'library'}
Truth table100%5/5
A and not(B and not(C) && D)
A= exists $opts->{"library"}B= defined $opts->{"library"}C= not ref $opts->{"library"}D= length $opts->{'library'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | Carp::croak("sqlite_extensions(): extension '$name' needs a 'class', a class name") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | if exists $opts->{class} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | && !(defined $opts->{class} && !ref $opts->{class} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 32 | ▶ | && $opts->{class} =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
exists $opts->{"class"} and not defined $opts->{"class"} && !ref($opts->{"class"}) && $opts->{"class"} =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/
defined $opts->{'class'} && !ref($opts->{'class'}) && $opts->{'class'} =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/
defined $opts->{"class"} and not ref $opts->{"class"}
MC/DC75%3/4
exists $opts->{"class"} and not defined $opts->{"class"} && !ref($opts->{"class"}) && $opts->{"class"} =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/
exists $opts->{"class"}
defined $opts->{"class"}
not ref $opts->{"class"}
$opts->{'class'} =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/
Truth table80%4/5
A and not(B and not(C) && D)
A= exists $opts->{"class"}B= defined $opts->{"class"}C= not ref $opts->{"class"}D= $opts->{'class'} =~ /\A[A-Za-z_]\w*(?:::\w+)*\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 29 | ▶ | $options{$name} = { %{ $options{$name} || {} }, %$opts }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$options{$name} || {}
MC/DC0%0/1
$options{$name} || {}
$options{$name}
Truth table50%1/2
A
A= $options{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 32 | $class->_sqlite_extensions(\@names); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 32 | $class->_sqlite_extension_options(\%options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 935 | return @{ $class->_sqlite_extensions }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 904 | ▶ | sub sqlite_extension_options { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sqlite_extension_options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 904 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 904 | my $own = $class->_sqlite_extension_options; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 904 | return { map { $_ => { %{ $own->{$_} } } } keys %$own }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 300 | ▶ | sub connection { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connection: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 300 | my ($self, @info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 300 | $self->storage_type('+DBIO::SQLite::Storage'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 300 | $self->_register_extension_layers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 300 | return $self->next::method(@info); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # The storage layer (ADR 0032) of every declared extension whose class names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # one is registered with core's register_storage_layer. An extension chooses | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # a layer, never the driver: the driver is the one this component pinned above. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 300 | ▶ | sub _register_extension_layers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_register_extension_layers: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 300 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 300 | ▶ | my $list = DBIO::SQLite::Extension->resolve_list($self, check_driver => 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 22 | for my $entry ($list->entries) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 36 | my $layer = $entry->{class}->storage_layer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 36 | ▶ | $self->register_storage_layer($layer) if defined $layer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 22 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 42 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||