blib/lib/ORLite/Migrate/Patch.pm

filter: Statementstmt 72.7% 32 / 44 Branchbran 30.0% 3 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 52.6% 10 / 19 Podpod 0.0% 0 / 12 totaltotal 51.1% 46 / 90 CC 7 SCAR 10.3
CC
7
Cov
63%
pragma
6.0
column_exists
6.0
file
4.9
CRAP 2.8
« blib/lib/ORLite/Migrate.pm ↑ Summary blib/lib/ORLite/Migrate/Timeline.pm »
1 package ORLite::Migrate::Patch;
2  
3 # A convenience module for writing migration patches.
4 # Based on Padre::DB::Patch.
5  
6 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use DBI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use vars qw{$VERSION @ISA @EXPORT $FILE};
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 $VERSION = '1.10';
15 2 @ISA = 'Exporter';
16 2 @EXPORT = qw{
17 file
18 dbh
19 do
20 selectall_arrayref
21 selectall_hashref
22 selectcol_arrayref
23 selectrow_array
24 selectrow_arrayref
25 selectrow_hashref
26 pragma
27 table_exists
28 column_exists
29 };
30  
31 # The location of the SQLite database file
32 2 $FILE = undef;
33 }
34  
35 1 ▶sub file {
Subroutine file: called CC=4 SCAR=15.9
Pod undocumented
36 1 ▶ unless ( $FILE ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ORLite::Migrate::Patch::FILE) 1 0 1
37 # The filename is passed on STDIN
38 1 $FILE = <STDIN>;
39 1 chomp($FILE);
40 1 ▶ unless ( -f $FILE and -w $FILE ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $ORLite::Migrate::Patch::FILE and -w $ORLite::Migrate::Patch::FILE) 0 1 1
Condition33%1/3
-f $ORLite::Migrate::Patch::FILE and -w $ORLite::Migrate::Patch::FILE
!ll&&!rl&&r
001
MC/DC0%0/2
-f $ORLite::Migrate::Patch::FILE and -w $ORLite::Migrate::Patch::FILE
-f $ORLite::Migrate::Patch::FILE -w $ORLite::Migrate::Patch::FILE
Truth table33%1/3
A and B
A= -f $ORLite::Migrate::Patch::FILEB= -w $ORLite::Migrate::Patch::FILE
ABresult
0X0
100
111
41 0 die "SQLite file $FILE does not exist";
42 }
43 }
44 1 return $FILE;
45 }
46  
47 1 ▶sub dbh {
Subroutine dbh: called CC=2 SCAR=7.4
Pod undocumented
48 1 my $file = file();
49 1 my $dbh = DBI->connect(
50 "dbi:SQLite:$file",
51 undef, undef,
52 { RaiseError => 1,
53 }
54 );
55 1 ▶ unless ($dbh) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh) 0 1 1
56 0 die "Failed to connect to $file";
57 }
58 1 return $dbh;
59 }
60  
61 1 ▶sub do {
Subroutine do: called CC=1 SCAR=0.0
Pod undocumented
62 1 dbh()->do(@_);
63 }
64  
65 0 ▶sub selectall_arrayref {
Subroutine selectall_arrayref: not called CC=1 SCAR=6.9
Pod undocumented
66 0 dbh()->selectall_arrayref(@_);
67 }
68  
69 0 ▶sub selectall_hashref {
Subroutine selectall_hashref: not called CC=1 SCAR=6.9
Pod undocumented
70 0 dbh()->selectall_hashref(@_);
71 }
72  
73 0 ▶sub selectcol_arrayref {
Subroutine selectcol_arrayref: not called CC=1 SCAR=6.9
Pod undocumented
74 0 dbh()->selectcol_arrayref(@_);
75 }
76  
77 0 ▶sub selectrow_array {
Subroutine selectrow_array: not called CC=1 SCAR=6.9
Pod undocumented
78 0 dbh()->selectrow_array(@_);
79 }
80  
81 0 ▶sub selectrow_arrayref {
Subroutine selectrow_arrayref: not called CC=1 SCAR=6.9
Pod undocumented
82 0 dbh()->selectrow_arrayref(@_);
83 }
84  
85 0 ▶sub selectrow_hashref {
Subroutine selectrow_hashref: not called CC=1 SCAR=6.9
Pod undocumented
86 0 dbh()->selectrow_hashref(@_);
87 }
88  
89 0 ▶sub pragma {
Subroutine pragma: not called CC=2 SCAR=17.9
Pod undocumented
90 0 ▶ do("pragma $_[0] = $_[1]") if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 0 0
91 0 selectrow_arrayref("pragma $_[0]")->[0];
92 }
93  
94 0 ▶sub table_exists {
Subroutine table_exists: not called CC=1 SCAR=6.9
Pod undocumented
95 0 selectrow_array(
96 "select count(*) from sqlite_master where type = 'table' and name = ?",
97 {}, $_[0],
98 );
99 }
100  
101 0 ▶sub column_exists {
Subroutine column_exists: not called CC=2 SCAR=17.9
Pod undocumented
102 0 ▶ table_exists( $_[0] )
Branch: 1 branch
BranchTrueFalseTotal
table_exists($_[0]) or selectrow_array("select count($_[1]) from $_[0]", scalar {}) 0 0 0
103 or selectrow_array( "select count($_[1]) from $_[0]", {} );
104 }
105  
106 2 1;
« blib/lib/ORLite/Migrate.pm ↑ Summary blib/lib/ORLite/Migrate/Timeline.pm »