App-DBCritic
view release on metacpan or search on metacpan
lib/App/DBCritic/Policy/DuplicateRelationships.pm view on Meta::CPAN
package App::DBCritic::Policy::DuplicateRelationships;
# ABSTRACT: Check for ResultSources with unnecessary duplicate relationships
#pod =head1 SYNOPSIS
#pod
#pod use App::DBCritic;
#pod
#pod my $critic = App::DBCritic->new(
#pod dsn => 'dbi:Oracle:HR', username => 'scott', password => 'tiger');
#pod $critic->critique();
#pod
#pod =head1 DESCRIPTION
#pod
#pod This policy returns a violation if a
#pod L<DBIx::Class::ResultSource|DBIx::Class::ResultSource> has relationships to
#pod other tables that are identical in everything but name.
#pod
#pod =cut
use strict;
use utf8;
use Modern::Perl '2011'; ## no critic (Modules::ProhibitUseQuotedVersion)
our $VERSION = '0.023'; # VERSION
use Algorithm::Combinatorics 'combinations';
use Data::Compare;
use English '-no_match_vars';
use Moo;
use Sub::Quote;
use namespace::autoclean -also => qr{\A _}xms;
has description => (
is => 'ro',
default => quote_sub q{'Duplicate relationships'},
);
#pod =attr description
#pod
#pod "Duplicate relationships"
#pod
#pod =cut
has explanation => (
is => 'ro',
default => quote_sub
q{'Each connection between tables should only be expressed once.'},
);
#pod =attr explanation
#pod
#pod "Each connection between tables should only be expressed once."
#pod
#pod =cut
sub violates {
my $source = shift->element;
return if $source->relationships < 2;
return join "\n" => map { sprintf '%s and %s are duplicates', @{$_} }
grep {
Compare( map { $source->relationship_info($_) } @{$_} )
} combinations( [ $source->relationships ], 2 );
}
#pod =method violates
#pod
#pod Returns details if the
#pod L<"current element"|App::DBCritic::Policy>'s C<relationship_info>
#pod hashes for any defined relationships are duplicated.
#pod
#pod =cut
with 'App::DBCritic::PolicyType::ResultSource';
#pod =attr applies_to
#pod
#pod This policy applies to L<ResultSource|DBIx::Class::ResultSource>s.
#pod
#pod =cut
1;
__END__
=pod
=encoding UTF-8
=for :stopwords Mark Gardner cpan testmatrix url annocpan anno bugtracker rt cpants
kwalitee diff irc mailto metadata placeholders metacpan
=head1 NAME
App::DBCritic::Policy::DuplicateRelationships - Check for ResultSources with unnecessary duplicate relationships
=head1 VERSION
version 0.023
=head1 SYNOPSIS
use App::DBCritic;
my $critic = App::DBCritic->new(
dsn => 'dbi:Oracle:HR', username => 'scott', password => 'tiger');
$critic->critique();
=head1 DESCRIPTION
This policy returns a violation if a
L<DBIx::Class::ResultSource|DBIx::Class::ResultSource> has relationships to
other tables that are identical in everything but name.
=head1 ATTRIBUTES
=head2 description
"Duplicate relationships"
=head2 explanation
"Each connection between tables should only be expressed once."
=head2 applies_to
This policy applies to L<ResultSource|DBIx::Class::ResultSource>s.
=head1 METHODS
=head2 violates
Returns details if the
L<"current element"|App::DBCritic::Policy>'s C<relationship_info>
hashes for any defined relationships are duplicated.
=head1 SUPPORT
=head2 Perldoc
You can find documentation for this module with the perldoc command.
perldoc App::DBCritic::Policy::DuplicateRelationships
=head2 Websites
The following websites have more information about this module, and may be of help to you. As always,
in addition to those websites please use your favorite search engine to discover more resources.
=over 4
=item *
Search CPAN
The default CPAN search engine, useful to view POD in HTML format.
L<http://search.cpan.org/dist/App-DBCritic>
=item *
CPAN Ratings
The CPAN Ratings is a website that allows community ratings and reviews of Perl modules.
L<http://cpanratings.perl.org/d/App-DBCritic>
( run in 0.440 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )