File Coverage

blib/lib/App/DBCritic/Policy/DuplicateRelationships.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod n/a
total 36 36 100.0


line stmt bran cond sub pod time code
1             package App::DBCritic::Policy::DuplicateRelationships;
2              
3 5     5   8289 use strict;
  5         14  
  5         191  
4 5     5   40 use utf8;
  5         14  
  5         48  
5 5     5   147 use Modern::Perl '2011'; ## no critic (Modules::ProhibitUseQuotedVersion)
  5         12  
  5         54  
6              
7             our $VERSION = '0.022'; # VERSION
8 5     5   4470 use Algorithm::Combinatorics 'combinations';
  5         18766  
  5         382  
9 5     5   3181 use Data::Compare;
  5         57421  
  5         47  
10 5     5   20680 use English '-no_match_vars';
  5         14  
  5         54  
11 5     5   1959 use Moo;
  5         12  
  5         64  
12 5     5   2506 use Sub::Quote;
  5         13  
  5         506  
13 5     5   2843 use namespace::autoclean -also => qr{\A _}xms;
  5         8422  
  5         56  
14              
15             has description => (
16             is => 'ro',
17             default => quote_sub q{'Duplicate relationships'},
18             );
19             has explanation => (
20             is => 'ro',
21             default => quote_sub
22             q{'Each connection between tables should only be expressed once.'},
23             );
24              
25             sub violates {
26             my $source = shift->element;
27             return if $source->relationships < 2;
28              
29             return join "\n" => map { sprintf '%s and %s are duplicates', @{$_} }
30             grep {
31             Compare( map { $source->relationship_info($_) } @{$_} )
32             } combinations( [ $source->relationships ], 2 );
33             }
34              
35             with 'App::DBCritic::PolicyType::ResultSource';
36             1;
37              
38             # ABSTRACT: Check for ResultSources with unnecessary duplicate relationships
39              
40             __END__