diff --git a/lib/NGCP/Template.pm b/lib/NGCP/Template.pm index b5c2a199..ed170418 100644 --- a/lib/NGCP/Template.pm +++ b/lib/NGCP/Template.pm @@ -25,6 +25,7 @@ sub new ABSOLUTE => 1, RELATIVE => 1, EVAL_PERL => 1, + PLUGIN_BASE => 'NGCP::Template::Plugin', %{$config}, }); diff --git a/lib/NGCP/Template/Plugin/Utils.pm b/lib/NGCP/Template/Plugin/Utils.pm new file mode 100644 index 00000000..e175165f --- /dev/null +++ b/lib/NGCP/Template/Plugin/Utils.pm @@ -0,0 +1,73 @@ +package NGCP::Template::Plugin::Utils 1.000; + +use strict; +use warnings; + +use parent qw(Template::Plugin); + +use MIME::Base64 (); + +sub new { + my ($class, $context, @params) = @_; + + bless { + _CONTEXT => $context, + }, $class; +} + +sub encode_base64 { + my ($self, @params) = @_; + return MIME::Base64::encode($params[0], ''); +} + +1; + +__END__ + +=encoding UTF-8 + +=head1 NAME + +NGCP::Template::Plugin::Utils - Utils plugin + +=head1 VERSION + +Version 1.000 + +=head1 DESCRIPTION + +This module provides common, stateless utility methods for NGCP templates +using Template::Plugin mechanism. + +[% USE Utils %] + +=head1 METHODS + +=over 8 + +=item [% encoded = Utils.encode_base64(unencoded) %] + +Converts give input String to base64. + +=back + +=head1 AUTHOR + +Rene Krenn, C<< >> + +=head1 LICENSE + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. +. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +. +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +=cut