
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. read data from stream_data or file.

config file name and path. if file no exists (exp. data from stream_data ) you can't saving by save_file.
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 .
default enable. use set_variable to change it.
when reload done, auto clean_assign with current object. default enable. use set_objvar to change it.
internal variable listed all command. i suggest don't modify and change this variable.
internal variable of parsed. i suggest don't modify and change this variable.

$sip_conf->get_objvar(var_name);
return defined object variables.
$sip_conf->fetch_sections_list();
only return sections name list. does not include 'unsection'.
$sip_conf->fetch_sections_hashref();
this function return parsed config files data.
$sip_conf->fetch_keys_list(section=>[section name|unsection]);
return keys list of section name or unsection.
$sip_conf->fetch_keys_hashref(section=>[section name|unsection]);
return referenced key list (and keys value), section value 'unsection' return all unsection keys, if section name unreachable return failed.
$sip_conf->fetch_values_arrayref(section=>[section name|unsection],
key=>key name);
return referenced value list, if section name unreachable return failed. if key name unreachable return failed.
$sip_conf->reload();
reload and parse config file. if clean_when_reload true will do clean_assign.

$sip_conf->set_objvar('var_name'=>'value');
set the object variables to new value.
$sip_conf->assign_cleanfile();
assign clean all to file.
$sip_conf->assign_matchreplace(match=>[string],replace=>[string]);
replace new data when matched.
$sip_conf->assign_append(point=>['up'|'down'|'foot'],
section=>[section name],
data=>'key=value'|['key=value','key=value']|{key=>'value',key=>'value'});
append data around with section name.
up / down / foot with section. $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'};
append data around with section name and key/value in same section.
over will overwrite with key/value matched. $sip_conf->assign_append(point=>'up'|'down',
data=>'key=value'|['key=value','key=value']|{key=>'value',key=>'value'});
simple append data without any section.
$sip_conf->assign_replacesection(section=>[section name|unsection],
data=>'key=value'|['key=value','key=value']|{key=>'value',key=>'value'});
replace the section body data.
$sip_conf->assign_delsection(section=>[section name|unsection]);
erase section name and section data.
$sip_conf->assign_addsection(section=>[section]);
add section with name.
$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'.
$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.