| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
28
|
|
|
28
|
|
1682
|
use warnings; |
|
|
28
|
|
|
|
|
99
|
|
|
|
28
|
|
|
|
|
1058
|
|
|
2
|
28
|
|
|
28
|
|
161
|
use strict; |
|
|
28
|
|
|
|
|
54
|
|
|
|
28
|
|
|
|
|
1604
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Jifty::DBI::Filter; |
|
5
|
28
|
|
|
28
|
|
151
|
use base 'Class::Accessor::Fast'; |
|
|
28
|
|
|
|
|
56
|
|
|
|
28
|
|
|
|
|
9703
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(record column value_ref handle)); |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Jifty::DBI::Filter - base class for Jifty::DBI filters |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# To implement your own filter |
|
16
|
|
|
|
|
|
|
package MyApp::Filter::Uppercase; |
|
17
|
|
|
|
|
|
|
use base qw/ Jifty::DBI::Filter /; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Setup for DB storage, store in lowercase |
|
20
|
|
|
|
|
|
|
sub encode { |
|
21
|
|
|
|
|
|
|
my $self = shift; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $value_ref = $self->value_ref; |
|
24
|
|
|
|
|
|
|
return unless defined $$value_ref; # don't blow up on undef |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$$value_ref = lc $$value_ref; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Setup for Perl code to use, always sees uppercase |
|
30
|
|
|
|
|
|
|
sub decode { |
|
31
|
|
|
|
|
|
|
my $self = shift; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $value_ref = $self->value_ref; |
|
34
|
|
|
|
|
|
|
return unless defined $$value_ref; # don't blow up on undef |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$$value_ref = uc $$value_ref; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# To use a filter |
|
40
|
|
|
|
|
|
|
use MyApp::Record schema { |
|
41
|
|
|
|
|
|
|
column filtered => |
|
42
|
|
|
|
|
|
|
type is 'text', |
|
43
|
|
|
|
|
|
|
filters are qw/ MyApp::Filter::Uppercase /; |
|
44
|
|
|
|
|
|
|
}; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
A filter allows Jifty::DBI models to tweak data prior to being stored and/or loaded. This is useful for marshalling and unmarshalling complex objects. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 METHODS |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 new |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Takes three arguments in a parameter hash: |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=over |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item value_ref |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
A reference to the current value you're going to be |
|
62
|
|
|
|
|
|
|
massaging. C works in place, massaging whatever value_ref |
|
63
|
|
|
|
|
|
|
refers to. |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item column |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
A L object, whatever sort of column we're working |
|
68
|
|
|
|
|
|
|
with here. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item handle |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
A L object, because some filters (i.e. |
|
73
|
|
|
|
|
|
|
L) depend on what database system is being used. |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=back |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub new { |
|
80
|
818
|
|
|
818
|
1
|
2054
|
my $class = shift; |
|
81
|
818
|
|
|
|
|
4549
|
my %args = ( |
|
82
|
|
|
|
|
|
|
column => undef, |
|
83
|
|
|
|
|
|
|
value_ref => undef, |
|
84
|
|
|
|
|
|
|
handle => undef, |
|
85
|
|
|
|
|
|
|
@_ |
|
86
|
|
|
|
|
|
|
); |
|
87
|
818
|
|
|
|
|
8287
|
my $self = $class->SUPER::new( { |
|
88
|
|
|
|
|
|
|
record => delete $args{record}, |
|
89
|
|
|
|
|
|
|
column => delete $args{column}, |
|
90
|
|
|
|
|
|
|
value_ref => delete $args{value_ref}, |
|
91
|
|
|
|
|
|
|
handle => delete $args{handle}, |
|
92
|
|
|
|
|
|
|
} ); |
|
93
|
|
|
|
|
|
|
|
|
94
|
818
|
|
|
|
|
32889
|
for ( grep $self->can($_), keys %args ) { |
|
95
|
0
|
|
|
|
|
0
|
$self->$_( $args{$_} ); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
818
|
|
|
|
|
2809
|
return ($self); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 encode |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
C takes data that users are handing to us and marshals it into |
|
104
|
|
|
|
|
|
|
a form suitable for sticking it in the database. This could be anything |
|
105
|
|
|
|
|
|
|
from flattening a L object into an ISO date to making sure |
|
106
|
|
|
|
|
|
|
that data is utf8 clean. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
|
109
|
|
|
|
|
|
|
|
|
110
|
1
|
|
|
1
|
1
|
4
|
sub encode { |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 decode |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
C takes data that the database is handing back to us and gets |
|
117
|
|
|
|
|
|
|
it into a form that's OK to hand back to the user. This could be |
|
118
|
|
|
|
|
|
|
anything from inflating an ISO date to a L object to |
|
119
|
|
|
|
|
|
|
making sure that the string properly has the utf8 flag. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
|
122
|
|
|
|
|
|
|
|
|
123
|
216
|
|
|
216
|
1
|
4157
|
sub decode { |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L, L, L, L, L, L, L, L, L |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 LICENSE |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Jifty::DBI is Copyright 2005-2007 Best Practical Solutions, LLC. |
|
134
|
|
|
|
|
|
|
Jifty::DBI is distributed under the same terms as Perl itself. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |