Agent
view release on metacpan or search on metacpan
warn "Unsafe agent trapped: $@\n";
return;
}
unless ($self->{AgentVar}) {
$self->{AgentVar} = '$agent';
my $agentclass = $tom->class;
my $str =
"if ('$agentclass' && (\${$agentclass\:\:}{new})) {\n" .
" \$agent = new $agentclass(" . %args . ");\n" .
"} else {\n" .
" \$agent = {}; bless \$agent, $agentclass;\n" .
"}";
$cpt->reval($str);
print "AGENT: ", ${$cpt->varglob('agent')}, "\n";
if ($@) {
warn "Unsafe agent trapped: $@\n" if $Debug;
return;
}
}
# store the agent's class in the agent itself:
${$cpt->varglob($self->{AgentVar})}->{Tom} = $tom;
bless $self, $class; # bless wrapper into Agent!
} else {
unless ($self = $tom->get_object) {
no strict;
# got no object, so create one:
my $agentclass = $tom->class();
if (($agentclass) && (${"$agentclass\:\:"}{new})) {
$self = new $agentclass(%args);
} else {
print STDERR "$agentclass\:\:new() not found!\n" if $Debug;
# we'll just bless $self into the agent's class:
$self = {};
bless $self, $agentclass;
}
}
# store the agent's class in the agent itself:
$self->{Tom} = $tom;
}
# this is not true for wrapped agents:
print "agent's class is: " . ref($self) . "\n" if $Debug > 1;
return $self; # blessed into owning agent's class!
}
##
# Inherited methods safe for use by agent objects.
##
sub run {
my ($self, %args) = @_;
Agent/Message.pm view on Meta::CPAN
#$Debug = 1;
sub new {
my ($class, %args) = @_;
my $self = {};
$self->{Body} = $args{Body};
if ($args{Transport}) {
${$self->{Transport}}{$args{Transport}} = [ $args{Address} ];
if ($args{SendNow}) {
bless $self, $class;
return $self->send;
}
}
bless $self, $class;
}
sub send {
my $self = shift;
my %args = @_;
my %trans = %{$self->{Transport}};
my @return;
foreach $medium (keys(%trans)) {
my @addrs = @{$trans{$medium}};
Agent/Transport/TCP.pm view on Meta::CPAN
Listen => 1,
LocalAddr => $addr . ':' . $port,
Reuse => 1
);
print "Couldn't get connection: $!\n" if ($Debug && $!);
return unless $args{'Cycle'}; # cycle for a free port?
$port++;
}
$self->{Server}->autoflush();
bless $self, $class;
}
sub recv {
my ($self, %args) = @_;
my $remote = $self->accept(%args) or return ();
return $remote->getlines();
}
examples/Eval.pa view on Meta::CPAN
# October 5, 1998.
##
package Agent::Eval;
@ISA = qw( Agent );
sub new {
my ($class, %args) = @_;
my $self = {};
foreach (keys(%args)) { $self->{"$_"} = $args{"$_"}; }
bless $self, $class;
}
sub agent_main {
my ($self, @args) = @_;
my $message;
# delete so we only do one hop..
my $to = delete($self->{Host});
if ($to) {
@message = ("$self->{Return}\n", $self->store());
examples/FreeSpace.pa view on Meta::CPAN
# Only those stored in $self are!
# Programming an agent is like programming a recursive function.
package Agent::FreeSpace;
@ISA = qw( Agent );
sub new {
my ($class, %args) = @_;
my $self = {};
foreach (keys(%args)) { $self->{"$_"} = $args{"$_"}; }
bless $self, $class;
}
sub agent_main {
my ($self, @args) = @_;
my $to = \$self->{To};
print "At: $$to\n" if $self->{verbose};
if ($$to) {
${$self->{Space}}{$$to} = $self->space();
}
examples/HelloWorld.pa view on Meta::CPAN
##
package Agent::HelloWorld;
#use Net::FTP;
@ISA = qw( Agent );
sub new {
my ($class, %args) = @_;
my $self = {};
foreach (keys(%args)) { $self->{"$_"} = $args{"$_"}; }
bless $self, $class;
}
sub agent_main {
my ($self, @args) = @_;
# NB: we don't need a transport address..
# delete so we only do one hop..
my $to = delete($self->{Host});
print "Are we there yet? " if $self->{verbose};
examples/Loop.pa view on Meta::CPAN
# Jan 18, 1998.
##
package Agent::Loop;
@ISA = qw( Agent );
sub new {
my ($class, %args) = @_;
my $self = {};
foreach (keys(%args)) { $self->{"$_"} = $args{"$_"}; }
bless $self, $class;
}
sub agent_main {
my ($self, @args) = @_;
# first, get a Transport address:
my $tcp = new Agent::Transport(
Medium => 'TCP',
Cycle => 1
) or die "Couldn't get a tcp transport address: $!!\n";
examples/MyAgent.pl view on Meta::CPAN
my $code= <<'HERE';
package Agent::Example::Test;
@ISA = qw ( Agent );
sub new {
my $class = shift;
my %args = @_;
my $self = {};
foreach (keys(%args)) { $self->{$_} = $args{$_}; }
bless $self, $class;
}
sub agent_main {
my $self = shift;
my $to = delete ($self->{Host});
my $mesg = new Agent::Message (
Body => [
ref($self)."\n",
$self->store()
],
examples/Static.pa view on Meta::CPAN
use Safe;
##
# Constructor:
sub new {
my ($class, %args) = @_;
my $self = {};
foreach (keys(%args)) { $self->{"$_"} = $args{"$_"}; }
bless $self, $class;
}
##
# agent_main - Main agent program. Waits for incoming requests, and hosts
# any agents it recieves. One might conceivably do a double fork()
# and run this in the background on UN*X machines.
##
sub agent_main {
my ($self, @args) = @_;
examples/Template.pa view on Meta::CPAN
##
# The agent's constructor:
sub new {
my ($class, %args) = @_;
my $self = {};
# copy all arguments into the new object:
foreach (keys(%args)) { $self->{"$_"} = $args{"$_"}; }
bless $self, $class;
}
##
# The agent_main sub:
sub agent_main {
my ($self, %args) = @_;
# This is the agent's main program.
( run in 2.086 seconds using v1.01-cache-2.11-cpan-de7293f3b23 )