line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::Helper::ResultSet::AutoRemoveColumns; |
2
|
|
|
|
|
|
|
$DBIx::Class::Helper::ResultSet::AutoRemoveColumns::VERSION = '2.035000'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Automatically remove columns from a ResultSet |
4
|
|
|
|
|
|
|
|
5
|
56
|
|
|
56
|
|
246553
|
use strict; |
|
56
|
|
|
|
|
211
|
|
|
56
|
|
|
|
|
1775
|
|
6
|
56
|
|
|
56
|
|
334
|
use warnings; |
|
56
|
|
|
|
|
160
|
|
|
56
|
|
|
|
|
1715
|
|
7
|
|
|
|
|
|
|
|
8
|
56
|
|
|
56
|
|
323
|
use parent 'DBIx::Class::Helper::ResultSet::RemoveColumns', 'DBIx::Class::ResultSet'; |
|
56
|
|
|
|
|
141
|
|
|
56
|
|
|
|
|
348
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->mk_group_accessors(inherited => '_fetchable_columns'); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
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
|
228
|
|
|
228
|
|
1267
|
my ( $self, $column ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
228
|
|
|
|
|
833
|
my $info = $self->result_source->column_info($column); |
24
|
|
|
|
|
|
|
|
25
|
228
|
100
|
|
|
|
2654
|
if (!defined $info->{remove_column}) { |
26
|
132
|
100
|
66
|
|
|
846
|
if (defined $info->{data_type} && |
27
|
|
|
|
|
|
|
$dont_fetch{lc $info->{data_type}} |
28
|
|
|
|
|
|
|
) { |
29
|
88
|
|
|
|
|
224
|
$info->{remove_column} = 1; |
30
|
|
|
|
|
|
|
} else { |
31
|
44
|
|
|
|
|
161
|
$info->{remove_column} = 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
228
|
|
|
|
|
1892
|
return $info->{remove_column}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub fetchable_columns { |
39
|
111
|
|
|
111
|
1
|
298
|
my $self = shift; |
40
|
111
|
100
|
|
|
|
2782
|
if (!$self->_fetchable_columns) { |
41
|
57
|
|
|
|
|
5874
|
$self->_fetchable_columns([ |
42
|
|
|
|
|
|
|
grep $self->_should_column_fetch($_), |
43
|
|
|
|
|
|
|
$self->result_source->columns |
44
|
|
|
|
|
|
|
]); |
45
|
|
|
|
|
|
|
} |
46
|
111
|
|
|
|
|
4067
|
return $self->_fetchable_columns; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _resolved_attrs { |
50
|
|
|
|
|
|
|
local $_[0]->{attrs}{remove_columns} = |
51
|
115
|
|
66
|
115
|
|
48270
|
$_[0]->{attrs}{remove_columns} || $_[0]->fetchable_columns; |
52
|
|
|
|
|
|
|
|
53
|
115
|
|
|
|
|
1919
|
return $_[0]->next::method; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
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) 2020 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 |