From f2034447758e4eb1e5bfcb075a2e53fbadd8c9a9 Mon Sep 17 00:00:00 2001 From: Nigel Kukard <nkukard@lbsd.net> Date: Sun, 1 Mar 2009 11:52:01 +0000 Subject: [PATCH] * Added utility library with a template replacer function --- smradius/util.pm | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 smradius/util.pm diff --git a/smradius/util.pm b/smradius/util.pm new file mode 100644 index 00000000..b91a0efa --- /dev/null +++ b/smradius/util.pm @@ -0,0 +1,65 @@ +# SMRadius Utility Functions +# Copyright (C) 2008-2009, AllWorldIT +# +# 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 2 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +## @class smradius::util +# Utility functions +package smradius::util; + +use strict; +use warnings; + +# Exporter stuff +require Exporter; +our (@ISA,@EXPORT); +@ISA = qw(Exporter); +@EXPORT = qw( + templateReplace +); + + + +## @fn templateReplace($string,$hashref) +# Template string replacer function +# +# @param string String to replace template items in +# @param hashref Hashref containing the hash of tempalte items & values +# +# @return String with replaced items +sub templateReplace +{ + my ($string,$hashref) = @_; + + + # Loop with hash sections + foreach my $section (keys %{$hashref}) { + # Loop with section items + foreach my $item (keys %{$hashref->{$section}}) { + # Grab value + my $itemVal = $hashref->{$section}->{$item}; + # Replace in string + $string =~ s/\%{$section\.$item}/$itemVal/gi; + } + } + + return $string; +} + + + +1; +# vim: ts=4 -- GitLab