0

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

并且工作正常

4

2 回答 2

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
);
于 2012-07-30T16:37:15.393 回答
2

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

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

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

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

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

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

于 2012-09-15T18:56:56.110 回答