| 1 | package DBIx::Class::Helper::Schema::Verifier::ColumnInfo; | ||||||||||
| 2 | 1 | $DBIx::Class::Helper::Schema::Verifier::ColumnInfo::VERSION = '2.033001'; | |||||||||
| 3 | # ABSTRACT: Verify that Results only use approved column_info keys | ||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use MRO::Compat; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use mro 'c3'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use base 'DBIx::Class::Helper::Schema::Verifier'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | 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 | ▶ | sub allowed_column_keys { @allowed_keys } | ||||||||
|
Subroutine
allowed_column_keys: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 52 | |||||||||||
| 53 | sub result_verifiers { | ||||||||||
| 54 | 3 | ▶ | my $self = shift; | ||||||||
|
Subroutine
result_verifiers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 55 | 3 | my %allowed = map { $_ => 1 } $self->allowed_column_keys; | |||||||||
| 56 | |||||||||||
| 57 | ( | ||||||||||
| 58 | sub { | ||||||||||
| 59 | 3 | ▶ | my ($s, $result, $set) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||
| 60 | 3 | my $column_info = $result->columns_info; | |||||||||
| 61 | 3 | for my $col_name (keys %$column_info) { | |||||||||
| 62 | 3 | for my $key (keys %{ $column_info->{$col_name} }) { | |||||||||
| 63 | 14 | ▶ | if (!$allowed{$key}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 1 | 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 | $self->next::method, | |||||||||
| 73 | ) | ||||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 1 | 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) 2016 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 | ||||||||||