| 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<DBIx::Class::ResultSource|DBIx::Class::ResultSource> has zero primary columns. | ||||||||||
| 17 | #pod | ||||||||||
| 18 | #pod =cut | ||||||||||
| 19 | |||||||||||
| 20 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 6 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 6 | ▶ | use Modern::Perl '2011'; ## no critic (Modules::ProhibitUseQuotedVersion) | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 2 | our $VERSION = '0.023'; # VERSION | |||||||||
| 25 | 6 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 6 | ▶ | use Sub::Quote; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 6 | ▶ | use namespace::autoclean -also => qr{\A _}xms; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | |||||||||||
| 29 | 2 | 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 | 2 | 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 | 7 | ▶ | sub violates { | ||||||||
|
Subroutine
violates: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 50 | 7 | my $source = shift->element; | |||||||||
| 51 | 7 | ▶ | return $source->name . ' has no primary key' if !$source->primary_columns; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 6 | 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<primary_columns> | ||||||||||
| 59 | #pod method returns nothing. | ||||||||||
| 60 | #pod | ||||||||||
| 61 | #pod =cut | ||||||||||
| 62 | |||||||||||
| 63 | 2 | with 'App::DBCritic::PolicyType::ResultSource'; | |||||||||
| 64 | |||||||||||
| 65 | #pod =attr applies_to | ||||||||||
| 66 | #pod | ||||||||||
| 67 | #pod This policy applies to L<ResultSource|DBIx::Class::ResultSource>s. | ||||||||||
| 68 | #pod | ||||||||||
| 69 | #pod =cut | ||||||||||
| 70 | |||||||||||
| 71 | 2 | 1; | |||||||||
| 72 | |||||||||||
| 73 | __END__ | ||||||||||