blib/lib/DBIO/SQLite/Introspect/ForeignKeys.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 100% 39 / 39 CC 3 SCAR 6.2
CC
3
Cov
100%
fetch
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« blib/lib/DBIO/SQLite/Introspect.pm ↑ Summary blib/lib/DBIO/SQLite/JSON/Op.pm »
1 package DBIO::SQLite::Introspect::ForeignKeys;
2 # ABSTRACT: Introspect SQLite foreign keys
3  
4 193 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 193 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 193 our $VERSION = '0.900007';
8  
9 193 ▶use DBIO::Introspect::Base ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 193 ▶use DBIO::SQLite::Util qw(quote_identifier selectall_hashrefs);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13  
14 755 ▶sub fetch {
Subroutine fetch: called CC=3 SCAR=11.0
Pod documented
15 755 my ($class, $dbh, $tables) = @_;
16 755 my %fks;
17  
18 755 for my $table_name (sort keys %$tables) {
19 1459 my $list = selectall_hashrefs($dbh,
20 sprintf('PRAGMA foreign_key_list(%s)', quote_identifier($table_name)));
21 1459 ▶ next unless @$list;
Branch: 1 branch
BranchTrueFalseTotal
unless @$list 1199 260 1459
22  
23 260 my $groups = DBIO::Introspect::Base->_aggregate_by_ordered($list, 'id');
24 $fks{$table_name} = [ map {
25 260 my ($id, $rows) = @$_;
26 293 my $first = $rows->[0];
27 293 my @from = map { $_->{from} } sort { $a->{seq} <=> $b->{seq} } @$rows;
28 293 my @to = map { $_->{to} } sort { $a->{seq} <=> $b->{seq} } @$rows;
29 +{
30 fk_id => $id,
31 from_columns => \@from,
32 to_table => $first->{table},
33 to_columns => \@to,
34 on_update => $first->{on_update},
35 on_delete => $first->{on_delete},
36 match => $first->{match},
37 293 };
38 } @$groups ];
39 }
40  
41 755 return \%fks;
42 }
43  
44 193 1;
45  
46 __END__
« blib/lib/DBIO/SQLite/Introspect.pm ↑ Summary blib/lib/DBIO/SQLite/JSON/Op.pm »