File Coverage

blib/lib/DBIx/Class/Helper/ResultSet/RemoveColumns.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 2 100.0
condition 6 6 100.0
subroutine 4 4 100.0
pod n/a
total 30 30 100.0


line stmt bran cond sub pod time code
1             package DBIx::Class::Helper::ResultSet::RemoveColumns;
2             $DBIx::Class::Helper::ResultSet::RemoveColumns::VERSION = '2.036000';
3             # ABSTRACT: Remove columns from a ResultSet
4              
5 57     57   25767 use strict;
  57         183  
  57         1544  
6 57     57   291 use warnings;
  57         147  
  57         1378  
7              
8 57     57   330 use parent 'DBIx::Class::ResultSet';
  57         155  
  57         313  
9              
10             sub _resolved_attrs {
11 507     507   187738 my $self = $_[0];
12              
13 507         982 my $attrs = $self->{attrs}; # not copying on purpose...
14              
15 507 100 100     2914 if ( !$attrs->{columns} && !$attrs->{select} && $attrs->{remove_columns} ) {
      100        
16 54         181 my %rc = map { $_ => 1 } @{$attrs->{remove_columns}};
  158         464  
  54         206  
17             $attrs->{columns} = [
18 54         345 grep { !$rc{$_} } $self->result_source->columns
  212         1033  
19             ]
20             }
21              
22 507         1466 return $self->next::method;
23             }
24              
25             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) 2020 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