TT#74153 add Utils methods

Utils.get_ref, Utils.to_perl, Utils.to_config_general

Change-Id: I8d435cdfa7b50e822c958efbbfd071bfef45741e
changes/12/36912/7
Rene Krenn 6 years ago
parent 0e35daa212
commit 1ea1824397

4
debian/control vendored

@ -10,6 +10,7 @@ Build-Depends:
git,
libcapture-tiny-perl,
libclone-perl,
libconfig-general-perl,
libconfig-tiny-perl,
libdata-validate-ip-perl,
libdbd-mysql-perl,
@ -17,6 +18,7 @@ Build-Depends:
libhash-merge-perl,
libio-interface-perl,
libipc-system-simple-perl,
libmime-base64-perl,
libnet-netmask-perl,
libreadonly-perl,
libregexp-ipv6-perl,
@ -51,6 +53,7 @@ Depends:
git (>= 1:1.7.2.5-3~),
libcapture-tiny-perl,
libclone-perl,
libconfig-general-perl,
libconfig-tiny-perl,
libdata-validate-ip-perl,
libdbd-mysql-perl,
@ -58,6 +61,7 @@ Depends:
libhash-merge-perl,
libio-interface-perl,
libipc-system-simple-perl,
libmime-base64-perl,
libnet-netmask-perl,
libngcp-template-perl,
libregexp-ipv6-perl,

@ -6,6 +6,8 @@ use warnings;
use parent qw(Template::Plugin);
use MIME::Base64 ();
use Data::Dumper ();
use Config::General ();
sub new {
my ($class, $context, @params) = @_;
@ -20,6 +22,22 @@ sub encode_base64 {
return MIME::Base64::encode($params[0], '');
}
sub to_perl {
my ($self, @params) = @_;
return Data::Dumper::Dumper($params[0]);
}
sub to_config_general {
my ($self, @params) = @_;
my $conf = Config::General->new();
return $conf->save_string($params[0]);
}
sub get_ref {
my ($self, @params) = @_;
return ref $params[0];
}
1;
__END__
@ -47,7 +65,19 @@ using Template::Plugin mechanism.
=item [% encoded = Utils.encode_base64(unencoded) %]
Converts give input String to base64.
Converts the given input String to base64.
=item [% serialized = Utils.to_perl(object) %]
Serializes the given input object to string (perl syntax).
=item [% serialized = Utils.to_config_general(object) %]
Serializes the given input object to string (Config::General syntax).
=item [% Utils.get_ref(object) %]
Get the variable type.
=back

Loading…
Cancel
Save