Question

i'm trying to use the Asterisk::AMI package but with a simple example dont works

#!/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'};

Alway i get an error :

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

EDIT

the documentation see wrong, i've try

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

and works fine

Was it helpful?

Solution

The documentation for Asterisk::AMI is wrong. You should write

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

which is equivalent to

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

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

By default there is no timeout on actions. To specify a default timeout for all actions, create your AMI object using, for example

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

OTHER TIPS

You have the astman. If you do this:

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

You are passing parameters to an object.

You should pass parameters to a method, for example:

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

The Perl Documentation is fine. The CPAN web site for Asterisk::AMI has a little mistake (at least in version 0.2.8).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top