[asterisk-users] Asterisk Tips and Tricks: Dynamic Subroutines in AGI
Darren Sessions
dmsessions at gmail.com
Thu Aug 28 21:12:21 CDT 2008
When I set out to develop a basic service provider Perl AGI framework
for Asterisk three or four years ago, I wanted to design something
that would make developing additional Perl AGI apps under this
framework scalable and easy to do. One of the features I wanted to
have in this framework was the ability to do a database dip on a
particular incoming called number to see which service I needed to
execute and then to dynamically execute that subroutine from the
database servers results. I could switch services or point the number
to a canceled operator message by simply doing an update to that
telephone number’s record in the database - instantly re-provisioning
the telephone number.
The hurdle in doing something like this was how to dynamically execute
a subroutine from the results of the database query which were dumped
into a variable. The method I used with the subroutine reference
doesn’t allow for arguments to be passed (if anyone finds / knows a
way to do this, let me know), so I use global variables.
This is a simple example of dynamic subroutine execution (without the
database query):
use strict;
use warnings;
our $called_number;
our $calling_number;
sub run_me {
$AGI->verbose(”Called Number = “.$called_number, 1);
$AGI->verbose(”Calling Number = “.$calling_number, 1);
}
sub set_variables {
$called_number = “8005551212″;
$calling_number = “3002221111″;
}
sub dynamic_execute {
my ($sub) = @_;
if (!$sub) {
$AGI->verbose(”No subroutine name passed!!”, 1);
return(-1);
}
my $exec = \&{$sub};
return($exec->());
}
set_variables();
dynamic_execute(”run_me”);
_____________________________
Darren Sessions
dmsessions at gmail.com
http://www.darrensessions.com
_____________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2423 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-users/attachments/20080828/2c92cc06/attachment.bin
More information about the asterisk-users
mailing list