Pflichtenhefte: Unterstützung für an Textblöcke angehängte Bilder
[kivitendo-erp.git] / SL / Template / Plugin / Base64.pm
1 package SL::Template::Plugin::Base64;
2
3 use strict;
4 use vars qw($VERSION);
5
6 $VERSION = 0.01;
7
8 use base qw(Template::Plugin);
9 use Template::Plugin;
10 use Template::Stash;
11 use MIME::Base64 ();
12
13 $Template::Stash::SCALAR_OPS->{'encode_base64'} = \&_encode_base64;
14 $Template::Stash::SCALAR_OPS->{'decode_base64'} = \&_decode_base64;
15
16 sub new {
17   my ($class, $context, $options) = @_;
18
19   $context->define_filter('encode_base64', \&_encode_base64);
20   $context->define_filter('decode_base64', \&_decode_base64);
21   return bless {}, $class;
22 }
23
24 sub _encode_base64 {
25   return MIME::Base64::encode_base64(shift, '');
26 }
27
28 sub _decode_base64 {
29   my ($self, $var) = @_;
30   return MIME::Base64::decode_base64(shift);
31 }
32
33 1;
34
35 __END__
36
37 =head1 NAME
38
39 SL::Template::Plugin::Base64 - TT2 interface to base64 encoding/decoding
40
41 =head1 SYNOPSIS
42
43   [% USE Base64 -%]
44   [% SELF.some_object.binary_stuff.encode_base64 -%]
45   [% SELF.some_object.binary_stuff FILTER encode_base64 -%]
46
47 =head1 DESCRIPTION
48
49 The I<Base64> Template Toolkit plugin provides access to the Base64
50 routines from L<MIME::Base64>.
51
52 The following filters (and vmethods of the same name) are installed
53 into the current context:
54
55 =over 4
56
57 =item C<encode_base64>
58
59 Returns the string encoded as Base64.
60
61 =item C<decode_base64>
62
63 Returns the Base64 string decoded back to binary.
64
65 =back
66
67 As the filters are also available as vmethods the following are all
68 equivalent:
69
70     FILTER encode_base64; content; END;
71     content FILTER encode_base64;
72     content.encode_base64;
73
74 =head1 AUTHOR
75
76 Moritz Bunkus E<lt>m.bunkus@linet-services.de<gt>
77
78 =cut