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
[EMAIL PROTECTED]
http://www.darrensessions.com
_____________________________


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

AstriCon 2008 - September 22 - 25 Phoenix, Arizona
Register Now: http://www.astricon.net

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Reply via email to