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 Web サイトには少し間違いがあります (少なくともバージョン 0.2.8 では)。

于 2012-09-15T18:56:56.110 に答える