#!/usr/bin/perl -w
use strict;
use Asterisk::AGI;
use Asterisk::Outgoing;

$SIG{HUP} = "IGNORE";

#sub verbose($$) {
#    my $agi = shift;
#    my $str = shift;
#    $agi->exec( 'Verbose', $str );
#}

my $agi   = new Asterisk::AGI;
my %input = $agi->ReadParse();

my $from       = $input{arg_1};
my $to_context = $input{arg_2};

my $callerid = $input{callerid};

my $out = new Asterisk::Outgoing();

$out->setvariable( 'Channel',   $from );
$out->setvariable( 'Context',   $to_context );
$out->setvariable( 'Extension', $callerid );
$out->setvariable( 'Priority',  '1' );
$out->setvariable( 'Archive',   'yes' );
$out->create_outgoing();

#foreach my $k ( sort keys %input ) {
#    $agi->exec( 'Verbose', "$k=" . $input{$k} );
#}
#verbose( $agi, "Callerid: '$callerid'" );

$agi->exec("Hangup");
