blib/lib/DBICx/Indexing.pm

filter: Statementstmt 90.9% 40 / 44 Branchbran 57.1% 8 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 84.8% 56 / 66 CC 12 SCAR 15.0
CC
12
Cov
83%
_has_cover_index
5.9
indices
5.0
sqlt_deploy_hook
4.6
CRAP 4.5
↑ Summary
1 package DBICx::Indexing;
2 5 our $VERSION = '0.002';
3  
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use base qw/DBIx::Class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 __PACKAGE__->mk_classdata('_dbicx_indexing');
9  
10 6 ▶sub indices {
Subroutine indices: called CC=5 SCAR=16.1
Pod documented
11 6 my $class = shift;
12  
13 6 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 2 6
14 4 my $idxs;
15 4 ▶ if (scalar(@_) == 1) { $idxs = $_[0] }
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 2 2 4
16 2 else { $idxs = {@_} }
17  
18 4 for my $cols (values %$idxs) {
19 16 ▶ $cols = [$cols] unless ref $cols eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cols eq "ARRAY" 4 12 16
20 }
21  
22 4 $class->_dbicx_indexing($idxs);
23 }
24  
25 6 return $class->_dbicx_indexing;
26 }
27  
28 2 ▶sub sqlt_deploy_hook {
Subroutine sqlt_deploy_hook: called CC=4 SCAR=15.2
Pod documented
29 2 my $self = shift;
30 2 my ($table) = @_;
31  
32 2 ▶ $self->next::method(@_) if $self->next::can;
Branch: 1 branch
BranchTrueFalseTotal
if $self->next::can 0 2 2
33  
34 2 my $indexes = $self->_dbicx_indexing;
35 2 for my $name (keys %$indexes) {
36 2 my $cols = $indexes->{$name};
37  
38 2 ▶ next if _has_cover_index($table, $cols);
Branch: 1 branch
BranchTrueFalseTotal
if _has_cover_index($table, $cols) 0 0 0
39  
40 0 $table->add_index(name => $name, fields => $cols);
41 }
42 }
43  
44 3 ▶sub _has_cover_index {
Subroutine _has_cover_index: called CC=5 SCAR=17.8
45 3 my ($table, $cols) = @_;
46  
47 3 my @idxs;
48 3 push @idxs, map { [$_->fields] } $table->get_indices;
49 3 push @idxs, map { [$_->field_names] } $table->unique_constraints;
50 3 push @idxs, [$table->primary_key->field_names];
51  
52 3 IDXS: for my $flst (@idxs) {
53 3 for my $c (@$cols) {
54 3 ▶ next IDXS unless @$flst;
Branch: 1 branch
BranchTrueFalseTotal
unless @$flst 0 3 3
55 3 ▶ next IDXS unless $flst->[0] eq $c;
Branch: 1 branch
BranchTrueFalseTotal
unless $flst->[0] eq $c 0 0 0
56  
57 0 shift @$flst;
58 }
59  
60 0 return 1;
61 }
62  
63 0 return 0;
64 }
65  
66 5 1;
67  
68 __END__
↑ Summary