| 1 | package DBIx::Class::MassAssignable; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.010000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use base qw(DBIx::Class); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Carp qw/croak carp/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | our $VERSION = '0.03'; | ||||||||||
| 10 | |||||||||||
| 11 | __PACKAGE__->mk_group_accessors('inherited', qw/ | ||||||||||
| 12 | attr_accessible | ||||||||||
| 13 | attr_protected | ||||||||||
| 14 | /); | ||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub set_columns { | ||||||||
|
Subroutine
set_columns: not called CC=1 SCAR=6.9
| |||||||||||
| 17 | 0 | my $self = shift; | |||||||||
| 18 | 0 | my $columns = shift; | |||||||||
| 19 | |||||||||||
| 20 | 0 | $self->_sanitize_mass_assignment($columns); | |||||||||
| 21 | |||||||||||
| 22 | 0 | return $self->next::method( $columns ); | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | sub set_inflated_columns { | ||||||||
|
Subroutine
set_inflated_columns: not called CC=1 SCAR=6.9
| |||||||||||
| 26 | 0 | my $self = shift; | |||||||||
| 27 | 0 | my $columns = shift; | |||||||||
| 28 | |||||||||||
| 29 | 0 | $self->_sanitize_mass_assignment($columns); | |||||||||
| 30 | |||||||||||
| 31 | 0 | return $self->next::method( $columns ); | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | sub _sanitize_mass_assignment { | ||||||||
|
Subroutine
_sanitize_mass_assignment: not called CC=1 SCAR=6.9
| |||||||||||
| 36 | 0 | my $self = shift; | |||||||||
| 37 | 0 | my $columns = shift; | |||||||||
| 38 | 0 | my $disable_warnings = shift; | |||||||||
| 39 | |||||||||||
| 40 | 0 | $self->_sanitize_attr_accessible($columns, $disable_warnings); | |||||||||
| 41 | 0 | $self->_sanitize_attr_protected($columns, $disable_warnings); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | sub _sanitize_attr_accessible { | ||||||||
|
Subroutine
_sanitize_attr_accessible: not called CC=6 SCAR=37.4
| |||||||||||
| 45 | 0 | my $self = shift; | |||||||||
| 46 | 0 | my $columns = shift; | |||||||||
| 47 | 0 | my $disable_warnings = shift; | |||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | return unless defined $self->attr_accessible; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | ▶ | croak "attr_accessible must be passed an array ref" unless ref($self->attr_accessible) eq "ARRAY"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | 0 | my %accessible = map { $_ => 1 } @{$self->attr_accessible} ; | |||||||||
| 53 | 0 | foreach my $key( keys %$columns ) { | |||||||||
| 54 | 0 | ▶ | unless($accessible{$key}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 0 | ▶ | carp "Attempted to mass assign none whitelisted value $key" unless $disable_warnings; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 0 | delete $columns->{$key} ; | |||||||||
| 57 | } | ||||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | sub _sanitize_attr_protected { | ||||||||
|
Subroutine
_sanitize_attr_protected: not called CC=6 SCAR=37.4
| |||||||||||
| 63 | 0 | my $self = shift; | |||||||||
| 64 | 0 | my $columns = shift; | |||||||||
| 65 | 0 | my $disable_warnings = shift; | |||||||||
| 66 | |||||||||||
| 67 | 0 | ▶ | return unless defined $self->attr_protected; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | ▶ | croak "attr_protected must be passed an array ref" unless ref($self->attr_protected) eq "ARRAY"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | |||||||||||
| 70 | 0 | my %protected = map { $_ => 1 } @{$self->attr_protected}; | |||||||||
| 71 | 0 | foreach my $key( keys %$columns ) { | |||||||||
| 72 | 0 | ▶ | if($protected{$key}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 0 | ▶ | carp "Attempted to mass assign blacklisted value $key" unless $disable_warnings; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 0 | delete $columns->{$key} ; | |||||||||
| 75 | } | ||||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 0 | ▶ | sub mass_assignable_columns { | ||||||||
|
Subroutine
mass_assignable_columns: not called CC=2 SCAR=17.9
| |||||||||||
| 81 | 0 | my $self = shift; | |||||||||
| 82 | |||||||||||
| 83 | 0 | my %columns = map { $_ => 1 } ($self->columns()); | |||||||||
| 84 | 0 | $self->_sanitize_mass_assignment(\%columns, 1); | |||||||||
| 85 | 0 | my @columns = keys %columns; | |||||||||
| 86 | 0 | ▶ | return @columns if wantarray; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 0 | return \@columns; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 1; | ||||||||||
| 91 | __END__ | ||||||||||