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   4168 use strict;
  5         9  
  5         184  
4 5     5   20 use utf8;
  5         7  
  5         26  
5 5     5   110 use Modern::Perl '2011'; ## no critic (Modules::ProhibitUseQuotedVersion)
  5         7  
  5         32  
6              
7             our $VERSION = '0.021'; # TRIAL VERSION
8 5     5   3850 use Algorithm::Combinatorics 'combinations';
  5         16144  
  5         384  
9 5     5   3200 use Data::Compare;
  5         47559  
  5         35  
10 5     5   16864 use English '-no_match_vars';
  5         11  
  5         44  
11 5     5   1749 use Moo;
  5         9  
  5         38  
12 5     5   1825 use Sub::Quote;
  5         8  
  5         437  
13 5     5   25 use namespace::autoclean -also => qr{\A _}xms;
  5         7  
  5         54  
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', @{$ARG} }
30             grep {
31             Compare( map { $source->relationship_info($ARG) } @{$ARG} )
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__