Helper/ResultSet/AutoRemoveColumns.pm

filter: Statementstmt 100% 26 / 26 Branchbran 100% 6 / 6 Conditioncond 66.6% 4 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 89.8% 44 / 49 CC 6 SCAR 9.0
CC
6
Cov
95%
_should_column_fetch
4.0
_resolved_attrs
2.0
fetchable_columns
2.0
CRAP 2.5
« Helper/Row/NumifyGet.pm ↑ Summary Helper/Row/ToJSON.pm »
1 package DBIx::Class::Helper::ResultSet::AutoRemoveColumns;
2 54 $DBIx::Class::Helper::ResultSet::AutoRemoveColumns::VERSION = '2.032002';
3 # ABSTRACT: Automatically 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::Helper::ResultSet::RemoveColumns', 'DBIx::Class::ResultSet';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 54 __PACKAGE__->mk_group_accessors(inherited => '_fetchable_columns');
11  
12 54 my %dont_fetch = (
13 text => 1,
14 ntext => 1,
15 blob => 1,
16 clob => 1,
17 bytea => 1,
18 );
19  
20 sub _should_column_fetch {
21 204 ▶ my ( $self, $column ) = @_;
Subroutine _should_column_fetch: called CC=4 SCAR=13.9
22  
23 204 my $info = $self->result_source->column_info($column);
24  
25 204 ▶ if (!defined $info->{remove_column}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $info->{"remove_column"}) 126 78 204
26 126 ▶ if (defined $info->{data_type} &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{'data_type'} and $dont_fetch{lc $info->{'data_type'}}) { } 84 42 126
Condition66%2/3
defined $info->{"data_type"} and $dont_fetch{lc $info->{"data_type"}}
!ll&&!rl&&r
04284
MC/DC50%1/2
defined $info->{"data_type"} and $dont_fetch{lc $info->{"data_type"}}
defined $info->{"data_type"} $dont_fetch{lc $info->{"data_type"}}
Truth table66%2/3
A and B
A= defined $info->{"data_type"}B= $dont_fetch{lc $info->{"data_type"}}
ABresult
0X0
100
111
27 $dont_fetch{lc $info->{data_type}}
28 ) {
29 84 $info->{remove_column} = 1;
30 } else {
31 42 $info->{remove_column} = 0;
32 }
33 }
34  
35 204 return $info->{remove_column};
36 }
37  
38 sub fetchable_columns {
39 102 ▶ my $self = shift;
Subroutine fetchable_columns: called CC=2 SCAR=6.9
Pod documented
40 102 ▶ if (!$self->_fetchable_columns) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_fetchable_columns) 51 51 102
41 51 $self->_fetchable_columns([
42 grep $self->_should_column_fetch($_),
43 $self->result_source->columns
44 ]);
45 }
46 102 return $self->_fetchable_columns;
47 }
48  
49 sub _resolved_attrs {
50 local $_[0]->{attrs}{remove_columns} =
51 104 ▶ $_[0]->{attrs}{remove_columns} || $_[0]->fetchable_columns;
Subroutine _resolved_attrs: called CC=2 SCAR=7.1
Condition66%2/3
$_[0]{'attrs'}{'remove_columns'} || $_[0]->fetchable_columns
l!l&&r!l&&!r
21020
MC/DC0%0/2
$_[0]{'attrs'}{'remove_columns'} || $_[0]->fetchable_columns
$_[0]{'attrs'}{'remove_columns'} $_[0]->fetchable_columns
Truth table66%2/3
A || B
A= $_[0]{'attrs'}{'remove_columns'}B= $_[0]->fetchable_columns
ABresult
1X1
011
000
52  
53 104 return $_[0]->next::method;
54 }
55  
56 54 1;
57  
58 __END__
59  
60 =pod
61  
62 =head1 NAME
63  
64 DBIx::Class::Helper::ResultSet::AutoRemoveColumns - Automatically remove columns from a ResultSet
65  
66 =head1 SYNOPSIS
67  
68 package MySchema::Result::Bar;
69  
70 use strict;
71 use warnings;
72  
73 use parent 'DBIx::Class::Core';
74  
75 __PACKAGE__->table('KittenRobot');
76 __PACKAGE__->add_columns(
77 id => {
78 data_type => 'integer',
79 is_auto_increment => 1,
80 },
81 kitten => {
82 data_type => 'integer',
83 },
84 robot => {
85 data_type => 'text',
86 is_nullable => 1,
87 },
88 your_mom => {
89 data_type => 'blob',
90 is_nullable => 1,
91 remove_column => 0,
92 },
93 );
94  
95 1;
96  
97 package MySchema::ResultSet::Bar;
98  
99 use strict;
100 use warnings;
101  
102 use parent 'DBIx::Class::ResultSet';
103  
104 __PACKAGE__->load_components('Helper::ResultSet::AutoRemoveColumns');
105  
106 =head1 DESCRIPTION
107  
108 This component automatically removes "heavy-weight" columns. To be specific,
109 columns of type C<text>, C<ntext>, C<blob>, C<clob>, or C<bytea>. You may
110 use the C<remove_column> key in the column info to specify directly whether or
111 not to remove the column automatically. See
112 L<DBIx::Class::Helper::ResultSet/NOTE> for a nice way to apply it to your
113 entire schema.
114  
115 =head1 METHODS
116  
117 =head2 _should_column_fetch
118  
119 $self->_should_column_fetch('kitten')
120  
121 returns true if a column should be fetched or not. This fetches a column if it
122 is not of type C<text>, C<ntext>, C<blob>, C<clob>, or C<bytea> or the
123 C<remove_column> is set to true. If you only wanted to explicitly state which
124 columns to remove you might override this method like this:
125  
126 sub _should_column_fetch {
127 my ( $self, $column ) = @_;
128  
129 my $info = $self->column_info($column);
130  
131 return !defined $info->{remove_column} || $info->{remove_column};
132 }
133  
134 =head2 fetchable_columns
135  
136 simply returns a list of columns that are fetchable.
137  
138 =head1 AUTHOR
139  
140 Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
141  
142 =head1 COPYRIGHT AND LICENSE
143  
144 This software is copyright (c) 2016 by Arthur Axel "fREW" Schmidt.
145  
146 This is free software; you can redistribute it and/or modify it under
147 the same terms as the Perl 5 programming language system itself.
148  
149 =cut
« Helper/Row/NumifyGet.pm ↑ Summary Helper/Row/ToJSON.pm »