line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::Helper::Schema::Verifier::ColumnInfo; |
2
|
|
|
|
|
|
|
$DBIx::Class::Helper::Schema::Verifier::ColumnInfo::VERSION = '2.036000'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Verify that Results only use approved column_info keys |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
83320
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
391
|
use MRO::Compat; |
|
1
|
|
|
|
|
1724
|
|
|
1
|
|
|
|
|
23
|
|
9
|
1
|
|
|
1
|
|
7
|
use mro 'c3'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
24
|
use base 'DBIx::Class::Helper::Schema::Verifier'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
449
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my @allowed_keys = ( |
14
|
|
|
|
|
|
|
# defaults from ::ResultSource |
15
|
|
|
|
|
|
|
qw( |
16
|
|
|
|
|
|
|
accessor |
17
|
|
|
|
|
|
|
auto_nextval |
18
|
|
|
|
|
|
|
data_type |
19
|
|
|
|
|
|
|
default_value |
20
|
|
|
|
|
|
|
extra |
21
|
|
|
|
|
|
|
is_auto_increment |
22
|
|
|
|
|
|
|
is_foreign_key |
23
|
|
|
|
|
|
|
is_nullable |
24
|
|
|
|
|
|
|
is_numeric |
25
|
|
|
|
|
|
|
retrieve_on_insert |
26
|
|
|
|
|
|
|
sequence |
27
|
|
|
|
|
|
|
size |
28
|
|
|
|
|
|
|
), |
29
|
|
|
|
|
|
|
# ::InflateColumn::DateTime |
30
|
|
|
|
|
|
|
qw( |
31
|
|
|
|
|
|
|
floating_tz_ok |
32
|
|
|
|
|
|
|
inflate_datetime |
33
|
|
|
|
|
|
|
locale |
34
|
|
|
|
|
|
|
timezone |
35
|
|
|
|
|
|
|
), |
36
|
|
|
|
|
|
|
# ::InflateColumn::File and ::InflateColumn::FS |
37
|
|
|
|
|
|
|
qw( |
38
|
|
|
|
|
|
|
file_column_path |
39
|
|
|
|
|
|
|
fs_column_path |
40
|
|
|
|
|
|
|
fs_new_on_update |
41
|
|
|
|
|
|
|
is_file_column |
42
|
|
|
|
|
|
|
is_fs_column |
43
|
|
|
|
|
|
|
), |
44
|
|
|
|
|
|
|
# ::Helpers |
45
|
|
|
|
|
|
|
qw( |
46
|
|
|
|
|
|
|
is_serializable |
47
|
|
|
|
|
|
|
keep_storage_value |
48
|
|
|
|
|
|
|
remove_column |
49
|
|
|
|
|
|
|
) ); |
50
|
|
|
|
|
|
|
|
51
|
3
|
|
|
3
|
1
|
55
|
sub allowed_column_keys { @allowed_keys } |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub result_verifiers { |
54
|
3
|
|
|
3
|
1
|
2845
|
my $self = shift; |
55
|
3
|
|
|
|
|
10
|
my %allowed = map { $_ => 1 } $self->allowed_column_keys; |
|
75
|
|
|
|
|
150
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
( |
58
|
|
|
|
|
|
|
sub { |
59
|
3
|
|
|
3
|
|
14
|
my ($s, $result, $set) = @_; |
60
|
3
|
|
|
|
|
13
|
my $column_info = $result->columns_info; |
61
|
3
|
|
|
|
|
23
|
for my $col_name (keys %$column_info) { |
62
|
3
|
|
|
|
|
6
|
for my $key (keys %{ $column_info->{$col_name} }) { |
|
3
|
|
|
|
|
8
|
|
63
|
14
|
100
|
|
|
|
32
|
if (!$allowed{$key}) { |
64
|
1
|
|
|
|
|
12
|
die sprintf join(' ', qw(Forbidden column config <%s> used in |
65
|
|
|
|
|
|
|
column <%s> in result <%s>. You can explicitly allow it by |
66
|
|
|
|
|
|
|
adding it to your schema's allowed_column_keys method.)), |
67
|
|
|
|
|
|
|
$key, $col_name, $result; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
}, |
72
|
3
|
|
|
|
|
28
|
$self->next::method, |
73
|
|
|
|
|
|
|
) |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=pod |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 NAME |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
DBIx::Class::Helper::Schema::Verifier::ColumnInfo - Verify that Results only use approved column_info keys |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
package MyApp::Schema; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__PACKAGE__->load_components('Helper::Schema::Verifier::ColumnInfo'); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# optionally add some non-standard allowed keys |
93
|
|
|
|
|
|
|
sub allowed_column_keys { |
94
|
|
|
|
|
|
|
my $self = shift; |
95
|
|
|
|
|
|
|
my @keys = $self->next::method; |
96
|
|
|
|
|
|
|
push @keys, qw(is_serializable keep_storage_value remove_column); |
97
|
|
|
|
|
|
|
return @keys; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 DESCRIPTION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
C<DBIx::Class::Helper::Schema::Verifier::ColumnInfo> verifies that none of your |
103
|
|
|
|
|
|
|
columns use non-approved configuration keys. L<DBIx::Class> doesn't do any key |
104
|
|
|
|
|
|
|
verification, so this Helper makes sure you don't get burned by a typo like |
105
|
|
|
|
|
|
|
using C<autoincrement> instead of C<is_auto_increment>. If your schema uses a |
106
|
|
|
|
|
|
|
non-approved column config key, it will refuse to load and instead offer a |
107
|
|
|
|
|
|
|
hopefully helpful message pointing out the error. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 METHODS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 allowed_column_keys() |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
It's entirely possible that you would like to use some non-default config keys, |
114
|
|
|
|
|
|
|
especially if you use some column-extension components. Override this method in |
115
|
|
|
|
|
|
|
your schema and append your new keys to the list returned by the superclass |
116
|
|
|
|
|
|
|
call. The overridden method must return a list of keys. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub allowed_column_keys { |
119
|
|
|
|
|
|
|
my $self = shift; |
120
|
|
|
|
|
|
|
my @keys = $self->next::method; |
121
|
|
|
|
|
|
|
# modify @keys as needed |
122
|
|
|
|
|
|
|
return @keys; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 AUTHOR |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Arthur Axel "fREW" Schmidt. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
134
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |