Asterisk cmd Perl

res_perl


Asterisk — A telephony toolkit for Linux.
res_perl — A Module To Incorporate Perl Into Asterisk.

Copyright (C) 2005, Anthony Minessale
Anthony Minessale <anthmct@yahoo.com>


res_perl does not appear to be available anymore. The last known link is to a website that has since expired.


DESCRIPTION:

This is res_perl the "mod_perl" of sorts for Asterisk. res_perl uses Perl embedding to allow a Perl
environment to be created inside a runnning Asterisk. An Asterisk-specific perl module AstAPI.pm is loaded in
this environment so when Perl code is executing, it has full access to a large asterisk API layer.

IMPORTANT NOTE:

As of this version you need to have perl compiled with usethreads and useithreads
For a quick build of perl from src use 'make perl' *NOTE* ***this will erase your current perl***

FEATURES:

res_perl can execute perl code from extensions.conf in a special package called Asterisk::Embed
that is loaded on startup from /usr/local/res_perl/modules/asterisk_init.pm the first arguement to the
Perl app is the name of a subroutine from this Asterisk::Embed package followed by a : seperated list
of optional parameters.

EX: exten => 1,1,Perl(myfunc:arg_1:arg_2:arg_n......)

  • NOTE* When you execute the Perl() app your Perl Environment will be cloned for that execution.
Any changes you make to the environment during the execution will be discarded when the execution ends.
This is a limitation of embeded thread support in Perl.

If you change asterisk_init.pm you need to enter the cli command "perl labotomy" to read the changes.
(*NOTE* labotomy not recommended in production!)

There is also a module called LoadFile that allows you to store your perl apps
in a seperate file and load them into memory without restarting. Files are loaded from
/usr/local/res_perl/apps automaticly.

EX: exten => 1,1,Perl(Loadfile:demo.pl:arg_1:arg_2:arg_n....)

If you alter the file demo.pl it will then the next execution will load it from disk instead of memory.
To re-cache just send the cli command "perl call LoadFileCacheAll". See /usr/local/res_perl/apps/demo.pl

Inside these functions you have access to several perlified api commands starting with asterisk_
see /usr/local/res_perl/modules/asterisk_init.pm for a few examples
(see AstAPIBase.c for the C defs they are all valid from perl once you are up and running.)


SPECIAL RETURN VALUES:

There are also *some* special return commands: (1 for now)

thread:<function>

This will spin off a thread with the perl sub you specify running inside it.
the sub will get 1 scalar arg being the number of times it was run (starting with 1)

STARTUP:

The function startup() is called from asterisk_init.pm when the module is loaded.


FUNCTIONS:

res_perl also registers the PERL function to the dialplan. Unlike the Perl() app the PERL function
executes in the Main environment and therefore can be used to make permenant changes to the environment.
A lock is held during the execution of the PERL function so a prolonged set of instructions is not advised.

The PERL function takes it's arguements the same way as the Perl() application does.
EX: exten => 1,1,Dial(${PERL(LoadFile:find_dest:${EXTENSION})})


CONFIG:

res_perl has hooks into both the asterisk runtime loadable configuration engine (res_config) and realtime.
There is a module called AstConfig.pm that lets you create, load and save files in the asterisk config format.
AstConfig.pm has a special method return_data() that returns a special Perl-to-Asterisk version of the config
object that can be passed to Asterisk. (See sub perl_config() in /usr/local/res_perl/modules/asterisk_init.pm)


SWITCH:

res_perl exposes the Asterisk Switch API to a Perl equivilant set of calls making it possible to create your
own dialplan switch with Perl code. See sub perl_switch_register in /usr/local/res_perl/modules/asterisk_init.pm

CDR:

res_perl exposes a hook to the Asterisk CDR handler. sub perl_log is called which will be called with a hash of all the
cdr info as it's arguement. Also, the special HASHES %CHAN_VARS and %CDR_VARS will already exist in the fashion of %ENV



Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ

res_perl


Asterisk — A telephony toolkit for Linux.
res_perl — A Module To Incorporate Perl Into Asterisk.

Copyright (C) 2005, Anthony Minessale
Anthony Minessale <anthmct@yahoo.com>


res_perl does not appear to be available anymore. The last known link is to a website that has since expired.


DESCRIPTION:

This is res_perl the "mod_perl" of sorts for Asterisk. res_perl uses Perl embedding to allow a Perl
environment to be created inside a runnning Asterisk. An Asterisk-specific perl module AstAPI.pm is loaded in
this environment so when Perl code is executing, it has full access to a large asterisk API layer.

IMPORTANT NOTE:

As of this version you need to have perl compiled with usethreads and useithreads
For a quick build of perl from src use 'make perl' *NOTE* ***this will erase your current perl***

FEATURES:

res_perl can execute perl code from extensions.conf in a special package called Asterisk::Embed
that is loaded on startup from /usr/local/res_perl/modules/asterisk_init.pm the first arguement to the
Perl app is the name of a subroutine from this Asterisk::Embed package followed by a : seperated list
of optional parameters.

EX: exten => 1,1,Perl(myfunc:arg_1:arg_2:arg_n......)

  • NOTE* When you execute the Perl() app your Perl Environment will be cloned for that execution.
Any changes you make to the environment during the execution will be discarded when the execution ends.
This is a limitation of embeded thread support in Perl.

If you change asterisk_init.pm you need to enter the cli command "perl labotomy" to read the changes.
(*NOTE* labotomy not recommended in production!)

There is also a module called LoadFile that allows you to store your perl apps
in a seperate file and load them into memory without restarting. Files are loaded from
/usr/local/res_perl/apps automaticly.

EX: exten => 1,1,Perl(Loadfile:demo.pl:arg_1:arg_2:arg_n....)

If you alter the file demo.pl it will then the next execution will load it from disk instead of memory.
To re-cache just send the cli command "perl call LoadFileCacheAll". See /usr/local/res_perl/apps/demo.pl

Inside these functions you have access to several perlified api commands starting with asterisk_
see /usr/local/res_perl/modules/asterisk_init.pm for a few examples
(see AstAPIBase.c for the C defs they are all valid from perl once you are up and running.)


SPECIAL RETURN VALUES:

There are also *some* special return commands: (1 for now)

thread:<function>

This will spin off a thread with the perl sub you specify running inside it.
the sub will get 1 scalar arg being the number of times it was run (starting with 1)

STARTUP:

The function startup() is called from asterisk_init.pm when the module is loaded.


FUNCTIONS:

res_perl also registers the PERL function to the dialplan. Unlike the Perl() app the PERL function
executes in the Main environment and therefore can be used to make permenant changes to the environment.
A lock is held during the execution of the PERL function so a prolonged set of instructions is not advised.

The PERL function takes it's arguements the same way as the Perl() application does.
EX: exten => 1,1,Dial(${PERL(LoadFile:find_dest:${EXTENSION})})


CONFIG:

res_perl has hooks into both the asterisk runtime loadable configuration engine (res_config) and realtime.
There is a module called AstConfig.pm that lets you create, load and save files in the asterisk config format.
AstConfig.pm has a special method return_data() that returns a special Perl-to-Asterisk version of the config
object that can be passed to Asterisk. (See sub perl_config() in /usr/local/res_perl/modules/asterisk_init.pm)


SWITCH:

res_perl exposes the Asterisk Switch API to a Perl equivilant set of calls making it possible to create your
own dialplan switch with Perl code. See sub perl_switch_register in /usr/local/res_perl/modules/asterisk_init.pm

CDR:

res_perl exposes a hook to the Asterisk CDR handler. sub perl_log is called which will be called with a hash of all the
cdr info as it's arguement. Also, the special HASHES %CHAN_VARS and %CDR_VARS will already exist in the fashion of %ENV



Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ

Created by: JustRumours, Last modification: Mon 04 of Jun, 2012 (18:05 UTC) by Corydon76
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+