Backend/SQLite.pm

filter: Statementstmt 98.2% 56 / 57 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 17 / 17 Podpod n/a totaltotal 96.2% 77 / 80 CC 5 SCAR 5.3
CC
5
Cov
95%
__ANON__
4.2
_munge_guid
2.0
BEGIN
1.0
CRAP 1.7
« Backend/PostgreSQL.pm ↑ Summary Backend/SQL.pm »
1 6 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Metabase::Backend::SQLite;
6 # ABSTRACT: Metabase backend implemented using SQLite
7  
8 6 our $VERSION = '1.001';
9  
10 6 ▶use MooseX::Types::Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use DBD::SQLite;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 6 with 'Metabase::Backend::SQL';
16  
17 6 has 'filename' => (
18 is => 'ro',
19 isa => 'Path::Class::File',
20 coerce => 1,
21 required => 1,
22 );
23  
24 6 has 'synchronous' => (
25 is => 'ro',
26 isa => 'Bool',
27 default => 0,
28 );
29  
30 6 has 'page_size' => (
31 is => 'ro',
32 isa => 'Int',
33 predicate => 'has_page_size',
34 );
35  
36 6 has 'cache_size' => (
37 is => 'ro',
38 isa => 'Int',
39 predicate => 'has_cache_size',
40 );
41  
42 79 ▶sub _build_dsn {
Subroutine _build_dsn: called CC=1 SCAR=0.0
43 79 my $self = shift;
44 79 return "dbi:SQLite:dbname=" . $self->filename;
45 }
46  
47 79 ▶sub _build_db_user { return "" }
Subroutine _build_db_user: called CC=1 SCAR=0.0
48  
49 79 ▶sub _build_db_pass { return "" }
Subroutine _build_db_pass: called CC=1 SCAR=0.0
50  
51 79 ▶sub _build_db_type { return "SQLite" }
Subroutine _build_db_type: called CC=1 SCAR=0.0
52  
53 239 ▶around _build_dbis => sub {
Subroutine __ANON__: called CC=4 SCAR=14.2
54 239 my $orig = shift;
55 239 my $self = shift;
56 239 my $dbis = $self->$orig;
57 239 ▶ my $toggle = $self->synchronous ? "ON" : "OFF";
Branch: 1 branch
BranchTrueFalseTotal
$self->synchronous ? : 0 239 239
58 239 $dbis->query("PRAGMA synchronous = $toggle");
59 239 for my $pragma ( qw/page_size cache_size/ ) {
60 478 my $pred = "has_$pragma";
61 478 ▶ if ( $self->$pred ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->$pred) 0 478 478
62 0 $dbis->query("PRAGMA $pragma = " . $self->$pragma);
63 }
64 }
65 239 return $dbis;
66 6 };
67  
68 80 ▶sub _fixup_sql_diff {
Subroutine _fixup_sql_diff: called CC=1 SCAR=0.0
69 80 my ($self, $diff) = @_;
70 # Fix up BEGIN/COMMIT
71 80 $diff =~ s/BEGIN;/BEGIN TRANSACTION;/mg;
72 80 $diff =~ s/COMMIT;/COMMIT TRANSACTION;/mg;
73 # Strip comments
74 80 $diff =~ s/^--[^\n]*$//msg;
75 # strip empty lines
76 80 $diff =~ s/^\n//msg;
77 80 return $diff;
78 }
79  
80 79 ▶sub _build__guid_field_params {
Subroutine _build__guid_field_params: called CC=1 SCAR=0.0
81 return {
82 79 data_type => 'char',
83 size => 36,
84 }
85 }
86  
87 9 ▶sub _build__blob_field_params {
Subroutine _build__blob_field_params: called CC=1 SCAR=0.0
88 return {
89 9 data_type => 'blob'
90 };
91 }
92  
93 6 my $hex = qr/[0-9a-f]/i;
94 208 ▶sub _munge_guid {
Subroutine _munge_guid: called CC=2 SCAR=6.9
95 208 my ($self, $guid) = @_;
96 208 ▶ $guid = "00000000-0000-0000-0000-000000000000"
Branch: 1 branch
BranchTrueFalseTotal
unless $guid =~ /${hex}{8}-${hex}{4}-${hex}{4}-${hex}{4}-${hex}{12}/ 68 140 208
97 unless $guid =~ /${hex}{8}-${hex}{4}-${hex}{4}-${hex}{4}-${hex}{12}/;
98 208 return $guid;
99 }
100  
101 20 ▶sub _unmunge_guid {
Subroutine _unmunge_guid: called CC=1 SCAR=0.0
102 20 my ($self, $guid) = @_;
103 20 return $guid;
104 }
105  
106 6 1;
107  
108  
109 # vim: ts=2 sts=2 sw=2 et:
110  
111 __END__
« Backend/PostgreSQL.pm ↑ Summary Backend/SQL.pm »