File Coverage

blib/lib/Test/Fixture/DBI/Util/SQLite.pm
Criterion Covered Total %
statement 6 22 27.2
branch 0 4 0.0
condition n/a
subroutine 2 3 66.6
pod 1 1 100.0
total 9 30 30.0


line stmt bran cond sub pod time code
1             package Test::Fixture::DBI::Util::SQLite;
2              
3 1     1   5 use strict;
  1         2  
  1         30  
4 1     1   5 use warnings;
  1         2  
  1         309  
5              
6             our $VERSION = '0.01';
7              
8             sub make_database {
9 0     0 1   my ( $class, $dbh ) = @_;
10              
11 0           my $rows = $dbh->selectall_arrayref(
12             q|SELECT name, type, tbl_name, sql FROM sqlite_master WHERE sql IS NOT NULL ORDER BY type|,
13             +{ Slice => +{} },
14             );
15              
16 0           my @database;
17              
18             ### retrieve table and view
19 0           push( @database,
20 0 0         map { +{ schema => $_->{name}, data => $_->{sql}, } }
21 0 0         sort { $a->{type} cmp $b->{type} || $a->{name} cmp $b->{name} }
22 0           grep { $_->{type} eq 'table' || $_->{type} eq 'view' } @$rows );
23              
24             ### retrive trigger
25 0           push(
26             @database,
27 0           sort { $a->{trigger} cmp $b->{trigger} }
28             map {
29 0           +{
30             trigger => $_->{name},
31             refer => $_->{tbl_name},
32             data => $_->{sql},
33             }
34             }
35 0           grep { $_->{type} eq 'trigger' } @$rows
36             );
37              
38             ### retrive index
39 0           push(
40             @database,
41 0           sort { $a->{index} cmp $b->{index} }
42             map {
43 0           +{
44             index => $_->{name},
45             refer => $_->{tbl_name},
46             data => $_->{sql},
47             }
48             }
49 0           grep { $_->{type} eq 'index' } @$rows
50             );
51              
52 0           return \@database;
53             }
54              
55             1;
56              
57             __END__