FusqlFS/Backend/SQLite/Tables.pm

filter: Statementstmt 100% 33 / 33 Branchbran n/a Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 6 / 6 totaltotal 96.3% 52 / 54 CC 2 SCAR 1.7
CC
2
Cov
97%
get
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« FusqlFS/Backend/SQLite/Table/Test.pm ↑ Summary FusqlFS/Cache.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package FusqlFS::Backend::SQLite::Tables;
5 2 ▶use FusqlFS::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 our $VERSION = $FusqlFS::Version::VERSION;
7 2 ▶use parent 'FusqlFS::Artifact';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 FusqlFS::Backend::SQLite::Tables - FusqlFS SQLite database tables interface
12  
13 =head1 SYNOPSIS
14  
15 use FusqlFS::Backend::SQLite::Tables;
16  
17 my $tables = FusqlFS::Backend::SQLite::Tables->new();
18 my $list = $tables->list();
19  
20 =head1 DESCRIPTION
21  
22 This is FusqlFS an interface to SQLite database tables. This class is not
23 to be used by itself.
24  
25 This class provides a view of a set of different table's artifacts like
26 indices, struct (fields description), data rows/records, constraints, triggers
27 etc.
28  
29 See L<FusqlFS::Artifact> for description of interface methods,
30 L<FusqlFS::Backend> to learn more on backend initialization and
31 L<FusqlFS::Backend::Base> for more info on database backends writing.
32  
33 =head1 EXPOSED STRUCTURE
34  
35 =over
36  
37 =item F<./indices>
38  
39 Table's indices, see L<FusqlFS::Backend::SQLite::Table::Indices> for details.
40  
41 =item F<./struct>
42  
43 Table's structure, see L<FusqlFS::Backend::SQLite::Table::Struct> for details.
44  
45 =item F<./constraints>
46  
47 Table's foreign keys, see L<FusqlFS::Backend::SQLite::Table::Constraints> for details.
48  
49 =item F<./triggers>
50  
51 Table's triggers, see L<FusqlFS::Backend::SQLite::Table::Triggers> for details.
52  
53 =item F<./data>
54  
55 Table's data, see L<FusqlFS::Backend::SQLite::Table::Data> for details.
56  
57 =back
58  
59 =cut
60  
61 sub init
62 3 ▶{
Subroutine init: called CC=1 SCAR=0.0
Pod documented
63 3 my $self = shift;
64 3 $self->{list_expr} = $self->expr('SELECT name FROM sqlite_master WHERE type = "table"');
65 3 $self->{get_expr} = $self->expr('SELECT 1 FROM sqlite_master WHERE type = "table" AND name = ?');
66  
67 3 $self->{rename_expr} = 'ALTER TABLE %s RENAME TO %s';
68 3 $self->{drop_expr} = 'DROP TABLE %s';
69 3 $self->{create_expr} = 'CREATE TABLE %s (id INT)';
70  
71 3 $self->autopackages('indices', 'data', 'struct'); # 'constraints', 'triggers'
72 }
73  
74 =begin testing list
75  
76 cmp_set $_tobj->list(), [], 'Tables list is sane';
77  
78 =end testing
79 =cut
80 sub list
81 4 ▶{
Subroutine list: called CC=1 SCAR=0.0
Pod documented
82 4 my $self = shift;
83 4 return $self->all_col($self->{list_expr});
84 }
85  
86 =begin testing get
87  
88 is $_tobj->get('fusqlfs_table'), undef, 'Test table doesn\'t exist';
89  
90 =end testing
91 =cut
92 sub get
93 5 ▶{
Subroutine get: called CC=2 SCAR=7.1
Pod documented
94 5 my $self = shift;
95 5 ▶ return $self->one_row($self->{get_expr}, $_[0]) && $self->{subpackages};
Condition66%2/3
$self->one_row($self->{'get_expr'}, $_[0]) && $self->{'subpackages'}
!ll&&!rl&&r
302
MC/DC50%1/2
$self->one_row($self->{'get_expr'}, $_[0]) && $self->{'subpackages'}
$self->one_row($self->{'get_expr'}, $_[0]) $self->{'subpackages'}
Truth table66%2/3
A && B
A= $self->one_row($self->{'get_expr'}, $_[0])B= $self->{'subpackages'}
ABresult
0X0
100
111
96 }
97  
98 =begin testing rename after create
99  
100 isnt $_tobj->rename('fusqlfs_table', 'new_fusqlfs_table'), undef, 'Table renamed';
101 is $_tobj->get('fusqlfs_table'), undef, 'Table is unaccessable under old name';
102 is_deeply $_tobj->get('new_fusqlfs_table'), $_tobj->{subpackages}, 'Table renamed correctly';
103 is_deeply $_tobj->list(), [ 'new_fusqlfs_table' ], 'Table is listed under new name';
104  
105 =end testing
106 =cut
107 sub rename
108 1 ▶{
Subroutine rename: called CC=1 SCAR=0.0
Pod documented
109 1 my $self = shift;
110 1 my ($table, $newtable) = @_;
111 1 $self->do($self->{rename_expr}, [$table, $newtable]);
112 }
113  
114 =begin testing drop after rename
115  
116 isnt $_tobj->drop('new_fusqlfs_table'), undef, 'Table dropped';
117 is $_tobj->get('new_fusqlfs_table'), undef, 'Table dropped correctly';
118 is_deeply $_tobj->list(), [], 'Tables list is empty';
119  
120 =end testing
121 =cut
122 sub drop
123 1 ▶{
Subroutine drop: called CC=1 SCAR=0.0
Pod documented
124 1 my $self = shift;
125 1 my ($table) = @_;
126 1 $self->do($self->{drop_expr}, [$table]);
127 }
128  
129 =begin testing create after get list
130  
131 isnt $_tobj->create('fusqlfs_table'), undef, 'Table created';
132 is_deeply $_tobj->get('fusqlfs_table'), $_tobj->{subpackages}, 'New table is sane';
133 is_deeply $_tobj->list(), [ 'fusqlfs_table' ], 'New table is listed';
134  
135 =end testing
136 =cut
137 sub create
138 2 ▶{
Subroutine create: called CC=1 SCAR=0.0
Pod documented
139 2 my $self = shift;
140 2 my ($table) = @_;
141 2 $self->do($self->{create_expr}, [$table]);
142 }
143  
144 2 1;
145  
146 __END__
« FusqlFS/Backend/SQLite/Table/Test.pm ↑ Summary FusqlFS/Cache.pm »