| 1 | package Jifty::DBI::Filter::Storable; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use base qw|Jifty::DBI::Filter|; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Storable (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | Jifty::DBI::Filter::Storable - Encodes arbitrary data using Storable | ||||||||||
| 12 | |||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||
| 14 | |||||||||||
| 15 | This filter allows you to store arbitrary Perl data structures in a | ||||||||||
| 16 | column of type 'blob', using L<Storable> to serialize them. | ||||||||||
| 17 | |||||||||||
| 18 | =head2 encode | ||||||||||
| 19 | |||||||||||
| 20 | If value is defined, then encodes it using L<Storable/nfreeze>. Does | ||||||||||
| 21 | nothing if value is not defined. | ||||||||||
| 22 | |||||||||||
| 23 | =cut | ||||||||||
| 24 | |||||||||||
| 25 | sub encode { | ||||||||||
| 26 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
encode: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 27 | |||||||||||
| 28 | 2 | my $value_ref = $self->value_ref; | |||||||||
| 29 | 2 | ▶ | return unless defined $$value_ref; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | |||||||||||
| 31 | 1 | $Storable::Deparse = 1; | |||||||||
| 32 | 1 | $$value_ref = Storable::nfreeze($value_ref); | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | =head2 decode | ||||||||||
| 36 | |||||||||||
| 37 | If value is defined, then decodes it using L<Storable/thaw>, otherwise | ||||||||||
| 38 | does nothing. | ||||||||||
| 39 | |||||||||||
| 40 | =cut | ||||||||||
| 41 | |||||||||||
| 42 | sub decode { | ||||||||||
| 43 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
decode: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 44 | |||||||||||
| 45 | 2 | my $value_ref = $self->value_ref; | |||||||||
| 46 | 2 | ▶ | return unless defined $$value_ref; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | # Storable doesn't take Unicode strings. | ||||||||||
| 49 | 1 | Encode::_utf8_off($$value_ref); | |||||||||
| 50 | |||||||||||
| 51 | 1 | local $@; | |||||||||
| 52 | 1 | $Storable::Eval = 1; | |||||||||
| 53 | 1 | $$value_ref = eval { ${ Storable::thaw($$value_ref) } }; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | =head1 SEE ALSO | ||||||||||
| 57 | |||||||||||
| 58 | L<Jifty::DBI::Filter>, L<Storable> | ||||||||||
| 59 | |||||||||||
| 60 | =cut | ||||||||||
| 61 | |||||||||||
| 62 | 1 | 1; | |||||||||