Asterisk::config - the Asterisk config read and write module.
use Asterisk::config; my $sip_conf = new Asterisk::config(file=>'/etc/asterisk/sip.conf'); my $conference = new Asterisk::config(file=>'/etc/asterisk/meetme.conf', keep_resource_array=>0); $allow = $sip_conf->fetch_values_arrayref(section=>'general',key=>'allow'); print $allow->[0]; $sip_conf->assign_append(point=>'down',data=>"[userb]\ntype=friend\n"); $sip_conf->save();
Asterisk::config can parse and saving data with Asterisk config files. this module support asterisk 1.0 1.2 1.4 1.6, and it also support Zaptel config files.
Version 0.9 syntax incompitable with 0.8.
$sip_conf = new Asterisk::config(file=>'file name', [stream_data=>$string], [object variable]);
Instantiates a new object of file. Reads data from stream_data or file.
FIXME: should all of those be documented in the POD (rather than in comments in the code?)
Config file name and path. Must be set. If file does exists (exp. data from stream_data), you will not be able to save using save_file.
stream_data
use resource array when save make fast than open file, but need more memory, default enabled. use set_objvar to change it.
When save done, auto call .
Enabled by default. Use set_variable to change it.
FIXME: what is set_variable?
set_variable
When reload done, auto clean_assign with current object.
Enabled by default. Use set_objvar to change it.
Internal variable listed all command.
Internal variable of parsed.
$sip_conf->get_objvar(var_name);
Return defined object variables.
$sip_conf->fetch_sections_list();
List of sections (not including unsection) in a file.
unsection
$sip_conf->fetch_sections_hashref();
Returns the config file parsed as a hash (section name -> section) of lists (list of lines).
$sip_conf->fetch_keys_list(section=>[section name|unsection]);
Returns list of the kes in the keys in section name (or unsection).
$sip_conf->fetch_keys_hashref(section=>[section name|unsection]);
Returns the section as a hash of key=>value pairs.
$sip_conf->fetch_values_arrayref(section=>[section name|unsection], key=>key name);
Returns a (reference to a) list of all the values a specific keys have in a specific section. referenced value list, Returns 0 if section was not found or key was not found in the section.
$sip_conf->reload();
Reloads and parses the config file.
If clean_when_reload is true, will also do clean_assign.
$sip_conf->set_objvar('var_name'=>'value');
Set the object variables to new value.
$sip_conf->assign_cleanfile();
Resets all the non-saved changes (from other assign_* functions).
$sip_conf->assign_matchreplace(match=>[string],replace=>[string]);
replace new data when matched.
match -> string of matched data.
replace -> new data string.
Used to add extra data to an existing section or to edit it.
$sip_conf->assign_append(point=>['up'|'down'|'foot'], section=>[section name], data=>'key=value'|['key=value','key=value']|{key=>'value',key=>'value'});
This form is used to merely append new data.
Append data up / down / foot with section.
up
down
foot
Matched section name, expect 'unsection'. If ommited, data will be placed above first setcion, as in 'unsection', but then you cannot use point="foot">.
point=
New replace data in string/array/hash.
$sip_conf->assign_append(point=>['up'|'down'|'over'], section=>[section name], comkey=>[key,value], data=>'key=value'|['key=value','key=value']|{key=>'value',key=>'value'};
Appends data before, after or instead a given line. The line is the first line in section where the key is key and the value is value (from comkey.
section
key
value
comkey
over will overwrite with key/value matched.
over
Match key and value.
$sip_conf->assign_replacesection(section=>[section name|unsection], data=>'key=value'|['key=value','key=value']|{key=>'value',key=>'value'});
replace the section body data.
section -> all section name and 'unsection'.
$sip_conf->assign_delsection(section=>[section name|unsection]);
erase section name and section data.
section -> all section and 'unsection'.
$sip_conf->assign_addsection(section=>[section]);
add section with name.
section -> name of new section.
$sip_conf->assign_editkey(section=>[section name|unsection],key=>[keyname],value=>[value],new_value=>[new_value]);
modify value with matched section.if don't assign value=> will replace all matched key.
warnning example script:
$sip_conf->assign_editkey(section=>'990001',key=>'all',new_value=>'gsm');
data:
all=g711 all=ilbc
will convert to:
all=gsm all=gsm
$sip_conf->assign_delkey(section=>[section name|unsection],key=>[keyname],value=>[value]);
erase all matched keyname in section or in 'unsection'.
keyname
$sip_conf->assign_delkey(section=>[section name|unsection],key=>[keyname],value_regexp=>[exten_number]);
erase when matched exten number.
exten => 100,n,... exten => 102,n,...
$sip_conf->save_file([new_file=>'filename']);
process commit list and save to file. if reload_when_save true will do reload. if no object variable file or file not exists or can't be save return failed. if defined new_file will save to new file, default overwrite objvar 'file'.
$sip_conf->clean_assign();
clean all assign rules.
see example in source tree.
Asterisk::config by Sun bing <hoowa.sun@gmail.com>
Version 0.7 patch by Liu Hailong.
The Asterisk::config module is Copyright (c) Sun bing <hoowa.sun@gmail.com> All rights reserved.
You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
The Asterisk::config is free Open Source software.
IT COMES WITHOUT WARRANTY OF ANY KIND.
Sun bing <hoowa.sun@gmail.com>
The Asterisk::config be Part of FreeIris opensource Telephony Project Access http://www.freeiris.org for more details.
To install Asterisk::config, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Asterisk::config
CPAN shell
perl -MCPAN -e shell install Asterisk::config
For more information on module installation, please visit the detailed CPAN module installation guide.