Test/Role/SQLite.pm

filter: Statementstmt 95.8% 23 / 24 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 3 / 3 totaltotal 90.2% 37 / 41 CC 3 SCAR 3.7
CC
3
Cov
89%
BUILD
2.1
clear_database
2.1
_build_database
2.0
CRAP 1.5
« Schema/Result/AttributeValue.pm ↑ Summary Schema/Component/Validation.pm »
1 package Interchange6::Test::Role::SQLite;
2  
3 =head1 NAME
4  
5 Interchange6::Test::Role::SQLite
6  
7 =cut
8  
9 2 ▶use Class::Load qw/try_load_class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Test::Roo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 with 'Interchange6::Test::Role::Database';
13  
14 =head1 METHODS
15  
16 See also L<Interchange6::Test::Role::Database> which is consumed by this role.
17  
18 =head2 BUILD
19  
20 Check that all required modules load or else plan skip_all
21  
22 =cut
23  
24 sub BUILD {
25 1 ▶ try_load_class('DBD::SQLite')
Subroutine BUILD: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
try_load_class("DBD::SQLite") or plan("skip_all", "DBD::SQLite required to run these tests") 0 1 1
26 or plan skip_all => "DBD::SQLite required to run these tests";
27 }
28  
29 2 my $fh = File::Temp->new(
30 TEMPLATE => 'ic6s_test_XXXXX',
31 EXLOCK => 0,
32 TMPDIR => 1,
33 );
34 2 my $dbfile = $fh->filename;
35  
36 after teardown => sub {
37 1 ▶ shift->clear_database;
Subroutine __ANON__: called CC=1 SCAR=0.0
38 2 };
39  
40 =head2 clear_database
41  
42 Attempt to unlink temporary database file
43  
44 =cut
45  
46 sub clear_database {
47 1 ▶ close($fh);
Subroutine clear_database: called CC=2 SCAR=7.2
Pod documented
48 1 ▶ unlink($dbfile) or diag "Could not unlink $dbfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
unlink $dbfile or diag("Could not unlink ${dbfile}: $!") 0 1 1
49 }
50  
51 sub _build_database {
52  
53 # does nothing atm for SQLite
54 0 ▶ return;
Subroutine _build_database: not called CC=1 SCAR=6.9
55 }
56  
57 sub _build_dbd_version {
58 1 ▶ return "DBD::SQLite $DBD::SQLite::VERSION";
Subroutine _build_dbd_version: called CC=1 SCAR=0.0
59 }
60  
61 =head2 connect_info
62  
63 Returns appropriate DBI connect info for this role.
64  
65 =cut
66  
67 sub connect_info {
68 1 ▶ my $self = shift;
Subroutine connect_info: called CC=1 SCAR=0.0
Pod documented
69  
70 1 return ( "dbi:SQLite:dbname=$dbfile", undef, undef,
71 {
72 sqlite_unicode => 1,
73 on_connect_call => 'use_foreign_keys',
74 on_connect_do => 'PRAGMA synchronous = OFF',
75 quote_names => 1,
76 }
77 );
78 }
79  
80 sub _build_database_info {
81 1 ▶ my $self = shift;
Subroutine _build_database_info: called CC=1 SCAR=0.0
82 return "SQLite library version: "
83 1 . $self->ic6s_schema->storage->dbh->{sqlite_version};
84 }
85  
86 2 1;
« Schema/Result/AttributeValue.pm ↑ Summary Schema/Component/Validation.pm »