孙冰 > Asterisk-config-0.95 > Asterisk::config

Download:
Asterisk-config-0.95.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Module Version: 0.95   Source   Latest Release: Asterisk-config-0.97

NAME ^

Asterisk::config - the Asterisk config read and write module.

SYNOPSIS ^

    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();

DESCRIPTION ^

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.

Note ^

Version 0.9 syntax incompitable with 0.8.

CLASS METHOD ^

new

    $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.

OBJECT VARIABLE ^

file

config file name and path. if file no exists (exp. data from stream_data ) you can't saving by save_file.

keep_resource_array

use resource array when save make fast than open file, but need more memory, default enabled. use set_objvar to change it.

reload_when_save

when save done, auto call .

default enable. use set_variable to change it.

clean_when_reload

when reload done, auto clean_assign with current object. default enable. use set_objvar to change it.

commit_list

internal variable listed all command. i suggest don't modify and change this variable.

parsed_conf

internal variable of parsed. i suggest don't modify and change this variable.

OBJECT READ METHOD ^

get_objvar

    $sip_conf->get_objvar(var_name);

return defined object variables.

fetch_sections_list

    $sip_conf->fetch_sections_list();

only return sections name list. does not include 'unsection'.

fetch_sections_hashref

    $sip_conf->fetch_sections_hashref();

this function return parsed config files data.

fetch_keys_list

    $sip_conf->fetch_keys_list(section=>[section name|unsection]);

return keys list of section name or unsection.

fetch_keys_hashref

    $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.

fetch_values_arrayref

    $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.

reload

    $sip_conf->reload();

reload and parse config file. if clean_when_reload true will do clean_assign.

OBJECT WRITE METHOD ^

set_objvar

    $sip_conf->set_objvar('var_name'=>'value');

set the object variables to new value.

assign_cleanfile

    $sip_conf->assign_cleanfile();

assign clean all to file.

assign_matchreplace

    $sip_conf->assign_matchreplace(match=>[string],replace=>[string]);

replace new data when matched.

assign_append

    $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.

    $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.

    $sip_conf->assign_append(point=>'up'|'down',
                             data=>'key=value'|['key=value','key=value']|{key=>'value',key=>'value'});

simple append data without any section.

assign_replacesection

    $sip_conf->assign_replacesection(section=>[section name|unsection],
                             data=>'key=value'|['key=value','key=value']|{key=>'value',key=>'value'});

replace the section body data.

assign_delsection

    $sip_conf->assign_delsection(section=>[section name|unsection]);

erase section name and section data.

assign_addsection

    $sip_conf->assign_addsection(section=>[section]);

add section with name.

assign_editkey

    $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

assign_delkey

    $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,...

save_file

    $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'.

clean_assign

    $sip_conf->clean_assign();

clean all assign rules.

EXAMPLES ^

see example in source tree.

AUTHORS ^

Asterisk::config by Sun bing <hoowa.sun@gmail.com>

Version 0.7 patch by Liu Hailong.

COPYRIGHT ^

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.

WARRANTY ^

The Asterisk::config is free Open Source software.

IT COMES WITHOUT WARRANTY OF ANY KIND.

SUPPORT ^

Sun bing <hoowa.sun@gmail.com>

The Asterisk::config be Part of FreeIris opensource Telephony Project Access http://www.freeiris.org for more details.