使用Asterisk :: AMI时出现致命错误

时间:2012-07-30 16:21:14

标签: perl asteriskami

我正在尝试使用Asterisk :: AMI软件包,但有一个简单的例子不能正常工作

#!/usr/bin/perl -w
# ami_test.pl

use strict;
use diagnostics;
use Asterisk::AMI;

// use default 127.0.0.1 5038
my $astman = Asterisk::AMI->new(
    Username => 'manager',
    Secret => 'secret'
);

die "Unable to connect to Asterisk" unless ($astman);

my $response = $astman->({
    Action => 'Command',
    Command => 'sip show peers'
});


print $response->{'Response'};

总是我得到一个错误:

Not a CODE reference at ami_test.pl line 17 (#1)
    (F) Perl was trying to evaluate a reference to a code value (that is, a
    subroutine), but found a reference to something else instead.  You can
    use the ref() function to find out what kind of ref it really was.  See
    also perlref.

Uncaught exception from user code:
        Not a CODE reference at ami_test.pl line 17.
 at ami_test.pl line 17

修改

文档看错了,我试试

my $response = $astman->action({
    Action => 'Command',
    Command => 'sip show peers'
});

并且工作正常

2 个答案:

答案 0 :(得分:2)

Asterisk::AMI的文档错误。你应该写

my $response = $astman->action({
    Action => 'Command',
    Command => 'sip show peers'
});

相当于

my $action = $astman->send_action({
    Action => 'Command',
    Command => 'sip show peers'
});

my $response = $astman->get_response($action);

默认情况下,操作没有超时。要为所有操作指定默认超时,请使用例如

创建AMI对象
my $astman = Asterisk::AMI->new(
    Username => 'manager',
    Secret => 'secret',
    Timeout => 10
);

答案 1 :(得分:2)

你有阿斯特曼。如果你这样做:

$astman->({ Action => 'Ping' }, \&actioncb);

您正在将参数传递给对象。

您应该将参数传递给方法,例如:

my $action = $astman->send_action({ Action => 'Ping' }, \&actioncb);

Perl文档很好。 Asterisk::AMI的CPAN网站有一点错误(至少在0.2.8版本中)。