Sorta passes the basic tests I have in place.

git-svn-id: svn://192.168.202.10@315 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
jaywhy
2006-09-28 23:00:40 +00:00
parent 195b702872
commit 87a0e7ec93
10 changed files with 111 additions and 39 deletions
+16 -8
View File
@@ -1,12 +1,20 @@
use inc::Module::Install 0.64;
use inc::Module::Install 0.46;
name 'Astguiclient';
all_from 'lib/Astguiclient.pm';
name('Astguiclient');
license('gpl');
perl_version('5.008');
version_from('lib/Astguiclient.pm');
requires 'Class::Accessor::Fast';
requires 'Asterisk::AGI';
requires 'Asterisk::Manager';
requires 'DBI';
requires 'Time::HiRes';
requires('Class::Accessor::Fast');
requires('Asterisk::AGI');
requires('Asterisk::Manager');
requires('DBI');
requires('Net::Server::PreFork');
requires('YAML::Syck');
requires('Text::SimpleTable');
requires('Module::CoreList');
no_index directory => 't';
no_index package => 'inc';
WriteAll;
@@ -1,11 +1,11 @@
Server:
Server_ip:
Server_ip: 192.168.1.2
Database:
Host: localhost
Host: 192.168.1.2
User: jaywhy
Password: 'password'
Port: 3306
DB_name: astguiclient
DB_name: 'asterisk'
Processes:
- AST_manager_listen
- AST_manager_send
+63 -13
View File
@@ -6,11 +6,13 @@ use DBI;
use Astguiclient::Config;
use Astguiclient::Manager;
use Astguiclient::Campaign;
use base 'Class::Accessor::Fast';
__PACKAGE__->mk_accessors(
qw( config dbi manager campaign )
);
use vars qw/ $DBI $MANAGER $CAMPAIGN $CONFIG /;
$Astguiclient::VERSION = '0.1';
BEGIN { require 5.006; }
=head1 NAME
@@ -30,19 +32,67 @@ sub new {
my $self = bless {}, $class;
# Setup accessors;
$self->config( Astguiclient::Config->new() );
$self->manager( Astguiclient::Manager->new() );
$self->campaign( Astguiclient::Campaign->new() );
my $f = $self->config->file();
my $dsn = "DBI:mysql:datbase=$f->{'Database'}{'DB_name'};host=$f->{'Database'}{'Host'};port=$f->{'Database'}{'Port'}";
$self->dbi (
DBI->connect( $dsn, $f->{'Database'}{'User'}, $f->{'Database'}{'Password'} )
);
Astguiclient->config( Astguiclient::Config->new() );
Astguiclient->manager( Astguiclient::Manager->new() );
Astguiclient->campaign( Astguiclient::Campaign->new() );
my $f = Astguiclient->config->file();
my $dsn = "DBI:mysql:database=$f->{'Database'}{'DB_name'};host=$f->{'Database'}{'Host'};port=$f->{'Database'}{'Port'}";
my $dbh = DBI->connect( $dsn, $f->{'Database'}{'User'}, $f->{'Database'}{'Password'}, { RaiseError => 1, AutoCommit => 0 } )
or die $DBI::errstr;
Astguiclient->dbi( $dbh );
return $self;
}
=head2 load
=head2 config
An accessor for L<Astguiclient::Config>.
=cut
sub config {
my $class = shift;
$CONFIG = shift if(@_);
return $CONFIG;
}
=head2 manager
An accessor for L<Astguiclient::Manager>.
=cut
sub manager {
my $class = shift;
$MANAGER = shift if(@_);
return $MANAGER;
}
=head2 dbi
An accessor for the DBI object.
=cut
sub dbi {
my $class = shift;
$DBI = shift if(@_);
return $DBI;
}
=head2 campaign
An accessor for L<Astguiclient::Campaign>.
=cut
sub campaign {
my $class = shift;
$CAMPAIGN = shift if(@_);
return $CAMPAIGN;
}
=head1 AUTHOR
@@ -1,9 +1,11 @@
package Astguiclient::AGI;
use strict;
use Asterisk::AGI;
use Time::HiRes qw( gettimeofday tv_interval usleep );
use base qw/Astguiclient/;
use base qw/Astguiclient Class::Accessor::Fast/;
__PACKAGE__->mk_accessors( qw/ agi input / );
=head1 NAME
@@ -19,7 +21,11 @@ Give description here
sub new {
my $class = shift;
return bless {}, $class;
my $self = $class->SUPER::new();
$self->agi( Asterisk::AGI->new() );
return $self;
}
=head2 call_log
@@ -159,7 +165,7 @@ sub _transfer_to_agent {
WHERE status = 'QUEUE' and server_ip = ? and campaign_id = ?
ORDER BY last_call_time limit 1",
undef,
$self->config->server->server_ip, $campaign->{campaign_id},
Astguiclient->config->file->{'Server_ip'}, $campaign->{campaign_id},
);
$self->_transfer( $extension );
@@ -168,6 +174,7 @@ sub _transfer_to_agent {
}
=head1 AUTHOR
Jason Yates <jaywhy@gmail.com>
@@ -1,6 +1,7 @@
package Astguiclient::Config;
use strict;
use Astguiclient::Util;
use YAML::Syck;
use vars qw( $SERVER $FILE );
@@ -25,6 +25,8 @@ sub process_request {
my $agc = $self->{server}{agc};
my %input = $agc->agi->ReadParse;
use Data::Dumper;
print STDERR Dumper(\%input);
my($method, $path) = $input{'request'} =~ m/\/(\w+)\?*([^\.]*)$/;
my %params;
my(@pairs) = split(/[&;]/,$path);
@@ -33,9 +35,13 @@ sub process_request {
$params{$p} = $v;
}
$self->input( \%params );
$agc->$method();
}
$agc->input( \%params );
if( $agc->can( $method ) ) {
$agc->$method();
} else { # Can't find that method.
$agc->agi->execute( 'NOOP' ); #NOTE is this the right thing todo?
}
}
=head2 child_init_hook
@@ -3,7 +3,7 @@ package Astguiclient::Util;
use File::Spec;
use Cwd;
our @dirs;
use vars qw( @dirs );
=head1 NAME
@@ -23,7 +23,7 @@ sub app_root {
if( not defined $APP_ROOT ) {
# Pop out bin/ from the cwd
my @dirs = File::Spec->splitdir( Cwd::cwd() );
pop @dirs;
pop @dirs if($dirs[-1] =~ 'bin');
$APP_ROOT = File::Spec->catdir( @dirs );
}
+1 -1
View File
@@ -57,7 +57,7 @@ my %required;
for (sort keys %used) {
my $first_in = Module::CoreList->first_release($_);
next if defined $first_in and $first_in <= 5.00803;
next if /^(Jifty|Jifty::DBI|inc|t|TestApp|Application)(::|$)/;
next if /^(Astguiclient|inc|t|TestApp|Application)(::|$)/;
ok(exists $required{$_}, "$_ in Makefile.PL")
or diag("used in ", join ", ", sort keys %{ $used{$_ } });
delete $used{$_};
+3 -3
View File
@@ -1,8 +1,8 @@
#!/usr/bin/perl -w
use strict;
use Test::More test => 2;
use Test::More test => '1';
use Astguiclient;
use_ok('Astguiclient');
my $a = Astguiclient->new();
ok($a->dbi->ping);
ok(Astguiclient->dbi->ping);
+3 -3
View File
@@ -1,9 +1,9 @@
#!/usr/bin/perl -w
use strict;
use Test::More tests => 3;
use Test::More tests => 2;
use Astguiclient;
use_ok('Astguiclient');
my $a = Astguiclient->new();
ok($a->config->file)
ok($a->config->file);
ok($a->config->server);