File Coverage

blib/lib/App/DBCritic/Policy/NoPrimaryKey.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1             package App::DBCritic::Policy::NoPrimaryKey;
2              
3             # ABSTRACT: Check for DBIx::Class::Schema::ResultSources without primary keys
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 has zero primary columns.
17             #pod
18             #pod =cut
19              
20 5     5   3918 use strict;
  5         13  
  5         211  
21 5     5   29 use utf8;
  5         11  
  5         32  
22 5     5   137 use Modern::Perl '2011'; ## no critic (Modules::ProhibitUseQuotedVersion)
  5         12  
  5         32  
23              
24             our $VERSION = '0.023'; # VERSION
25 5     5   763 use Moo;
  5         11  
  5         29  
26 5     5   1717 use Sub::Quote;
  5         14  
  5         527  
27 5     5   40 use namespace::autoclean -also => qr{\A _}xms;
  5         11  
  5         49  
28              
29             has description => ( is => 'ro', default => quote_sub q{'No primary key'} );
30              
31             #pod =attr description
32             #pod
33             #pod "No primary key"
34             #pod
35             #pod =cut
36              
37             has explanation => (
38             is => 'ro',
39             default => quote_sub
40             q{'Tables should have one or more columns defined as a primary key.'},
41             );
42              
43             #pod =attr explanation
44             #pod
45             #pod "Tables should have one or more columns defined as a primary key."
46             #pod
47             #pod =cut
48              
49             sub violates {
50             my $source = shift->element;
51             return $source->name . ' has no primary key' if !$source->primary_columns;
52             return;
53             }
54              
55             #pod =method violates
56             #pod
57             #pod Returns details if the
58             #pod L<"current element"|App::DBCritic::Policy>'s C
59             #pod method returns nothing.
60             #pod
61             #pod =cut
62              
63             with 'App::DBCritic::PolicyType::ResultSource';
64              
65             #pod =attr applies_to
66             #pod
67             #pod This policy applies to Ls.
68             #pod
69             #pod =cut
70              
71             1;
72              
73             __END__