DBI/Filter.pm

filter: Statementstmt 94.1% 16 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 96.1% 25 / 26 CC 2 SCAR 2.6
CC
2
Cov
94%
new
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« DBI/Filter/Storable.pm ↑ Summary DBI.pm »
1 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Jifty::DBI::Filter;
5 28 ▶use base 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 28 __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<encode> works in place, massaging whatever value_ref
63 refers to.
64  
65 =item column
66  
67 A L<Jifty::DBI::Column> object, whatever sort of column we're working
68 with here.
69  
70 =item handle
71  
72 A L<Jifty::DBI::Handle> object, because some filters (i.e.
73 L<Jifty::DBI::Filter::Boolean>) depend on what database system is being used.
74  
75 =back
76  
77 =cut
78  
79 sub new {
80 819 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=7.0
Pod documented
81 819 my %args = (
82 column => undef,
83 value_ref => undef,
84 handle => undef,
85 @_
86 );
87 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 819 } );
93
94 819 for ( grep $self->can($_), keys %args ) {
95 0 $self->$_( $args{$_} );
96 }
97  
98 819 return ($self);
99 }
100  
101 =head2 encode
102  
103 C<encode> 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<DateTime> object into an ISO date to making sure
106 that data is utf8 clean.
107  
108 =cut
109  
110 ▶sub encode {
Subroutine encode: called CC=1 SCAR=0.0
Pod documented
111  
112 }
113  
114 =head2 decode
115  
116 C<decode> 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<DateTime> object to
119 making sure that the string properly has the utf8 flag.
120  
121 =cut
122  
123 ▶sub decode {
Subroutine decode: called CC=1 SCAR=0.0
Pod documented
124  
125 }
126  
127 =head1 SEE ALSO
128  
129 L<Jifty::DBI::Filter::Date>, L<Jifty::DBI::Filter::DateTime>, L<Jifty::DBI::Filter:SaltHash>, L<Jifty::DBI::Filter::Storable>, L<Jifty::DBI::Filter::Time>, L<Jifty::DBI::Filter::Truncate>, L<Jifty::DBI::Filter::YAML>, L<Jifty::DBI::Filter::base64>, L<Jifty::DBI::Filter::utf8>
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 28 1;
« DBI/Filter/Storable.pm ↑ Summary DBI.pm »