App-DBCritic
view release on metacpan or search on metacpan
lib/App/DBCritic/Policy/NullableTextColumn.pm view on Meta::CPAN
package App::DBCritic::Policy::NullableTextColumn;
# ABSTRACT: Check for ResultSources with nullable text columns
#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 nullable text
#pod columns.
#pod
#pod =cut
use strict;
use utf8;
use Modern::Perl '2011'; ## no critic (Modules::ProhibitUseQuotedVersion)
our $VERSION = '0.023'; # VERSION
use DBI ':sql_types';
use English '-no_match_vars';
use List::Util 1.33 'any';
use Moo;
use Sub::Quote;
use namespace::autoclean -also => qr{\A _}xms;
has description => (
is => 'ro',
default => quote_sub q{'Nullable text column'},
);
#pod =attr description
#pod
#pod "Nullable text column"
#pod
#pod =cut
has explanation => (
is => 'ro',
default => quote_sub
q{'Text columns should not be nullable. Default to empty string instead.'},
);
#pod =attr explanation
#pod
#pod "Text columns should not be nullable. Default to empty string instead."
#pod
#pod =cut
sub violates {
my $source = shift->element;
## no critic (ProhibitAccessOfPrivateData,ProhibitCallsToUndeclaredSubs)
my @text_types = (
qw(TEXT NTEXT CLOB NCLOB CHARACTER CHAR NCHAR VARCHAR VARCHAR2 NVARCHAR2),
'CHARACTER VARYING',
map { uc $_->{TYPE_NAME} }
map { $source->storage->dbh->type_info($_) } (
SQL_CHAR, SQL_CLOB,
SQL_VARCHAR, SQL_WVARCHAR,
SQL_LONGVARCHAR, SQL_WLONGVARCHAR,
),
);
lib/App/DBCritic/Policy/NullableTextColumn.pm view on Meta::CPAN
#pod =item C<CHAR>
#pod
#pod =item C<NCHAR>
#pod
#pod =item C<VARCHAR>
#pod
#pod =item C<VARCHAR2>
#pod
#pod =item C<NVARCHAR2>
#pod
#pod =item C<CHARACTER VARYING>
#pod
#pod =item C<SQL_CHAR>
#pod
#pod =item C<SQL_CLOB>
#pod
#pod =item C<SQL_VARCHAR>
#pod
#pod =item C<SQL_WVARCHAR>
#pod
#pod =item C<SQL_LONGVARCHAR>
#pod
#pod =item C<SQL_WLONGVARCHAR>
#pod
#pod =back
#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::NullableTextColumn - Check for ResultSources with nullable text columns
=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 nullable text
columns.
=head1 ATTRIBUTES
=head2 description
"Nullable text column"
=head2 explanation
"Text columns should not be nullable. Default to empty string instead."
=head2 applies_to
This policy applies to L<ResultSource|DBIx::Class::ResultSource>s.
=head1 METHODS
=head2 violates
Returns details of each column from the
L<"current element"|App::DBCritic::Policy> that maps to
following data types and
L<"is nullable"|DBIx::Class::ResultSource/is_nullable>:
=over
=item C<TEXT>
=item C<NTEXT>
=item C<CLOB>
=item C<NCLOB>
=item C<CHARACTER>
=item C<CHAR>
=item C<NCHAR>
=item C<VARCHAR>
=item C<VARCHAR2>
=item C<NVARCHAR2>
=item C<CHARACTER VARYING>
=item C<SQL_CHAR>
=item C<SQL_CLOB>
=item C<SQL_VARCHAR>
( run in 1.024 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )