Agent

 view release on metacpan or  search on metacpan

Agent.pm  view on Meta::CPAN

	if ($stored) {
		if (ref($stored) eq 'ARRAY') { $code = join('', @$stored); }
		else { $code = $stored; }
		$method = 'repair';
	} else {
		if ($fh) {
			unless ($fh->isa('IO::Handle')) {
				warn "File argument was not of IO::Handle!";
				return;
			}
			local $/ = undef;
			$code = <$fh>;
		} elsif ($name) {
			$code = _find_agent($name);
		} elsif ($code) {
			if (ref($stored) eq 'ARRAY') {
				$code = join('', @$code);
			}
		} else {
			my ($pkg, $fl, $ln) = caller();
			warn "$fl:$ln passed no valid arguments!";

Agent.pm  view on Meta::CPAN

	push (@dirs, '.', @INC);			# search local dir & @INC too.
	# adapted from Class::Tom::insert:
	foreach $_ (@dirs) {
		print "Agent: Looking in $_ for $name\n" if $Debug > 1;
		if (-e "$_/$name") {
			print "Agent: Found $name!\n" if $Debug;
			unless ( open(PAFILE, "$_/$name") ) {
				warn "Agent: could not open $_/$name!";
				return;
			}
			local $/ = undef;
			my $code = <PAFILE>;
			close PAFILE;
			return $code;
		}
	}
	return;
}

sub _run {
	my ($self, %args) = @_;

Agent.pm  view on Meta::CPAN


=over 4

=item A Perl Agent

Is any chunk of Perl code that can accomplish some user-defined objective
by communicating with other agents, and manipulating any data it obtains.

A Perl Agent consists of a knowledge base (variables), a reasoning
procedure (code), and access to one or more languages coupled with
methods of communication.  These languages remain largely undefined, or
rather, user-defined; support for KQML/KIF is under development.

=item Developing An Agent

Note that the developer must devise the reasoning procedure and knowledge
base described above.  Agent Perl does not place any restrictions on what
you may do; it only tries to make the 'doing' part easier.

An agent is written as an inheriting sub-class of I<Agent>.  Each agent's
class should be stored in a '.pa' file (I<p>erl I<a>gent), and must contain

Agent/Transport/TCP.pm  view on Meta::CPAN

                PeerAddr => $addr,
                Reuse => 1
	) or return ();	# use IO::Socket's $!

	for( @msg ) { $con->send( $_ ) or return (); }

	# preserve connection?
	${$args{KeepAlive}}  = $con if (ref $args{KeepAlive} eq 'SCALAR');

	$con->close();
	undef $con;	# paranoia
	1;
}

sub valid_address {
	$_ = shift;
	$_ =~ /(^(\d{1,3}\.){3}\d{1,3})|(^(\w+\.)*\w+)\:\d+$/;
	return $_;
}

##

examples/keepalive.pl  view on Meta::CPAN

print "S: waiting for incoming...\n";
my $client = $tcp->accept() or die "ACK!";

my @data = $client->getline;

print "S: made it! ", ref( $client ), "\n";
print @data;
print "S: writing 'hi there!\\n' to C...\n";
print $client "hi there! Ed!\n";
print "S: done.\n";
undef $client;	# terminate socket connection

"Waiting for process $pid...\n";
waitpid( $pid, 0 );



( run in 0.846 second using v1.01-cache-2.11-cpan-d80b1682f3f )