line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::DBCritic::Policy::NullableTextColumn; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
4470
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
190
|
|
4
|
5
|
|
|
5
|
|
21
|
use utf8; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
32
|
|
5
|
5
|
|
|
5
|
|
109
|
use Modern::Perl '2011'; ## no critic (Modules::ProhibitUseQuotedVersion) |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
42
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.021'; # TRIAL VERSION |
8
|
5
|
|
|
5
|
|
838
|
use DBI ':sql_types'; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
2088
|
|
9
|
5
|
|
|
5
|
|
30
|
use English '-no_match_vars'; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
46
|
|
10
|
5
|
|
|
5
|
|
2028
|
use List::Util 1.33 'any'; |
|
5
|
|
|
|
|
155
|
|
|
5
|
|
|
|
|
369
|
|
11
|
5
|
|
|
5
|
|
27
|
use Moo; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
33
|
|
12
|
5
|
|
|
5
|
|
2436
|
use Sub::Quote; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
475
|
|
13
|
5
|
|
|
5
|
|
25
|
use namespace::autoclean -also => qr{\A _}xms; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
64
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has description => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
default => quote_sub q{'Nullable text column'}, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
has explanation => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
default => quote_sub |
22
|
|
|
|
|
|
|
q{'Text columns should not be nullable. Default to empty string instead.'}, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub violates { |
26
|
|
|
|
|
|
|
my $source = shift->element; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
## no critic (ProhibitAccessOfPrivateData,ProhibitCallsToUndeclaredSubs) |
29
|
|
|
|
|
|
|
my @text_types = ( |
30
|
|
|
|
|
|
|
qw(TEXT NTEXT CLOB NCLOB CHARACTER CHAR NCHAR VARCHAR VARCHAR2 NVARCHAR2), |
31
|
|
|
|
|
|
|
'CHARACTER VARYING', |
32
|
|
|
|
|
|
|
map { uc $ARG->{TYPE_NAME} } |
33
|
|
|
|
|
|
|
map { $source->storage->dbh->type_info($ARG) } ( |
34
|
|
|
|
|
|
|
SQL_CHAR, SQL_CLOB, |
35
|
|
|
|
|
|
|
SQL_VARCHAR, SQL_WVARCHAR, |
36
|
|
|
|
|
|
|
SQL_LONGVARCHAR, SQL_WLONGVARCHAR, |
37
|
|
|
|
|
|
|
), |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my %column = %{ $source->columns_info }; |
41
|
|
|
|
|
|
|
return join "\n", map {"$ARG is a nullable text column."} grep { |
42
|
|
|
|
|
|
|
my $col = $_; |
43
|
|
|
|
|
|
|
any { uc( $column{$col}{data_type} // q{} ) eq $_ } @text_types |
44
|
|
|
|
|
|
|
and $column{$col}{is_nullable}; |
45
|
|
|
|
|
|
|
} keys %column; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
with 'App::DBCritic::PolicyType::ResultSource'; |
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# ABSTRACT: Check for ResultSources with nullable text columns |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |