上的Asterisk::AMI出现致命错误



我正在尝试使用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'
});

并且工作良好

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

您拥有astman。如果你这样做:

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

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

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

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

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

最新更新