Index: trunk/poe/lib/POE/Kernel.pm
===================================================================
--- trunk/poe/lib/POE/Kernel.pm (revision 2276)
+++ trunk/poe/lib/POE/Kernel.pm (working copy)
@@ -1368,7 +1368,7 @@
# structures as a side effect.
sub session_alloc {
- my ($self, $session, @args) = @_;
+ my ($self, $session, $aliases, @args) = @_;
# If we already returned, then we must reinitialize. This is so
# $poe_kernel->run() will work correctly more than once.
@@ -1391,6 +1391,12 @@
# Register that a session was created.
$kr_run_warning |= KR_RUN_SESSION;
+ # Set initial session alias if present
+ if (defined $aliases) {
+ $self->_alias_set($session, $_)
+ for @$aliases;
+ }
+
# Allocate the session's data structure. This must be done before
# we dispatch anything regarding the new session.
my $new_sid = $self->_data_sid_allocate();
@@ -2254,8 +2260,8 @@
### Set an alias in the current session.
-sub alias_set {
- my ($self, $name) = @_;
+sub _alias_set {
+ my ($self, $target_session, $name) = @_;
if (ASSERT_USAGE) {
_confess "<us> undefined alias in alias_set()" unless defined $name;
@@ -2264,17 +2270,19 @@
# Don't overwrite another session's alias.
my $existing_session = $self->_data_alias_resolve($name);
if (defined $existing_session) {
- if ($existing_session != $kr_active_session) {
+ if ($existing_session != $target_session) {
$self->_explain_usage("alias '$name' is in use by another session");
return EEXIST;
}
return 0;
}
- $self->_data_alias_add($kr_active_session, $name);
+ $self->_data_alias_add($target_session, $name);
return 0;
}
+sub alias_set { my $self = shift; $self->_alias_set($kr_active_session, @_) }
+
### Remove an alias from the current session.
sub alias_remove {
Index: trunk/poe/lib/POE/Session.pm
===================================================================
--- trunk/poe/lib/POE/Session.pm (revision 2276)
+++ trunk/poe/lib/POE/Session.pm (working copy)
@@ -20,6 +20,7 @@
sub CREATE_PACKAGES () { 'package_states' }
sub CREATE_OBJECTS () { 'object_states' }
sub CREATE_HEAP () { 'heap' }
+sub CREATE_ALIAS () { 'aliases' }
sub OPT_TRACE () { 'trace' }
sub OPT_DEBUG () { 'debug' }
@@ -184,13 +185,13 @@
}
sub try_alloc {
- my ($self, @args) = @_;
+ my ($self, $aliases, @args) = @_;
# Verify that the session has a special start state, otherwise how
# do we know what to do? Don't even bother registering the session
# if the start state doesn't exist.
if (exists $self->[SE_STATES]->{+EN_START}) {
- $POE::Kernel::poe_kernel->session_alloc($self, @args);
+ $POE::Kernel::poe_kernel->session_alloc($self, $aliases, @args);
}
else {
carp( "discarding session ",
@@ -248,6 +249,22 @@
delete $params{+CREATE_OPTIONS};
}
+ # Extract initial aliases.
+
+ my $aliases;
+ if (exists $params{+CREATE_ALIAS}) {
+ if (ref($params{+CREATE_ALIAS}) eq 'ARRAY') {
+ $aliases = $params{+CREATE_ALIAS};
+ }
+ elsif (ref($params{+CREATE_ALIAS}) eq '') {
+ $aliases = [ $params{+CREATE_ALIAS} ];
+ }
+ else {
+ croak "aliases for $type constructor is expected to be a ARRAY reference";
+ }
+ delete $params{+CREATE_ALIAS};
+ }
+
# Get down to the business of defining states.
while (my ($param_name, $param_value) = each %params) {
@@ -371,7 +388,7 @@
}
}
- return $self->try_alloc(@args);
+ return $self->try_alloc($aliases, @args);
}
#------------------------------------------------------------------------------