App-DBCritic

 view release on metacpan or  search on metacpan

lib/App/DBCritic/Violation.pm  view on Meta::CPAN

package App::DBCritic::Violation;

# ABSTRACT: A violation of a App::DBCritic::Policy

#pod =head1 SYNOPSIS
#pod
#pod     use App::DBCritic::Violation;
#pod
#pod     my $violation = App::DBCritic::Violation->new(
#pod         description => 'Violated policy',
#pod         explanation => 'Consult the rulebook',
#pod         description => 'The frob table is improperly swizzled.',
#pod     );
#pod     print "$violation\n";
#pod
#pod =head1 DESCRIPTION
#pod
#pod This class represents L<App::DBCritic::Policy|App::DBCritic::Policy>
#pod violations flagged by L<App::DBCritic|App::DBCritic>.
#pod
#pod =cut

use strict;
use utf8;
use Modern::Perl '2011';    ## no critic (Modules::ProhibitUseQuotedVersion)

our $VERSION = '0.023';     # VERSION
use Const::Fast;
use English '-no_match_vars';
use Moo;
use Sub::Quote;
use overload q{""} => sub { shift->as_string };

const my @TEXT_FIELDS => qw(description explanation details);
for (@TEXT_FIELDS) {
    has $_ => ( is => 'ro', default => quote_sub q{q{}} );
}

#pod =attr description
#pod
#pod A short string briefly describing what's wrong.
#pod Only settable at construction.
#pod
#pod =attr explanation
#pod
#pod A string giving a longer general description of the problem.
#pod Only settable at construction.
#pod
#pod =attr details
#pod
#pod A string describing the issue as it specifically applies to the L</element>
#pod being critiqued.
#pod
#pod =cut

has element => ( is => 'ro' );

#pod =attr element
#pod
#pod The schema element that violated a
#pod L<App::DBCritic::Policy|App::DBCritic::Policy>.
#pod Only settable at construction.
#pod
#pod =cut

has as_string => ( is => 'ro', lazy => 1, default => \&_build_as_string );

sub _build_as_string {
    my $self    = shift;
    my $element = $self->element;
    my $type    = ref $element;

    $type =~ s/\A .* :://xms;
    const my %TYPE_MAP => (
        Table     => $element->from,
        ResultSet => $element->result_class,
        Schema    => 'schema',
    );
    return "[$type $TYPE_MAP{$type}] " . join "\n",
        map { $self->$_ } @TEXT_FIELDS;
}

#pod =attr as_string
#pod
#pod Returns a string representation of the object.  The same method is called if

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.865 second using v1.00-cache-2.02-grep-82fe00e-cpan-72ae3ad1e6da )