Skip Menu |

This queue is for tickets about the POE CPAN distribution.

Report information
The Basics
Id: 28867
Status: rejected
Priority: 0/
Queue: POE

People
Owner: Nobody in particular
Requestors: nperez [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] Add (expose really) alias_remove_all() method for POE::Kernel
Hola, Here is a patch that implements alias_remove_all(). The reason I did this was because I got a bug report in one of my modules that was leaking due to the way I had interpreted the documentation to alias_remove() with no arguments (ie. I'd read it wrong for years). I'm not the only author that has done this. It isn't initially obvious how to remove all aliases other than iterating through them via: $kernel->alias_remove( $_ ) for $kernel->alias_list( $session ); This patch exposes the internal _data_alias_clear_session and does some light checking on the public api. Tests are updated, as are docs for POE::Kernel. Let me know if I screwed up the white space/style/whatever and I'll fix it. Nick
Subject: add_alias_remove_all.patch
=== t/10_units/03_base/11_assert_usage.t ================================================================== --- t/10_units/03_base/11_assert_usage.t (revision 2242) +++ t/10_units/03_base/11_assert_usage.t (revision 2243) @@ -8,7 +8,7 @@ use strict; use lib qw(./mylib); -use Test::More tests => 76; +use Test::More tests => 81; use Symbol qw(gensym); @@ -234,6 +234,10 @@ $@ && $@ =~ /alias does not belong to current session/, "alias belongs to another session" ); + + # This shouldn't barf if there no valid aliases + eval { $_[KERNEL]->alias_remove_all( ) }; + ok( !$@, 'remove all aliases with no aliases' ); } } ); @@ -250,6 +254,37 @@ } ); +POE::Session->create( + inline_states => { + _start => sub { + $_[KERNEL]->alias_set('zomg'); + $_[KERNEL]->alias_set('wtf'); + $_[KERNEL]->alias_set('mtfnpy'); + + eval { $_[KERNEL]->alias_remove_all( ) }; + ok( !$@, 'remove all aliases with aliases' ); + + eval { $_[KERNEL]->alias_remove('zomg'); }; + ok( + $@ && $@ =~ /alias does not exist/, + 'alias does not exist' + ); + + eval { $_[KERNEL]->alias_remove('wtf'); }; + ok( + $@ && $@ =~ /alias does not exist/, + 'alias does not exist' + ); + + eval { $_[KERNEL]->alias_remove('mtfnpy'); }; + ok( + $@ && $@ =~ /alias does not exist/, + 'alias does not exist' + ); + } + } +); + # Filehandle I/O. POE::Session->create( === lib/POE/Kernel.pm ================================================================== --- lib/POE/Kernel.pm (revision 2242) +++ lib/POE/Kernel.pm (revision 2243) @@ -2297,6 +2297,28 @@ return 0; } +### Remove all aliases from the current session. + +sub alias_remove_all { + my ($self) = @_; + + if (ASSERT_USAGE) { + _confess "<us> must call alias_remove_all() from a running session" + if $kr_active_session == $self; + } + + # This should never happen, actually. + _trap "unknown session in alarm_remove_all call" + unless $self->_data_ses_exists($kr_active_session); + + # Now get rid of all of the aliases for this session + # This functionality is actually implemented in + # POE::Resource::Aliases. Just needs to be exposed + + $self->_data_alias_clear_session($kr_active_session); + return 0; +} + ### Resolve an alias into a session. sub alias_resolve { @@ -2595,6 +2617,9 @@ # Clear an alias for the current session: $status = $kernel->alias_remove( $alias ); + # Clear all aliases for the current session. + $status = $kernel->alias_remove_all( ); + # Resolve an alias into a session reference. Most POE::Kernel # methods do this for you. $session_reference = $kernel->alias_resolve( $alias ); @@ -3269,6 +3294,15 @@ EPERM: ALIAS belongs to some other session, and the current one does not have the authority to clear it. +=item alias_remove_all + +alias_remove_all() clears all aliases from the current session. All +aliases that refered to this session will be free for other sessions. + +This method takes no arguments. It returns zero upon success. + + $kernel->alias_remove_all( ); # I'M SPARTACUS + =item alias_resolve ALIAS alias_resolve() returns a session reference corresponding to its given
Duplicate of #28891.