Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

rt.cpan.org ticket 8465.
  • Loading branch information...
commit ccd406eb81329a760ac1cd6c474f3fab1fef1693 1 parent 0d776ef
@rcaputo authored
View
99 samples/fakelogin.perl
@@ -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
19 samples/forkbomb.perl
@@ -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
25 samples/names.perl
@@ -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
17 samples/objmaps.perl
@@ -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
8 samples/objsessions.perl
@@ -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();
View
8 samples/packagesessions.perl
@@ -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
36 samples/selects.perl
@@ -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
16 samples/sessions.perl
@@ -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();
View
51 samples/signals.perl
@@ -20,10 +20,11 @@
# fictitious signals (SIGFOO and SIGQUUX). The session then starts an
# alarm loop that signals FOO to itself once a second.
-POE::Session->new
+POE::Session->create(
+ inline_states => {
### _start the session
- ( '_start' => sub
- { my $kernel = $_[KERNEL];
+ '_start' => sub{
+ my $kernel = $_[KERNEL];
# register signal handlers
$kernel->sig('INT', 'signal handler');
$kernel->sig('FOO', 'signal handler');
@@ -34,12 +35,12 @@
$kernel->delay('set an alarm', 1);
},
### _stop the session
- '_stop' => sub
- { print "First session stopped.\n";
+ '_stop' => sub {
+ print "First session stopped.\n";
},
### alarm handler
- 'set an alarm' => sub
- { my ($kernel, $session) = @_[KERNEL, SESSION];
+ 'set an alarm' => sub {
+ my ($kernel, $session) = @_[KERNEL, SESSION];
print "First session's alarm rang. Sending SIGFOO to itself...\n";
# send a signal to itself
$kernel->signal($session, 'FOO');
@@ -47,19 +48,21 @@
$kernel->delay('set an alarm', 1);
},
### signal handler
- 'signal handler' => sub
- { my ($kernel, $signal_name) = @_[KERNEL, ARG0];
+ 'signal handler' => sub {
+ my ($kernel, $signal_name) = @_[KERNEL, ARG0];
print "First session caught SIG$signal_name\n";
- print( "First session's pending alarms: ",
- join(':', map { "\"$_\"" } $kernel->queue_peek_alarms()), "\n"
- );
+ print(
+ "First session's pending alarms: ",
+ join(':', map { "\"$_\"" } $kernel->queue_peek_alarms()), "\n"
+ );
# stop pending alarm on SIGINT
if ($signal_name eq 'INT') {
print "First session stopping...\n";
$kernel->delay('set an alarm');
}
},
- );
+ }
+);
#==============================================================================
# This is another pathological inline session. This one registers
@@ -67,10 +70,11 @@
# The session then starts an alarm loop that signals QUUX to the
# kernel twice a second. This propagates SIGQUUX to every session.
-POE::Session->new
+POE::Session->create(
+ inline_states => {
### _start the session
- ( '_start' => sub
- { my $kernel = $_[KERNEL];
+ '_start' => sub {
+ my $kernel = $_[KERNEL];
# register signal handlers
$kernel->sig('INT', 'signal handler');
$kernel->sig('BAZ', 'signal handler');
@@ -81,12 +85,12 @@
$kernel->delay('set an alarm', 0.5);
},
### _stop the session
- '_stop' => sub
- { print "Second session stopped.\n";
+ '_stop' => sub {
+ print "Second session stopped.\n";
},
### alarm handler
- 'set an alarm' => sub
- { my $kernel = $_[KERNEL];
+ 'set an alarm' => sub {
+ my $kernel = $_[KERNEL];
print "Second session's alarm rang. Sending SIGQUUX to kernel...\n";
# signal the kernel
$kernel->signal($kernel, 'QUUX');
@@ -94,8 +98,8 @@
$kernel->delay('set an alarm', 0.5);
},
### signal handler
- 'signal handler' => sub
- { my ($kernel, $signal_name) = @_[KERNEL, ARG0];
+ 'signal handler' => sub {
+ my ($kernel, $signal_name) = @_[KERNEL, ARG0];
print "Second session caught SIG$signal_name\n";
print( "Second session's pending alarms: ",
join(':', $kernel->queue_peek_alarms()), "\n"
@@ -106,7 +110,8 @@
$kernel->delay('set an alarm');
}
},
- );
+ }
+);
#==============================================================================
# Tell the kernel to run the sessions.
View
114 samples/thrash.perl
@@ -39,17 +39,20 @@
sub client_create {
my $serial_number = shift;
# create the session
- POE::Session->new( _start => \&client_start,
- _stop => \&client_stop,
- receive => \&client_receive,
- error => \&client_error,
- connected => \&client_connected,
- signals => \&client_signals,
- _parent => sub {},
-
- # ARG0
- [ $serial_number ]
- );
+ POE::Session->create(
+ inline_states => {
+ _start => \&client_start,
+ _stop => \&client_stop,
+ receive => \&client_receive,
+ error => \&client_error,
+ connected => \&client_connected,
+ signals => \&client_signals,
+ _parent => sub {},
+ },
+
+ # ARG0
+ args => [ $serial_number ]
+ );
}
#------------------------------------------------------------------------------
@@ -65,12 +68,12 @@ sub client_start {
# watch for SIGINT
$kernel->sig('INT', 'signals');
# create a socket factory
- $heap->{'wheel'} = POE::Wheel::SocketFactory->new
- ( RemoteAddress => $server_addr, # connecting to address $server_addr
- RemotePort => $server_port, # connecting to port $server_port
- SuccessEvent => 'connected', # generating this event when connected
- FailureEvent => 'error', # generating this event upon an error
- );
+ $heap->{'wheel'} = POE::Wheel::SocketFactory->new(
+ RemoteAddress => $server_addr, # connecting to address $server_addr
+ RemotePort => $server_port, # connecting to port $server_port
+ SuccessEvent => 'connected', # generating this event when connected
+ FailureEvent => 'error', # generating this event upon an error
+ );
}
#------------------------------------------------------------------------------
@@ -94,13 +97,13 @@ sub client_connected {
die "possible filehandle leak" if fileno($socket) > 63;
DEBUG && print "Client $heap->{'serial'} is connected.\n";
# switch to read/write behavior
- $heap->{'wheel'} = POE::Wheel::ReadWrite->new
- ( Handle => $socket, # read and write on this socket
- Driver => POE::Driver::SysRW->new, # using sysread and syswrite
- Filter => POE::Filter::Line->new, # and parsing I/O as lines
- InputEvent => 'receive', # generating this event on input
- ErrorEvent => 'error', # generating this event on error
- );
+ $heap->{'wheel'} = POE::Wheel::ReadWrite->new(
+ Handle => $socket, # read and write on this socket
+ Driver => POE::Driver::SysRW->new, # using sysread and syswrite
+ Filter => POE::Filter::Line->new, # and parsing I/O as lines
+ InputEvent => 'receive', # generating this event on input
+ ErrorEvent => 'error', # generating this event on error
+ );
shutdown($socket, 1);
}
@@ -156,13 +159,15 @@ sub client_signals {
sub pool_create {
# create the server
- POE::Session->new
- ( _start => \&pool_start,
+ POE::Session->create(
+ inline_states => {
+ _start => \&pool_start,
_stop => \&pool_stop,
signals => \&pool_signals,
_child => \&pool_child,
_parent => sub {},
- );
+ },
+ );
}
#------------------------------------------------------------------------------
@@ -266,8 +271,9 @@ sub pool_child {
sub session_create {
my ($handle, $peer_host, $peer_port) = @_;
# create the session
- POE::Session->new
- ( _start => \&session_start,
+ POE::Session->create(
+ inline_states => {
+ _start => \&session_start,
_stop => \&session_stop,
receive => \&session_receive,
flushed => \&session_flushed,
@@ -275,10 +281,11 @@ sub session_create {
signals => \&session_signals,
_child => sub {},
_parent => sub {},
+ },
- # ARG0, ARG1, ARG2
- [ $handle, $peer_host, $peer_port ]
- );
+ # ARG0, ARG1, ARG2
+ args => [ $handle, $peer_host, $peer_port ]
+ );
}
#------------------------------------------------------------------------------
@@ -297,17 +304,18 @@ sub session_start {
$heap->{'host'} = $peer_host;
$heap->{'port'} = $peer_port;
# start reading and writing
- $heap->{'wheel'} = POE::Wheel::ReadWrite->new
- ( Handle => $handle, # on the client's socket
- Driver => POE::Driver::SysRW->new, # using sysread and syswrite
- Filter => POE::Filter::Line->new, # and parsing I/O as lines
- InputEvent => 'receive', # generating this event on input
- ErrorEvent => 'error', # generating this event on error
- FlushedEvent => 'flushed', # generating this event on flush
- );
+ $heap->{'wheel'} = POE::Wheel::ReadWrite->new(
+ Handle => $handle, # on the client's socket
+ Driver => POE::Driver::SysRW->new, # using sysread and syswrite
+ Filter => POE::Filter::Line->new, # and parsing I/O as lines
+ InputEvent => 'receive', # generating this event on input
+ ErrorEvent => 'error', # generating this event on error
+ FlushedEvent => 'flushed', # generating this event on flush
+ );
# give the client the time of day
- $heap->{'wheel'}->put
- ( "Hi, $peer_host $peer_port! The time is: " . gmtime() . " GMT" );
+ $heap->{'wheel'}->put(
+ "Hi, $peer_host $peer_port! The time is: " . gmtime() . " GMT"
+ );
}
#------------------------------------------------------------------------------
@@ -375,15 +383,17 @@ sub session_signals {
sub server_create {
# create the server
- POE::Session->new
- ( _start => \&server_start,
+ POE::Session->create(
+ inline_states => {
+ _start => \&server_start,
_stop => \&server_stop,
accept_success => \&server_accept,
accept_error => \&server_error,
signals => \&server_signals,
_child => sub {},
_parent => sub {},
- );
+ }
+ );
}
#------------------------------------------------------------------------------
@@ -399,13 +409,13 @@ sub server_start {
$kernel->sig('INT', 'signals');
$kernel->sig('QUIT', 'signals');
# create a socket factory
- $heap->{'wheel'} = POE::Wheel::SocketFactory->new
- ( BindAddress => $server_addr, # bind the listener to this address
- BindPort => $server_port, # bind the listener to this port
- Reuse => 'yes', # and reuse the socket right away
- SuccessEvent => 'accept_success', # generate this event for connections
- FailureEvent => 'accept_error', # generate this event for errors
- );
+ $heap->{'wheel'} = POE::Wheel::SocketFactory->new(
+ BindAddress => $server_addr, # bind the listener to this address
+ BindPort => $server_port, # bind the listener to this port
+ Reuse => 'yes', # and reuse the socket right away
+ SuccessEvent => 'accept_success', # generate this event for connections
+ FailureEvent => 'accept_error', # generate this event for errors
+ );
}
#------------------------------------------------------------------------------
View
56 samples/wheels2.perl
@@ -3,7 +3,7 @@
# A simple socket client that uses a two-handle wheel to pipe between
# a socket and the console. It's hardcoded to talk with wheels.perl's
-# rot13 server on localhost port 32000.
+# rot13 server on localhost port 32100.
use strict;
use lib '../lib';
@@ -11,7 +11,7 @@
use POE qw(Wheel::SocketFactory Wheel::ReadWrite Driver::SysRW Filter::Stream);
-my $rot13_port = 32000;
+my $rot13_port = 32100;
#==============================================================================
# A client socket session that pipes between a connected socket and
@@ -27,12 +27,12 @@ sub session_start {
print "Connecting...\n";
- $heap->{connector} = POE::Wheel::SocketFactory->new
- ( RemoteAddress => '127.0.0.1',
- RemotePort => $rot13_port,
- SuccessEvent => 'connect_success',
- FailureEvent => 'connect_failure',
- );
+ $heap->{connector} = POE::Wheel::SocketFactory->new(
+ RemoteAddress => '127.0.0.1',
+ RemotePort => $rot13_port,
+ SuccessEvent => 'connect_success',
+ FailureEvent => 'connect_failure',
+ );
}
#------------------------------------------------------------------------------
@@ -46,22 +46,22 @@ sub session_connect_success {
delete $heap->{connector};
- $heap->{console_wheel} = POE::Wheel::ReadWrite->new
- ( InputHandle => \*STDIN,
- OutputHandle => \*STDOUT,
- Driver => POE::Driver::SysRW->new,
- Filter => POE::Filter::Stream->new,
- InputEvent => 'console_input',
- ErrorEvent => 'console_error',
- );
-
- $heap->{socket_wheel} = POE::Wheel::ReadWrite->new
- ( Handle => $connected_socket,
- Driver => POE::Driver::SysRW->new,
- Filter => POE::Filter::Stream->new,
- InputEvent => 'socket_input',
- ErrorEvent => 'socket_error',
- );
+ $heap->{console_wheel} = POE::Wheel::ReadWrite->new(
+ InputHandle => \*STDIN,
+ OutputHandle => \*STDOUT,
+ Driver => POE::Driver::SysRW->new,
+ Filter => POE::Filter::Stream->new,
+ InputEvent => 'console_input',
+ ErrorEvent => 'console_error',
+ );
+
+ $heap->{socket_wheel} = POE::Wheel::ReadWrite->new(
+ Handle => $connected_socket,
+ Driver => POE::Driver::SysRW->new,
+ Filter => POE::Filter::Stream->new,
+ InputEvent => 'socket_input',
+ ErrorEvent => 'socket_error',
+ );
$heap->{console_wheel}->put("Begun terminal session.");
}
@@ -135,8 +135,9 @@ sub session_socket_error {
# Start the Session, which will fire off the _start event and begin
# the connection.
-POE::Session->new
- ( _start => \&session_start,
+POE::Session->create(
+ inline_states => {
+ _start => \&session_start,
_stop => \&session_stop,
connect_success => \&session_connect_success,
@@ -147,7 +148,8 @@ sub session_socket_error {
socket_input => \&session_socket_input,
socket_error => \&session_socket_error,
- );
+ },
+);
$poe_kernel->run();
Please sign in to comment.
Something went wrong with that request. Please try again.