| 1 | package Jifty::DBI::Filter::base64; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | |||
| 6 | use base qw|Jifty::DBI::Filter|; | ||
| 7 | use MIME::Base64 (); | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | Jifty::DBI::Filter::base64 - Encodes data as base64 | ||
| 12 | |||
| 13 | =head1 DESCRIPTION | ||
| 14 | |||
| 15 | This filter allow you to store arbitrary data in a column of type | ||
| 16 | 'text'. | ||
| 17 | |||
| 18 | =head2 encode | ||
| 19 | |||
| 20 | If value is defined, then encodes it using | ||
| 21 | L<MIME::Base64/encode_base64>. Does nothing if value is not defined. | ||
| 22 | |||
| 23 | =cut | ||
| 24 | |||
| 25 | sub encode { | ||
| 26 | my $self = shift; | ||
| 27 | |||
| 28 | my $value_ref = $self->value_ref; | ||
| 29 | return unless defined $$value_ref; | ||
| 30 | |||
| 31 | $$value_ref = MIME::Base64::encode_base64($$value_ref); | ||
| 32 | |||
| 33 | return 1; | ||
| 34 | } | ||
| 35 | |||
| 36 | =head2 decode | ||
| 37 | |||
| 38 | If value is defined, then decodes it using | ||
| 39 | L<MIME::Base64/decode_base64>, otherwise do nothing. | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | sub decode { | ||
| 44 | my $self = shift; | ||
| 45 | |||
| 46 | my $value_ref = $self->value_ref; | ||
| 47 | return unless defined $$value_ref; | ||
| 48 | |||
| 49 | $$value_ref = MIME::Base64::decode_base64($$value_ref); | ||
| 50 | } | ||
| 51 | |||
| 52 | =head1 SEE ALSO | ||
| 53 | |||
| 54 | L<Jifty::DBI::Filter>, L<MIME::Base64> | ||
| 55 | |||
| 56 | =cut | ||
| 57 | |||
| 58 | 1; |