The document discusses the Perl event framework POE (Pumpkin Onion Engine). It provides an overview of POE's components including the Kernel, Sessions, Wheels, and Components. It also presents two case studies - a ping multipler application that uses the POE::Component::Client::Ping component, and an IRC bot that uses the POE::Component::IRC component. The document demonstrates how POE allows building event-driven and multithreaded applications using these reusable POE components.
13. COMPONENT POE::Wheel
“Plugins” para a sessão.
WHEEL Encapsular conjuntos de
manipuladores de eventos.
SESSION #Exemplo: POE::Wheel::Run
#Executa um programa ou um conjunto de
código em um subprocesso usando fork() e
troca informações pelo stdin, stdout, stderr.
KERNEL
14. COMPONENT POE::Component
564 componentes no
WHEEL CPAN até ontem.
(30/Outubro/2009)
SESSION POE::Component::IRC,
POE::Component::Server::Radius
POE::Component::Server::TCP
POE::Component::Server::HTTP
POE::Component::Github
KERNEL POE::Component::Jabber
(...)
17. use POE;
use POE::Component::Client::Ping;
my @addresses = qw(200.219.201.245
200.219.201.246 200.219.201.247);
POE::Component::Client::Ping->spawn(
Alias => 'pinger',
Timeout => 5, SESSION
);
POE::Session->create( COMPONENT
inline_states => {
_start => &client_start,
pong => &client_got_pong,
}
);
18. sub client_start {
my ($kernel, $session) =
@_[KERNEL, SESSION];
print "Starting to ping hosts.n";
foreach my $address (@addresses) {
$kernel->post(
pinger => ping => pong => $address);
}
}
19. sub client_got_pong {
my ($kernel, $session) = @_[KERNEL, SESSION];
my $request_packet = $_[ARG0];
my ($request_packetest_address, $request_timeout, $request_time) =
@{$request_packet};
my $response_packet = $_[ARG1];
my ($response_address, $roundtrip_time, $reply_time) =
@{$response_packet};
if (defined $response_address) {
printf("Pinged %-15.15s - Response from %-15.15s in %6.3fsn",
$request_address, $response_address, $roundtrip_time);
}
else {
print "Time's up for responses from $request_address.n";
}
}