| 1 | package App::DBCritic::Violation; | ||
| 2 | |||
| 3 | # ABSTRACT: A violation of a App::DBCritic::Policy | ||
| 4 | |||
| 5 | #pod =head1 SYNOPSIS | ||
| 6 | #pod | ||
| 7 | #pod use App::DBCritic::Violation; | ||
| 8 | #pod | ||
| 9 | #pod my $violation = App::DBCritic::Violation->new( | ||
| 10 | #pod description => 'Violated policy', | ||
| 11 | #pod explanation => 'Consult the rulebook', | ||
| 12 | #pod description => 'The frob table is improperly swizzled.', | ||
| 13 | #pod ); | ||
| 14 | #pod print "$violation\n"; | ||
| 15 | #pod | ||
| 16 | #pod =head1 DESCRIPTION | ||
| 17 | #pod | ||
| 18 | #pod This class represents L<App::DBCritic::Policy|App::DBCritic::Policy> | ||
| 19 | #pod violations flagged by L<App::DBCritic|App::DBCritic>. | ||
| 20 | #pod | ||
| 21 | #pod =cut | ||
| 22 | |||
| 23 | 15 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 24 | 15 | ▶ | use utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | 15 | ▶ | use Modern::Perl '2011'; ## no critic (Modules::ProhibitUseQuotedVersion) |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | |||
| 27 | 15 | our $VERSION = '0.023'; # VERSION | |
| 28 | 15 | ▶ | use Const::Fast; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 29 | 15 | ▶ | use English '-no_match_vars'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 30 | 15 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 31 | 15 | ▶ | use Sub::Quote; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 32 | 15 | ▶ | use overload q{""} => sub { shift->as_string }; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 33 | |||
| 34 | 15 | const my @TEXT_FIELDS => qw(description explanation details); | |
| 35 | 15 | for (@TEXT_FIELDS) { | |
| 36 | 45 | has $_ => ( is => 'ro', default => quote_sub q{q{}} ); | |
| 37 | } | ||
| 38 | |||
| 39 | #pod =attr description | ||
| 40 | #pod | ||
| 41 | #pod A short string briefly describing what's wrong. | ||
| 42 | #pod Only settable at construction. | ||
| 43 | #pod | ||
| 44 | #pod =attr explanation | ||
| 45 | #pod | ||
| 46 | #pod A string giving a longer general description of the problem. | ||
| 47 | #pod Only settable at construction. | ||
| 48 | #pod | ||
| 49 | #pod =attr details | ||
| 50 | #pod | ||
| 51 | #pod A string describing the issue as it specifically applies to the L</element> | ||
| 52 | #pod being critiqued. | ||
| 53 | #pod | ||
| 54 | #pod =cut | ||
| 55 | |||
| 56 | 15 | has element => ( is => 'ro' ); | |
| 57 | |||
| 58 | #pod =attr element | ||
| 59 | #pod | ||
| 60 | #pod The schema element that violated a | ||
| 61 | #pod L<App::DBCritic::Policy|App::DBCritic::Policy>. | ||
| 62 | #pod Only settable at construction. | ||
| 63 | #pod | ||
| 64 | #pod =cut | ||
| 65 | |||
| 66 | 15 | has as_string => ( is => 'ro', lazy => 1, default => \&_build_as_string ); | |
| 67 | |||
| 68 | 4 | ▶ | sub _build_as_string { |
|
Subroutine
_build_as_string: called CC=1 SCAR=0.0
| |||
| 69 | 4 | my $self = shift; | |
| 70 | 4 | my $element = $self->element; | |
| 71 | 4 | my $type = ref $element; | |
| 72 | |||
| 73 | 4 | $type =~ s/\A .* :://xms; | |
| 74 | 4 | const my %TYPE_MAP => ( | |
| 75 | Table => $element->from, | ||
| 76 | ResultSet => $element->result_class, | ||
| 77 | Schema => 'schema', | ||
| 78 | ); | ||
| 79 | return "[$type $TYPE_MAP{$type}] " . join "\n", | ||
| 80 | 4 | map { $self->$_ } @TEXT_FIELDS; | |
| 81 | } | ||
| 82 | |||
| 83 | #pod =attr as_string | ||
| 84 | #pod | ||
| 85 | #pod Returns a string representation of the object. The same method is called if | ||
| 86 | #pod the object appears in double quotes. | ||
| 87 | #pod | ||
| 88 | #pod =cut | ||
| 89 | |||
| 90 | 15 | 1; | |
| 91 | |||
| 92 | __END__ | ||