blib/lib/DBIO/SQLite/Extension/VirtualTable.pm

filter: Statementstmt 95.7% 45 / 47 Branchbran 70.0% 7 / 10 Conditioncond 27.7% 5 / 18 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 80.0% 8 / 10 Podpod 100% 5 / 5 totaltotal 70.7% 70 / 99 CC 13 SCAR 14.5
CC
13
Cov
76%
_uses_module
6.5
module
6.0
shadow_suffixes
6.0
CRAP 4.3
« blib/lib/DBIO/SQLite/Adapter.pm ↑ Summary blib/lib/DBIO/SQLite/Diff/Rebuild.pm »
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]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
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]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$modules ? : 55 0 55
grep({lc $_ eq $module;} @$modules) ? : 55 0 55
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
BranchTrueFalseTotal
unless defined $at 508 110 618
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
BranchTrueFalseTotal
unless @rest >= 2 and $rest[0][0] eq "word" and uc $rest[0][1] eq "USING" 0 110 110
Condition33%2/6
@rest >= 2 and $rest[0][0] eq "word" and uc $rest[0][1] eq "USING"
!ll&&!rl&&r
00110
@rest >= 2 and $rest[0][0] eq "word"
!ll&&!rl&&r
00110
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"
ABCresult
0XX0
10X0
1100
1111
53 110 ▶ return lc token_identifier(@{ $rest[1] }) eq $class->module ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
lc token_identifier(@{$rest[1];}) eq $class->module ? : 55 55 110
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'} || {}
l!l
1040
$ctx->{'self'} || {}
l!l
1040
MC/DC0%0/1
+($ctx->{'self'} || {})->{'state'} || {}
$ctx->{'self'}
Truth table50%1/2
A
A= $ctx->{'self'}
Aresult
11
00
60 104 ▶ return [ map { $ctx->{driver}{table}->($_) } @{ $state->{shadow_tables} || [] } ];
Condition50%1/2
$state->{'shadow_tables'} || []
l!l
1040
MC/DC0%0/1
$state->{'shadow_tables'} || []
$state->{'shadow_tables'}
Truth table50%1/2
A
A= $state->{'shadow_tables'}
Aresult
11
00
61 }
62  
63 5 1;
64  
65 __END__
« blib/lib/DBIO/SQLite/Adapter.pm ↑ Summary blib/lib/DBIO/SQLite/Diff/Rebuild.pm »