X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/15fa34d9610c4fb162779285473a197fffb73659..9cddaf376822b4229457212a27d5d98958f11368:/SL/Template/Plugin/Base64.pm diff --git a/SL/Template/Plugin/Base64.pm b/SL/Template/Plugin/Base64.pm new file mode 100644 index 000000000..897a49a0a --- /dev/null +++ b/SL/Template/Plugin/Base64.pm @@ -0,0 +1,78 @@ +package SL::Template::Plugin::Base64; + +use strict; +use vars qw($VERSION); + +$VERSION = 0.01; + +use base qw(Template::Plugin); +use Template::Plugin; +use Template::Stash; +use MIME::Base64 (); + +$Template::Stash::SCALAR_OPS->{'encode_base64'} = \&_encode_base64; +$Template::Stash::SCALAR_OPS->{'decode_base64'} = \&_decode_base64; + +sub new { + my ($class, $context, $options) = @_; + + $context->define_filter('encode_base64', \&_encode_base64); + $context->define_filter('decode_base64', \&_decode_base64); + return bless {}, $class; +} + +sub _encode_base64 { + return MIME::Base64::encode_base64(shift, ''); +} + +sub _decode_base64 { + my ($self, $var) = @_; + return MIME::Base64::decode_base64(shift); +} + +1; + +__END__ + +=head1 NAME + +SL::Template::Plugin::Base64 - TT2 interface to base64 encoding/decoding + +=head1 SYNOPSIS + + [% USE Base64 -%] + [% SELF.some_object.binary_stuff.encode_base64 -%] + [% SELF.some_object.binary_stuff FILTER encode_base64 -%] + +=head1 DESCRIPTION + +The I Template Toolkit plugin provides access to the Base64 +routines from L. + +The following filters (and vmethods of the same name) are installed +into the current context: + +=over 4 + +=item C + +Returns the string encoded as Base64. + +=item C + +Returns the Base64 string decoded back to binary. + +=back + +As the filters are also available as vmethods the following are all +equivalent: + + FILTER encode_base64; content; END; + content FILTER encode_base64; + content.encode_base64; + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.de + +=cut