Permalink
Browse files

Remove POE::Session->new() from the tarball samples. Resolves

rt.cpan.org ticket 8465.
  • Loading branch information...
1 parent 0d776ef commit ccd406eb81329a760ac1cd6c474f3fab1fef1693 @rcaputo committed Jan 29, 2005
View
@@ -10,9 +10,10 @@
use lib '../lib';
use IO::Socket;
-use POE qw( Wheel::SocketFactory Wheel::ReadWrite Driver::SysRW
- Filter::Line Filter::Stream
- );
+use POE qw(
+ Wheel::SocketFactory Wheel::ReadWrite Driver::SysRW
+ Filter::Line Filter::Stream
+);
#==============================================================================
# This is the login state group.
@@ -80,9 +81,10 @@ sub login_error {
$errstr = 'Client closed connection' unless $errnum;
- print( "Session ", $session->ID,
- ": login: $operation error $errnum: $errstr\n"
- );
+ print(
+ "Session ", $session->ID,
+ ": login: $operation error $errnum: $errstr\n"
+ );
delete $heap->{wheel};
}
@@ -97,12 +99,12 @@ sub login_session_start {
print "Session ", $session->ID, " - received connection\n";
# start reading and writing
- $heap->{wheel} = POE::Wheel::ReadWrite->new
- ( 'Handle' => $handle,
- 'Driver' => POE::Driver::SysRW->new,
- 'Filter' => POE::Filter::Line->new,
- 'ErrorEvent' => 'error',
- );
+ $heap->{wheel} = POE::Wheel::ReadWrite->new(
+ 'Handle' => $handle,
+ 'Driver' => POE::Driver::SysRW->new,
+ 'Filter' => POE::Filter::Line->new,
+ 'ErrorEvent' => 'error',
+ );
# hello, world!\n
$heap->{wheel}->put('FreeBSD (localhost) (ttyp2)', '', '');
$kernel->yield('login_start');
@@ -111,18 +113,21 @@ sub login_session_start {
sub login_session_create {
my ($handle, $peer_addr, $peer_port) = @_[ARG0, ARG1, ARG2];
- POE::Session->new( _start => \&login_session_start,
- # start parameters
- [ $handle, $peer_addr, $peer_port],
- # general error handler
- error => \&login_error,
- # login prompt states
- login_start => \&login_login_start,
- login_input => \&login_login_input,
- # password prompt states
- password_start => \&login_password_start,
- password_input => \&login_password_input
- );
+ POE::Session->create(
+ inline_states => {
+ _start => \&login_session_start,
+ # general error handler
+ error => \&login_error,
+ # login prompt states
+ login_start => \&login_login_start,
+ login_input => \&login_login_input,
+ # password prompt states
+ password_start => \&login_password_start,
+ password_input => \&login_password_input,
+ },
+ # start parameters
+ args => [ $handle, $peer_addr, $peer_port],
+ );
undef;
}
@@ -132,36 +137,40 @@ package main;
my $port = shift;
if (not defined $port) {
- print( "*** This program listens on port 23 by default. You can change\n",
- "*** the port by putting a new one on the command line. For\n",
- "*** example, to listen on port 10023:\n",
- "*** $0 10023\n",
- );
+ print(
+ "*** This program listens on port 23 by default. You can change\n",
+ "*** the port by putting a new one on the command line. For\n",
+ "*** example, to listen on port 10023:\n",
+ "*** $0 10023\n",
+ );
$port = 23;
}
-POE::Session->new
- ( '_start' => sub
- { my $heap = $_[HEAP];
-
- $heap->{wheel} = POE::Wheel::SocketFactory->new
- ( BindPort => $port,
- SuccessEvent => 'socket_ok',
- FailureEvent => 'socket_error',
- Reuse => 'yes',
- );
+POE::Session->create(
+ inline_states => {
+ '_start' => sub {
+ my $heap = $_[HEAP];
+
+ $heap->{wheel} = POE::Wheel::SocketFactory->new(
+ BindPort => $port,
+ SuccessEvent => 'socket_ok',
+ FailureEvent => 'socket_error',
+ Reuse => 'yes',
+ );
},
- 'socket_error' => sub
- { my ($session, $heap, $operation, $errnum, $errstr) =
+ 'socket_error' => sub {
+ my ($session, $heap, $operation, $errnum, $errstr) =
@_[SESSION, HEAP, ARG0, ARG1, ARG2];
- print( "Session ", $session->ID,
- ": listener: $operation error $errnum: $errstr\n"
- );
+ print(
+ "Session ", $session->ID,
+ ": listener: $operation error $errnum: $errstr\n"
+ );
},
'socket_ok' => \&login_session_create,
- );
+ },
+);
$poe_kernel->run();
View
@@ -164,14 +164,17 @@ sub fetch_id {
# This is a helper function that creates a new forkbomber session.
sub create_new_forkbomber {
- POE::Session->new( '_start' => \&_start,
- '_stop' => \&_stop,
- '_child' => \&_child,
- '_parent' => \&_parent,
- 'signal_handler' => \&signal_handler,
- 'fork' => \&fork,
- 'fetch_id' => \&fetch_id,
- );
+ POE::Session->create(
+ inline_states => {
+ '_start' => \&_start,
+ '_stop' => \&_stop,
+ '_child' => \&_child,
+ '_parent' => \&_parent,
+ 'signal_handler' => \&signal_handler,
+ 'fork' => \&fork,
+ 'fetch_id' => \&fetch_id,
+ }
+ );
}
#==============================================================================
View
@@ -37,7 +37,11 @@ sub new {
# hello, world!
print "> $self created\n";
# give this object to POE
- POE::Session->new($self, [ qw(_start _stop lock unlock sighandler) ]);
+ POE::Session->create(
+ object_states => [
+ $self, [ qw(_start _stop lock unlock sighandler) ]
+ ]
+ );
# Don't let the caller have a reference. It's not very nice, but it
# also prevents the caller from holding onto the reference and
@@ -176,14 +180,17 @@ sub new {
# hello, world!
print "> $self created\n";
# give this object to POE
- POE::Session->new( $self,
- [ qw(_start _stop
- acquire_lock retry_acquire
- release_lock retry_release
- perform_locked_operation perform_unlocked_operation
- )
- ]
- );
+ POE::Session->create(
+ object_states => [
+ $self,
+ [ qw(_start _stop
+ acquire_lock retry_acquire
+ release_lock retry_release
+ perform_locked_operation perform_unlocked_operation
+ )
+ ],
+ ]
+ );
# it will manage itself, thank you
undef;
}
View
@@ -126,13 +126,16 @@ sub poe_runtime_state {
package main;
foreach my $name (qw(one two three four five six seven eight nine ten)) {
- POE::Session->new( new Counter($name) =>
- { _start => 'poe_start',
- _stop => 'poe_stop',
- increment => 'poe_increment',
- sigint => 'poe_sigint',
- },
- );
+ POE::Session->create(
+ object_states => [
+ Counter->new($name) => {
+ _start => 'poe_start',
+ _stop => 'poe_stop',
+ increment => 'poe_increment',
+ sigint => 'poe_sigint',
+ },
+ ],
+ );
}
$poe_kernel->run();
View
@@ -125,9 +125,11 @@ sub runtime_state {
package main;
foreach my $name (qw(one two three four five six seven eight nine ten)) {
- POE::Session->new( Counter->new($name) =>
- [ qw(_start _stop increment sigint) ]
- );
+ POE::Session->create(
+ object_states => [
+ Counter->new($name) => [ qw(_start _stop increment sigint) ]
+ ],
+ );
}
$poe_kernel->run();
@@ -112,9 +112,11 @@ package main;
# stupid scope trick, part 3 of 3
$Counter::name = $name;
# create the session
- POE::Session->new( Counter =>
- [ qw(_start _stop increment sigint) ]
- );
+ POE::Session->create(
+ package_states => [
+ Counter => [ qw(_start _stop increment sigint) ]
+ ]
+ );
}
$poe_kernel->run();
View
@@ -155,12 +155,12 @@ sub server_start {
$kernel->sig('INT', 'signal');
$kernel->sig('PIPE', 'signal');
# create the listening socket
- my $listener = IO::Socket::INET->new
- ( 'LocalPort' => $chargen_port,
- 'Listen' => 5,
- 'Proto' => 'tcp',
- 'Reuse' => 'yes',
- );
+ my $listener = IO::Socket::INET->new(
+ LocalPort => $chargen_port,
+ Listen => 5,
+ Proto => 'tcp',
+ Reuse => 'yes',
+ );
# move to 'accept' when read-okay
if ($listener) {
$kernel->select_read($listener, 'accept');
@@ -224,17 +224,19 @@ sub server_accept {
my $peer_host = $connection->peerhost();
my $peer_port = $connection->peerport();
# create a session to handle I/O
- my $new = POE::Session->new
- ( _start => \&session_start,
+ my $new = POE::Session->create(
+ inline_states => {
+ _start => \&session_start,
_stop => \&session_stop,
_default => \&session_default,
'read' => \&session_read,
'write' => \&session_write,
signal => \&session_signal,
+ },
- # ARG0, ARG1 and ARG2
- [ $connection, $peer_host, $peer_port ]
- );
+ # ARG0, ARG1 and ARG2
+ args => [ $connection, $peer_host, $peer_port ]
+ );
}
else {
if ($! == EAGAIN) {
@@ -276,12 +278,12 @@ sub client_start {
# so it knows when to stop
$heap->{'lines read'} = 0;
# try to make a connection
- my $socket = IO::Socket::INET->new
- ( 'PeerHost' => 'localhost',
- 'PeerPort' => $chargen_port,
- 'Proto' => 'tcp',
- 'Reuse' => 'yes',
- );
+ my $socket = IO::Socket::INET->new(
+ PeerHost => 'localhost',
+ PeerPort => $chargen_port,
+ Proto => 'tcp',
+ Reuse => 'yes',
+ );
# start reading if connected
if ($socket) {
print "The chargen client has connected to port $chargen_port.\n";
View
@@ -148,14 +148,16 @@ sub main_start {
foreach my $name (qw(one two three four five six seven eight nine ten)) {
# stupid scope trick, part 3 of 3 parts
$session_name = $name;
- my $session = POE::Session->new
- ( _start => \&child_start,
+ my $session = POE::Session->create(
+ inline_states => {
+ _start => \&child_start,
_stop => \&child_stop,
increment => \&child_increment,
display_one => \&child_display_one,
display_two => \&child_display_two,
fetch_name => \&child_fetch_name,
- );
+ }
+ );
# Normally, sessions are stopped if they have nothing to do. The
# only exception to this rule is newly created sessions. Their
@@ -197,11 +199,13 @@ sub main_child {
# Start the main (parent) session, and begin processing events.
# Kernel::run() will continue until there is nothing left to do.
-POE::Session->new
- ( _start => \&main_start,
+POE::Session->create(
+ inline_states => {
+ _start => \&main_start,
_stop => \&main_stop,
_child => \&main_child,
- );
+ }
+);
$poe_kernel->run();
Oops, something went wrong.

0 comments on commit ccd406e

Please sign in to comment.