blib/lib/App/DBCritic/Policy/DuplicateRelationships.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 100% 53 / 53 CC 2 SCAR 1.7
CC
2
Cov
100%
violates
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« blib/lib/App/DBCritic/Policy/NullableTextColumn.pm ↑ Summary bin/dbcritic »
1 package App::DBCritic::Policy::DuplicateRelationships;
2  
3 # ABSTRACT: Check for ResultSources with unnecessary duplicate relationships
4  
5 #pod =head1 SYNOPSIS
6 #pod
7 #pod use App::DBCritic;
8 #pod
9 #pod my $critic = App::DBCritic->new(
10 #pod dsn => 'dbi:Oracle:HR', username => 'scott', password => 'tiger');
11 #pod $critic->critique();
12 #pod
13 #pod =head1 DESCRIPTION
14 #pod
15 #pod This policy returns a violation if a
16 #pod L<DBIx::Class::ResultSource|DBIx::Class::ResultSource> has relationships to
17 #pod other tables that are identical in everything but name.
18 #pod
19 #pod =cut
20  
21 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 6 ▶use Modern::Perl '2011'; ## no critic (Modules::ProhibitUseQuotedVersion)
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 2 our $VERSION = '0.023'; # VERSION
26 6 ▶use Algorithm::Combinatorics 'combinations';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ▶use Data::Compare;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 6 ▶use English '-no_match_vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 6 ▶use Sub::Quote;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 6 ▶use namespace::autoclean -also => qr{\A _}xms;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 2 has description => (
34 is => 'ro',
35 default => quote_sub q{'Duplicate relationships'},
36 );
37  
38 #pod =attr description
39 #pod
40 #pod "Duplicate relationships"
41 #pod
42 #pod =cut
43  
44 2 has explanation => (
45 is => 'ro',
46 default => quote_sub
47 q{'Each connection between tables should only be expressed once.'},
48 );
49  
50 #pod =attr explanation
51 #pod
52 #pod "Each connection between tables should only be expressed once."
53 #pod
54 #pod =cut
55  
56 7 ▶sub violates {
Subroutine violates: called CC=2 SCAR=6.9
Pod documented
57 7 my $source = shift->element;
58 7 ▶ return if $source->relationships < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $source->relationships < 2 4 3 7
59  
60 1 return join "\n" => map { sprintf '%s and %s are duplicates', @{$_} }
61 grep {
62 3 Compare( map { $source->relationship_info($_) } @{$_} )
63 } combinations( [ $source->relationships ], 2 );
64 }
65  
66 #pod =method violates
67 #pod
68 #pod Returns details if the
69 #pod L<"current element"|App::DBCritic::Policy>'s C<relationship_info>
70 #pod hashes for any defined relationships are duplicated.
71 #pod
72 #pod =cut
73  
74 2 with 'App::DBCritic::PolicyType::ResultSource';
75  
76 #pod =attr applies_to
77 #pod
78 #pod This policy applies to L<ResultSource|DBIx::Class::ResultSource>s.
79 #pod
80 #pod =cut
81  
82 2 1;
83  
84 __END__
« blib/lib/App/DBCritic/Policy/NullableTextColumn.pm ↑ Summary bin/dbcritic »