mirror of https://github.com/sipwise/ngcpcfg.git
The perl Template::Toolkit is very rich, but its "function" support is a bit poor. The ways to do it are either via MACRO directives, or by simulating them with one function per file and then using PROCESS on these. The problem is that this is very clunky, does not support nesting, as we'd need different "argument" names for each "function", and it's quite cumbersome to use, need to assign aguments passed beforehand, and then assign back a designated return value from another variable. This is also one of the reasons some of the functions are not encapsulated, and have been inlined in various loops, because it was not possible to cleanly PROCESS them from those call sites. Instead we should use its native support for perl objects and perl subroutines, which exposes these as proper methods of a designated variable, and have none of the above mentioned problems. So we'll switch from constructs such as: argv.arg-a = variable; argv.arg-b = 'value'; PROCESS 'path-to-library-dir/function' result = out into: result = ngcp.function(variable, 'value'); In addition this might actually be faster, as it does not require processing additional files, and it's all just native perl code. This will be exposed within the NGCP templates as the ngcp object, and new member functions will start replacing our old and clunky native Template PROCESS-style library. Change-Id: Id2f0d181c695a9dd074646881b7d9de3478570afchanges/75/21875/4
parent
acb6ea8682
commit
696ac4c247
@ -0,0 +1,59 @@
|
||||
package NGCP::Template 1.000;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use List::Util qw(any);
|
||||
|
||||
sub new
|
||||
{
|
||||
my ($this, $config) = @_;
|
||||
my $class = ref $this || $this;
|
||||
|
||||
my $self = {
|
||||
config => $config,
|
||||
};
|
||||
|
||||
return bless $self, $class;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=encoding UTF-8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
NGCP::Template - NGCP module for the Template::Tolkit framework
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
Version 1.000
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module provides the methods for the ngcp object that can be used within
|
||||
the NGCP templates. This makes it easier to use instead of the old library
|
||||
of code executed via the C<PROCESS> directive.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Guillem Jover, C<< <gjover@sipwise.com> >>
|
||||
|
||||
=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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
=cut
|
||||
Loading…
Reference in new issue