| 1 | package DBIx::Class::Helper::ResultSet::RemoveColumns; | ||||||||||||||||||||||||||||
| 2 | 54 | $DBIx::Class::Helper::ResultSet::RemoveColumns::VERSION = '2.032002'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Remove columns from a ResultSet | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 54 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 54 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 54 | ▶ | use parent 'DBIx::Class::ResultSet'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | sub _resolved_attrs { | ||||||||||||||||||||||||||||
| 11 | 486 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
_resolved_attrs: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 486 | my $attrs = $self->{attrs}; # not copying on purpose... | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 486 | ▶ | if ( !$attrs->{columns} && $attrs->{remove_columns} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $attrs->{"columns"} and $attrs->{"remove_columns"}
MC/DC100%2/2
not $attrs->{"columns"} and $attrs->{"remove_columns"}
not $attrs->{"columns"}
$attrs->{"remove_columns"}
Truth table100%3/3
not(A) and B
A= not $attrs->{"columns"}B= $attrs->{"remove_columns"}
| |||||||||||||||||||||||||||||
| 16 | 51 | my %rc = map { $_ => 1 } @{$attrs->{remove_columns}}; | |||||||||||||||||||||||||||
| 17 | $attrs->{columns} = [ | ||||||||||||||||||||||||||||
| 18 | 51 | grep { !$rc{$_} } $self->result_source->columns | |||||||||||||||||||||||||||
| 19 | ] | ||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 486 | return $self->next::method; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 54 | 1; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | __END__ | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =pod | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 NAME | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | DBIx::Class::Helper::ResultSet::RemoveColumns - Remove columns from a ResultSet | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | package MySchema::ResultSet::Bar; | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | use strict; | ||||||||||||||||||||||||||||
| 40 | use warnings; | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | use parent 'DBIx::Class::ResultSet'; | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | __PACKAGE__->load_components('Helper::ResultSet::RemoveColumns'); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # in code using resultset: | ||||||||||||||||||||||||||||
| 47 | my $rs = $schema->resultset('Bar')->search(undef, { | ||||||||||||||||||||||||||||
| 48 | remove_columns => ['giant_text_col', 'password'], | ||||||||||||||||||||||||||||
| 49 | }); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | This component allows convenient removal of columns from a select. | ||||||||||||||||||||||||||||
| 54 | Normally to do this you would do this by listing all of the columns | ||||||||||||||||||||||||||||
| 55 | B<except> the ones you want to remove. This does that part for you. | ||||||||||||||||||||||||||||
| 56 | See L<DBIx::Class::Helper::ResultSet/NOTE> for a nice way to apply it to | ||||||||||||||||||||||||||||
| 57 | your entire schema. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | It doesn't get a lot more complicated than the synopsis. If you are interested | ||||||||||||||||||||||||||||
| 60 | in having more control, check out | ||||||||||||||||||||||||||||
| 61 | L<DBIx::Class::Helper::ResultSet::AutoRemoveColumns>. | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =over | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =item * | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | Load the component | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =item * | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Put an C<ArrayRef> of columns to remove in the C<remove_columns> search attribute. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =item * | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Profit. | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =back | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | This software is copyright (c) 2016 by Arthur Axel "fREW" Schmidt. | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 88 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||||||||||