| 1 | package DBIO::SQLite::Extension::VirtualTable; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Base of the extension classes of SQLite modules that keep shadow tables | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use base 'DBIO::SQLite::Extension'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use DBIO::SQLite::Util qw(sql_tokens create_name_index token_identifier); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub module { die ref($_[0]) || $_[0], " must define module\n" } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
module: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub shadow_suffixes { die ref($_[0]) || $_[0], " must define shadow_suffixes\n" } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shadow_suffixes: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 57 | ▶ | sub name { $_[0]->module } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 55 | ▶ | sub inspect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inspect: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 55 | my ($class, $ctx) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 55 | my $dbh = $ctx->{dbh}; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 55 | my $module = $class->module; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 55 | my $modules = eval { $dbh->selectcol_arrayref('PRAGMA module_list') }; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 55 | ▶ | my $available = $modules ? ((grep { lc $_ eq $module } @$modules) ? 1 : 0) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 55 | my $rows = $dbh->selectall_arrayref(q{ | |||||||||||||||||||||||||||||||||||||||||
| 29 | SELECT name, sql FROM sqlite_master | ||||||||||||||||||||||||||||||||||||||||||
| 30 | WHERE type = 'table' AND sql IS NOT NULL ORDER BY name | ||||||||||||||||||||||||||||||||||||||||||
| 31 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 55 | my @virtual = grep { $class->_uses_module($_->[1]) } @$rows; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 55 | my @names = map { $_->[0] } @virtual; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | module => $module, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | available => $available, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | virtual_tables => \@names, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 55 | shadow_tables => [ map { my $n = $_; map { $n . $_ } $class->shadow_suffixes } @names ], | |||||||||||||||||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # CREATE VIRTUAL TABLE <name> USING <module>(...) | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 618 | ▶ | sub _uses_module { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_uses_module: called CC=6 SCAR=18.7
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 618 | my ($class, $sql) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 618 | my @tokens = sql_tokens($sql); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 618 | my $at = create_name_index(\@tokens, 'VIRTUAL', 'TABLE'); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 618 | ▶ | return 0 unless defined $at; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 110 | my @rest = grep { $_->[0] ne 'skip' } @tokens[ $at + 1 .. $#tokens ]; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 110 | ▶ | return 0 unless @rest >= 2 && $rest[0][0] eq 'word' && uc $rest[0][1] eq 'USING'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@rest >= 2 and $rest[0][0] eq "word" and uc $rest[0][1] eq "USING"
@rest >= 2 and $rest[0][0] eq "word"
MC/DC0%0/3
@rest >= 2 and $rest[0][0] eq "word" and uc $rest[0][1] eq "USING"
@rest >= 2
$rest[0][0] eq "word"
uc $rest[0][1] eq "USING"
Truth table25%1/4
A and B and C
A= @rest >= 2B= $rest[0][0] eq "word"C= uc $rest[0][1] eq "USING"
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 110 | ▶ | return lc token_identifier(@{ $rest[1] }) eq $class->module ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 104 | ▶ | sub claims { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
claims: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 104 | my ($class, $model, $ctx) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 104 | ▶ | my $state = ($ctx->{self} || {})->{state} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
+($ctx->{'self'} || {})->{'state'} || {}
$ctx->{'self'} || {}
MC/DC0%0/1
+($ctx->{'self'} || {})->{'state'} || {}
$ctx->{'self'}
Truth table50%1/2
A
A= $ctx->{'self'}
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 104 | ▶ | return [ map { $ctx->{driver}{table}->($_) } @{ $state->{shadow_tables} || [] } ]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$state->{'shadow_tables'} || []
MC/DC0%0/1
$state->{'shadow_tables'} || []
$state->{'shadow_tables'}
Truth table50%1/2
A
A= $state->{'shadow_tables'}
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||||||||||||||||