POE-API-Peek-2.20000755001751000144 011703316666 13013 5ustar00chrisusers000000000000README100644001751000144 3337211703316666 14004 0ustar00chrisusers000000000000POE-API-Peek-2.20NAME POE::API::Peek - Peek into the internals of a running POE environment VERSION version 2.20 DESCRIPTION POE::API::Peek extends the POE::Kernel interface to provide clean access to Kernel internals in a cross-version compatible manner. Other calculated data is also available. My intention is to provide massive amounts of internal data for use in POE debugging. WARNING This version of this module is certified against POE version 1.300 and above. It will fail on any other POE version. Further, this module requires perl v5.6.1 or above. METHODS new my $api = POE::API::Peek->new(); Returns a blessed reference. Takes no parameters. id my $foo = $api->id(); Obtain the unique id for the kernel. Takes no parameters. Returns a scalar containing a string. KERNEL UTILITIES is_kernel_running if($api->is_kernel_running) { # do stuff... } Tell if the POE Kernel is running and active. Returns 1 if the Kernel is running and 0 if it is not. active_event my $event = $api->active_event(); Get the active event name. Returns a string containing the event name. kernel_memory_size my $size = $api->kernel_memory_size(); Get the memory footprint of the kernel and consequently the entire POE environment. See the Devel::Size documentation for several caveats involved in this metric. event_list my $events = $api->event_list(); Gets the list of events for the whole POE environment. Returns a hash with the session IDs as the keys and a list of events as the values. which_loop my $loop_name = $api->which_loop(); Tell which Loop POE has decided to use. Returns the string name of the Loop module. SESSION UTILITIES current_session my $foo = $api->current_session(); Get the POE::Session object for the currently active session. Takes no parameters. Returns a scalar containing a reference. get_session_children my @children = $api->get_session_children($session_id); my @children = $api->get_session_children(); Get the children (if any) for a given session. Takes one optional parameter, a POE::Session object or ID. If this parameter is not provided, the method defaults to the currently active session. Returns a list of POE::Session objects. is_session_child if($api->is_session_child($parent, $session_id)) { } if($api->is_session_child($parent, $session)) { } if($api->is_session_child($parent)) { } Determine if POE::Session A is a child of POE::Session B. Takes one mandatory parameter, a POE::Session object which is the potential parent session this method will interrogate. Takes one optional parameter, a POE::Session object which is the session whose parentage this method will determine. If this parameter is not specified, it will default to the currently active session. Returns a boolean. get_session_parent my $parent = $api->get_session_parent($session_id); my $parent = $api->get_session_parent($session); my $parent = $api->get_session_parent(); Get the parent for a given session. Takes one optional parameter, a POE::Session object or ID. If this parameter is not provided, the method defaults to the currently active session. Returns a POE::Session object. resolve_session_to_ref my $session = $api->resolve_session_to_ref($session_id); my $session = $api->resolve_session_to_ref(); Obtain a reference to a session given its ID. Takes one optional parameter, a POE::Session ID. If this parameter is not specified, it will default to the currently active session. Returns a reference to a POE::Session object on success; undef on failure. resolve_session_to_id my $session_id = $api->resolve_session_to_id($session); my $session_id = $api->resolve_session_to_id(); Obtain the session id for a given POE::Session object. Takes one optional parameter, a POE::Session object or ID. If this parameter is not specified, it will default to the currently active session. Returns an integer on success and undef on failure. get_session_refcount my $count = $api->get_session_refcount($session_id); my $count = $api->get_session_refcount($session); my $count = $api->get_session_refcount(); Obtain the reference count for a given POE::Session. Takes one optional parameter, a POE::Session object or ID. If this parameter is not specified, it will default to the currently active session. Returns an integer. session_count my $count = $api->session_count(); Obtain a count of how many sessions exist. Takes no parameters. Returns an integer. Note: for various reasons, the Kernel counts as a session. session_list my @sessions = $api->session_list(); Obtain a list of all the sessions that exist. Takes no parameters. Returns a list populated with POE::Session objects. Note: While the Kernel counts as a session, it has been extracted from this list. session_memory_size my $size = $api->session_memory_size(); my $size = $api->session_memory_size($session); my $size = $api->session_memory_size($session_id); Get the memory footprint of a session. If no session is provided, the current session is used. See the Devel::Size documentation for several caveats involved in this metric. session_event_list my @events = $api->session_event_list(); my $events = $api->session_event_list(); my @events = $api->session_event_list($session); my $events = $api->session_event_list($session); my @events = $api->session_event_list($session_id); my $events = $api->session_event_list($session_id); Get the list of events for a session. If no session is provided, the current session is used. ALIAS UTILITIES resolve_alias my $session = $api->resolve_alias($session_alias); Resolve a session alias into a POE::Session object. Takes one mandatory parameter, a session alias. Returns a POE::Session object on success or undef on failure. session_alias_list my @aliases = $api->session_alias_list($session_id); my @aliases = $api->session_alias_list($session); my @aliases = $api->session_alias_list(); Obtain a list of aliases for a POE::Session object. Takes one optional parameter, a POE::Session object or ID. If this parameter is not specified, it will default to the currently active session. Returns a list of strings. session_alias_count my $count = $api->session_alias_count($session_id); my $count = $api->session_alias_count($session); my $count = $api->session_alias_count(); Obtain the count of how many aliases a session has. Takes one optional parameter, a POE::Session object or ID. If this parameter is not specified, it will default to the currently active session. Returns an integer. session_id_loggable my $str = $api->session_id_loggable($session_id); my $str = $api->session_id_loggable($session); my $str = $api->session_id_loggable(); Obtain a loggable version of a session id. Takes one optional parameter, a POE::Session object or ID. If this parameter is not specified, it will default to the currently active session. Returns a string. EVENT UTILITIES # event_count_to {{{ event_count_to my $count = $api->event_count_to($session_id); my $count = $api->event_count_to($session); my $count = $api->event_count_to(); Get the number of events heading toward a particular session. Takes one parameter, a POE::Session object or ID. if none is provided, defaults to the current session. Returns an integer. event_count_from my $count = $api->get_session_extref_count($session_id); my $count = $api->event_count_from($session); my $count = $api->event_count_from(); Get the number of events heading out from a particular session. Takes one parameter, a POE::Session object or ID. If none is provided, defaults to the current session. Return an integer. event_queue my $foo = $api->event_queue(); Access the internal event queue. Takes no parameters. Returns a scalar containing a reference to a POE::Queue::Array object. event_queue_dump my @queue = $api->event_queue_dump(); Dump the contents of the event queue in a nice understandable fashion. Takes no parameters. Returns a list of queue items. Each item is a hash containing the following entries: * ID The id number that POE's queue identifies this entry as. * index The index into the POE::Queue::Array which holds this entry. * priority The priority level this entry has. * event The name of this event * source What caused this event. Usually a POE::Session. * destination Where this event is headed. Usually a POE::Session. * type The type of event this is. May have the value User, _start, _stop, _signal, _garbage_collect, _parent, _child, _sigchld_poll, Alarm, File Activity, or Unknown. EXTREF UTILITIES extref_count my $count = $api->extref_count(); Obtain a count of sessions with extra references. Takes no parameters. Returns an integer. get_session_extref_count my $count = $api->get_session_extref_count($session_id); my $count = $api->get_session_extref_count($session); my $count = $api->get_session_extref_count(); Obtain the number of extra references a session has. Takes one optional parameter, a POE::Session object or ID. If this parameter is not specified, it will default to the currently active session. Returns an integer. FILEHANDLE UTILITIES is_handle_tracked if($api->is_handle_tracked($handle, $mode)) { } Determine if POE is tracking a handle. Takes two mandatory parameters, a filehandle and a mode indicator. Returns a boolean. handle_count my $count = $api->handle_count(); Obtain a count of how many handles POE is tracking. Takes no parameters. Returns an integer. session_handle_count my $count = $api->session_handle_count($session_id); my $count = $api->session_handle_count($session); my $count = $api->session_handle_count(); Obtain a count of the active handles for a given session. Takes one optional parameter, a POE::Session object or ID. If this parameter is not supplied, it will default to the currently active session. PID UTILITIES session_pid_count my $count = $api->session_pid_count($session_id); my $count = $api->session_pid_count($session); my $count = $api->session_pid_count(); Obtain a count of the process IDs being watched by a session. Takes one optional parameter, a POE::Session object or ID. If this parameter is not supplied, it will default to the currently active session. Since 1.350 of POE it is no longer possible to query the number of processes a session is watching. This method is deprecated and will be removed in a future version. SIGNAL UTILITIES POTENTIAL BREAKAGE NOTE: In POE v1.293 (in particular: svn rev 2916) changed the structure of signals. Previously, the data portion of a signal was simply the name of the event to be called. Now it contains a data portion, continuation style arguments that may be passed on to the signal handler. See the POE::Kernel documentation for more info. get_safe_signals my @safe_signals = $api->get_safe_signals(); Obtain a list of signals which it is safe for POE to manipulate. Takes no parameters. Returns a list of strings. get_signal_type my $type = $api->get_signal_type($signal_name); Figure out which type of signal this is. Signals can be one of three types, BENIGN, TERMINAL, NONMASKABLE. The type value returned here, corresponds to subroutine constants SIGTYPE_BENIGN, SIGTYPE_TERMINAL, and SIGTYPE_NONMASKABLE in POE::Kernel's namespace. Takes one mandatory parameter, a signal name. is_signal_watched if($api->is_signal_watched($signal_name)) { } Determine if a signal is being explicitly watched. Takes one mandatory parameter, a signal name. Returns a boolean. signals_watched_by_session my %signals = $api->signals_watched_by_session($session); my %signals = $api->signals_watched_by_session(); Get the signals watched by a session and the events they generate. Takes one optional parameter, a POE::Session object or ID. If this parameter is not supplied, it will default to the currently active session. Returns a hash, with a signal name as the key and the event the session generates as the value. signal_watchers my %watchers = $api->signal_watchers($signal_name); Get a list of the sessions watching a particular signal. Takes one mandatory parameter, a signal name. Returns a hash, keyed by session reference with an event name as the value. is_signal_watched_by_session if($api->is_signal_watched_by_session($signal_name, $session_id)) { } if($api->is_signal_watched_by_session($signal_name, $session)) { } if($api->is_signal_watched_by_session($signal_name)) { } Determine if a given session is explicitly watching a signal. Takes one mandatory parameter, a signal name. Takes one optional parameter, a POE::Session object or ID. If this parameter is not provided, it will default to the currently active session. Returns a boolean. AUTHORS sungo Yuval Kogman Chris 'BinGOs' Williams Philip Gwyn COPYRIGHT AND LICENSE This software is Copyright (c) 2012 by Matt Cashner (sungo). This is free software, licensed under: The (three-clause) BSD License LICENSE100644001751000144 307511703316666 14106 0ustar00chrisusers000000000000POE-API-Peek-2.20This software is Copyright (c) 2012 by Matt Cashner (sungo). This is free software, licensed under: The (three-clause) BSD License The BSD License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Matt Cashner (sungo) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Changes100644001751000144 375211703316666 14376 0ustar00chrisusers000000000000POE-API-Peek-2.20============================== 2012-01-11 14:31:42 +0000 2.20 ============================== commit a2d0a846b4d568b063c104e2a04b6a5f719fe983 Author: Chris 'BinGOs' Williams Date: Wed Jan 11 14:28:30 2012 +0000 Work around session_pid_count() not working in 1.350 of POE Reported as [rt.cpan.org #73393] by Gregor Herrmann of the Debian Perl Group ============================== 2011-08-09 20:34:24 +0100 2.19 ============================== commit 756389048014cd091e68bd62cab3ad5290468bff Author: Chris 'BinGOs' Williams Date: Tue Aug 9 20:33:33 2011 +0100 Fix PID section of documentation ============================== 2011-08-09 20:13:51 +0100 2.18 ============================== commit b1256aa03b5d9450db6f00ec6e9341120d84a6b1 Author: Chris 'BinGOs' Williams Date: Tue Aug 9 20:13:51 2011 +0100 Bump the POE version warning to 1.300 commit 05c83f314b1bc4cf3e433a51d792ee4aeba31f54 Author: Philip Gwyn Date: Tue Aug 9 19:05:06 2011 +0100 [rt.cpan.org #70177] "Many kernel calls need a session ID / session_pid_count" Many kernel calls require a session ID now. They no longer work with a session reference. The included patch converts all kernel calls to using session ID where needed. It also documents and tests this. POE::API::Peek does not wrap _data_sig_pids_ses anywhere. The included patch adds session_pid_count for this. It also documents and tests this. Signed-off-by: Chris 'BinGOs' Williams ============================== 2011-05-27 22:09:56 -0400 2.17 ============================== commit 342c419e64a164f83d4cab8b802aa3701a208109 Author: sungo Date: Fri May 27 22:09:56 2011 -0400 apply BinGO's patch to fix brokennes caused by POE 1.311 ==================================== End of changes in the last 1825 days ==================================== dist.ini100644001751000144 71011703316666 14516 0ustar00chrisusers000000000000POE-API-Peek-2.20name = POE-API-Peek version = 2.20 author = sungo author = Yuval Kogman author = Chris 'BinGOs' Williams author = Philip Gwyn license = BSD copyright_holder = Matt Cashner (sungo) [@Classic] [ReadmeFromPod] [PodPurler] [ChangelogFromGit] file_name = Changes tag_regexp = ^\d max_age = 1825 [GithubMeta] [MetaJSON] [Clean] [Prereqs] POE = 1.311 Devel::Size = 0 Test::More = 0 META.yml100644001751000144 131211703316666 14342 0ustar00chrisusers000000000000POE-API-Peek-2.20--- abstract: 'Peek into the internals of a running POE environment' author: - 'sungo ' - 'Yuval Kogman ' - "Chris 'BinGOs' Williams " - 'Philip Gwyn ' build_requires: {} configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300006, CPAN::Meta::Converter version 2.113640' license: bsd meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: POE-API-Peek requires: Devel::Size: 0 POE: 1.311 Test::More: 0 resources: homepage: https://github.com/bingos/poe-api-peek repository: https://github.com/bingos/poe-api-peek.git version: 2.20 MANIFEST100644001751000144 41211703316666 14202 0ustar00chrisusers000000000000POE-API-Peek-2.20Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini lib/POE/API/Peek.pm t/00-basic.t t/01-session.t t/02-alias.t t/03-event.t t/04-extref.t t/05-filehandle.t t/06-signals.t t/07-kernel.t t/08-pid.t t/release-pod-coverage.t t/release-pod-syntax.t META.json100644001751000144 221011703316666 14510 0ustar00chrisusers000000000000POE-API-Peek-2.20{ "abstract" : "Peek into the internals of a running POE environment", "author" : [ "sungo ", "Yuval Kogman ", "Chris 'BinGOs' Williams ", "Philip Gwyn " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300006, CPAN::Meta::Converter version 2.113640", "license" : [ "bsd" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "POE-API-Peek", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "runtime" : { "requires" : { "Devel::Size" : 0, "POE" : "1.311", "Test::More" : 0 } } }, "release_status" : "stable", "resources" : { "homepage" : "https://github.com/bingos/poe-api-peek", "repository" : { "type" : "git", "url" : "https://github.com/bingos/poe-api-peek.git", "web" : "https://github.com/bingos/poe-api-peek" } }, "version" : "2.20" } t000755001751000144 011703316666 13177 5ustar00chrisusers000000000000POE-API-Peek-2.2008-pid.t100644001751000144 366011703316666 14532 0ustar00chrisusers000000000000POE-API-Peek-2.20/t # Tests for pid related code. See code block labeled "PID Fun" use warnings; use strict; use POE; use Data::Dumper; use Test::More tests => 10; use_ok('POE::API::Peek'); SKIP: { my $ver = $POE::VERSION; $ver =~ s/_.+$//; skip "POE version less than 1.350 required for these tests", 9 unless $ver < '1.350'; my $api = POE::API::Peek->new(); POE::Session->create( inline_states => { _start => \&_start, _stop => \&_stop, dummy => sub {}, }, heap => { api => $api }, ); POE::Kernel->run(); } exit 0; ############################################### sub _start { my $sess = $_[SESSION]; my $api = $_[HEAP]->{api}; my $pid_count = eval { $api->session_pid_count }; ok(!$@, "session_pid_count() causes no exceptions" ); ok( defined $pid_count, "session_pid_count() returns data" ); is( $pid_count, 0, "session_pid_count() knows that this session hasn't registered a PID" ); POE::Session->create( inline_states => { _start => sub { my $new_pid_count = eval { $api->session_pid_count($sess) }; ok(!$@, "session_pid_count(session) causes no exceptions" ); is( $new_pid_count, $pid_count, "session_pid_count(session) knows that this session hasn't registered a PID" ); $new_pid_count = eval { $api->session_pid_count($sess->ID) }; ok(!$@, "session_pid_count(ID) causes no exceptions" ); is( $new_pid_count, $pid_count, "session_pid_count(ID) knows that this session hasn't registered a PID" ); }, _stop => sub {}, } ); $poe_kernel->sig_child( $$ => 'dummy' ); $pid_count = eval { $api->session_pid_count }; is( $pid_count, 1, "session_pid_count() now counts one PID" ); $poe_kernel->sig_child( $$ ); $pid_count = eval { $api->session_pid_count }; is( $pid_count, 0, "session_pid_count() now counts zero" ); } sub _stop { } Makefile.PL100644001751000144 220611703316666 15046 0ustar00chrisusers000000000000POE-API-Peek-2.20 use strict; use warnings; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "Peek into the internals of a running POE environment", "AUTHOR" => "sungo , Yuval Kogman , Chris 'BinGOs' Williams , Philip Gwyn ", "BUILD_REQUIRES" => {}, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "POE-API-Peek", "EXE_FILES" => [], "LICENSE" => "bsd", "NAME" => "POE::API::Peek", "PREREQ_PM" => { "Devel::Size" => 0, "POE" => "1.311", "Test::More" => 0 }, "VERSION" => "2.20", "test" => { "TESTS" => "t/*.t" } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); 00-basic.t100644001751000144 51611703316666 15004 0ustar00chrisusers000000000000POE-API-Peek-2.20/t # Tests for session related api. see code block marked "Session fun". use Test::More tests => 3; use warnings; use strict; use POE; use Data::Dumper; use_ok('POE::API::Peek'); my $api; eval { $api = POE::API::Peek->new(); }; ok(!$@, "new() throws no execptions"); is(ref $api, "POE::API::Peek", "new() returns a Peek object"); 02-alias.t100644001751000144 717711703316666 15050 0ustar00chrisusers000000000000POE-API-Peek-2.20/t # Tests for alias related code. See code block labeled "Alias fun" use Test::More tests => 24; use warnings; use strict; use POE; use Data::Dumper; use_ok('POE::API::Peek'); my $api = POE::API::Peek->new(); POE::Session->create( inline_states => { _start => \&_start, _stop => \&_stop, }, heap => { api => $api }, ); POE::Kernel->run(); ############################################### sub _start { my $sess = $_[SESSION]; my $api = $_[HEAP]->{api}; my $cur_sess; my $sid = $sess->ID; # session_id_loggable {{{ my $log_id; eval { $log_id = $api->session_id_loggable() }; ok(!$@, "session_id_loggable() causes no exceptions"); like($log_id, qr/session $sid/, "session_id_loggable() returns proper string when no alias"); my $new_log_id; eval { $new_log_id = $api->session_id_loggable($sess) }; ok(!$@, "session_id_loggable(session) causes no exceptions"); is($new_log_id, $log_id, "session_id_loggable(session) returns proper string when no alias"); eval { $new_log_id = $api->session_id_loggable($sid) }; ok(!$@, "session_id_loggable(ID) causes no exceptions"); is($new_log_id, $log_id, "session_id_loggable(ID) returns proper string when no alias"); $_[KERNEL]->alias_set('PIE'); $log_id = undef; eval { $log_id = $api->session_id_loggable() }; ok(!$@, "session_id_loggable() causes no exceptions"); like($log_id, qr/session $sid \(PIE/, "session_id_loggable() returns proper string when alias is set"); # }}} # session alias_count {{{ my $alias_count; eval { $alias_count = $api->session_alias_count() }; ok(!$@, "session_alias_count() causes no exceptions"); is($alias_count, 1, "session_alias_count() returns the proper alias count"); POE::Session->create( inline_states => { _start => sub { my $new_alias_count; eval { $new_alias_count = $api->session_alias_count($sess) }; ok(!$@, "session_alias_count(session) causes no exceptions"); is($new_alias_count, $alias_count, "session_alias_count(session) returns the proper alias count"); eval { $new_alias_count = $api->session_alias_count($sid) }; ok(!$@, "session_alias_count(ID) causes no exceptions"); is($new_alias_count, $alias_count, "session_alias_count(ID) returns the proper alias count"); }, _stop => sub {}, } ); # }}} # session_alias_list {{{ my @aliases; eval { @aliases = $api->session_alias_list() }; ok(!$@, "session_alias_list() causes no exceptions"); is(scalar @aliases, 1, 'session_alias_list() returns proper amount of data'); is($aliases[0], 'PIE', 'session_alias_list() returns proper data'); POE::Session->create( inline_states => { _start => sub { my @new_aliases; eval { @new_aliases = $api->session_alias_list($sess) }; ok(!$@, "session_alias_list(session) causes no exceptions"); is_deeply(\@new_aliases, \@aliases, 'session_alias_list(session) returns proper data'); eval { @new_aliases = $api->session_alias_list($sess) }; ok(!$@, "session_alias_list(ID) causes no exceptions"); is_deeply(\@new_aliases, \@aliases, 'session_alias_list(ID) returns proper data'); }, _stop => sub {}, } ); # }}} # resolve_alias {{{ my $session; eval { $session = $api->resolve_alias('PIE') }; ok(!$@, "resolve_alias() causes no exceptions"); is_deeply($session, $sess, "resolve_alias() resolves the provided alias properly"); # }}} } sub _stop { } 03-event.t100644001751000144 756611703316666 15103 0ustar00chrisusers000000000000POE-API-Peek-2.20/t # Tests for event related code. See code block labeled "Event fun" use warnings; use strict; use POE; use Data::Dumper; use Test::More tests => 20; use_ok('POE::API::Peek'); my $api = POE::API::Peek->new(); POE::Session->create( inline_states => { _start => \&_start, _stop => \&_stop, dummy => sub {}, }, heap => { api => $api }, ); POE::Kernel->run(); ############################################### sub _start { my $sess = $_[SESSION]; my $api = $_[HEAP]->{api}; # event_count_to {{{ my $to_count; eval { $to_count = $api->event_count_to() }; ok(!$@, "event_count_to() causes no exceptions"); is($to_count, 0, 'event_count_to() returns proper count'); POE::Session->create( inline_states => { _start => sub { my $new_to_count; eval { $new_to_count = $api->event_count_to($sess) }; ok(!$@, "event_count_to(session) causes no exceptions"); is($new_to_count, $to_count, 'event_count_to(session) returns proper count'); eval { $new_to_count = $api->event_count_to($sess->ID) }; ok(!$@, "event_count_to(ID) causes no exceptions"); is($new_to_count, $to_count, 'event_count_to(ID) returns proper count'); }, _stop => sub {} } ); # }}} # event_count_from {{{ my $from_count; eval { $from_count = $api->event_count_from() }; ok(!$@, "event_count_from() causes no exceptions"); is($from_count, 0, 'event_count_from() returns proper count'); POE::Session->create( inline_states => { _start => sub { my $new_from_count; eval { $new_from_count = $api->event_count_from($sess) }; ok(!$@, "event_count_from(session) causes no exceptions"); is($new_from_count, $from_count, 'event_count_from(session) returns proper count'); eval { $new_from_count = $api->event_count_from($sess->ID) }; ok(!$@, "event_count_from(ID) causes no exceptions"); is($new_from_count, $from_count, 'event_count_from(ID) returns proper count'); }, _stop => sub {} } ); # }}} # event_queue {{{ my $queue; eval { $queue = $api->event_queue() }; ok(!$@, "event_queue() causes no exceptions"); # work around a bug in pre 0.04 releases of POE::XS::Queue::Array. if( ($queue->isa('POE::Queue')) or ($queue->isa('POE::XS::Queue::Array')) ) { pass('event_queue() returns POE::Queue object'); } else { fail('event_queue() returns POE::Queue object'); } # }}} # event_queue_dump {{{ my $ver = $POE::VERSION; $ver =~ s/_.+$//; if($ver >= '0.31') { $_[KERNEL]->yield('dummy'); my @queue; eval { @queue = $api->event_queue_dump() }; ok(!$@, "event_queue_dump() causes no exceptions: $@"); # 3 = GC the temp sessions (2) + our dummy is(scalar @queue, 3, "event_queue_dump() returns the right number of items"); my $item = $queue[-1]; is($item->{type}, 'User', 'event_queue_dump() item has proper type'); is($item->{event}, 'dummy', 'event_queue_dump() item has proper event name'); is($item->{source}, $item->{destination}, 'event_queue_dump() item has proper source and destination'); } else { my @queue; eval { @queue = $api->event_queue_dump() }; ok(!$@, "event_queue_dump() causes no exceptions: $@"); is(scalar @queue, 1, "event_queue_dump() returns the right number of items"); my $item = $queue[0]; is($item->{type}, '_sigchld_poll', 'event_queue_dump() item has proper type'); is($item->{event}, '_sigchld_poll', 'event_queue_dump() item has proper event name'); is($item->{source}, $item->{destination}, 'event_queue_dump() item has proper source and destination'); } # }}} } sub _stop { } 04-extref.t100644001751000144 421611703316666 15245 0ustar00chrisusers000000000000POE-API-Peek-2.20/t # Tests for extref related code. See code block labeled "Extref fun" use Test::More tests => 11; use warnings; use strict; use POE; use Data::Dumper; use_ok('POE::API::Peek'); my $api = POE::API::Peek->new(); POE::Session->create( inline_states => { _start => \&_start, _stop => \&_stop, }, heap => { api => $api }, ); POE::Kernel->run(); ############################################### sub _start { my $sess = $_[SESSION]; my $api = $_[HEAP]->{api}; # extref_count {{{ my $ext_count; eval { $ext_count = $api->extref_count() }; ok(!$@, 'extref_count() does not cause exceptions'); is($ext_count, 0, 'extref_count() returns proper count'); # }}} # get_session_extref_count {{{ my $sess_ext_count; eval { $sess_ext_count = $api->get_session_extref_count() }; ok(!$@, 'get_session_extref_count() does not cause exceptions'); is($sess_ext_count, 0, 'get_session_extref_count() returns proper count'); POE::Session->create( inline_states => { _start => sub { my $new_ext_count; eval { $new_ext_count = $api->get_session_extref_count($sess) }; ok(!$@, 'get_session_extref_count(session) does not cause exceptions'); is($new_ext_count, $sess_ext_count, 'get_session_extref_count(session) returns proper count'); eval { $new_ext_count = $api->get_session_extref_count($sess->ID) }; ok(!$@, 'get_session_extref_count(ID) does not cause exceptions'); is($new_ext_count, $sess_ext_count, 'get_session_extref_count(ID) returns proper count'); $poe_kernel->refcount_increment( $sess->ID, "PIE" ); eval { $ext_count = $api->get_session_extref_count($sess) }; is($ext_count, 1, 'get_session_extref_count() returns adjusted count'); $poe_kernel->refcount_decrement( $sess->ID, "PIE" ); eval { $ext_count = $api->get_session_extref_count($sess) }; is($ext_count, 0, 'get_session_extref_count() returns adjusted count'); }, _stop => sub {}, } ); # }}} } sub _stop { } 07-kernel.t100644001751000144 274111703316666 15234 0ustar00chrisusers000000000000POE-API-Peek-2.20/t use Test::More tests => 11; use warnings; use strict; use POE; use Data::Dumper; use_ok('POE::API::Peek'); my $api = POE::API::Peek->new(); my $sess = POE::Session->create( inline_states => { _start => \&_start, _stop => sub {}, }, heap => { api => $api }, ); POE::Kernel->run(); ############################################### sub _start { my $sess = $_[SESSION]; my $api = $_[HEAP]->{api}; my $cur_sess; ok($api->is_kernel_running, "is_kernel_running() successfully reports that Kernel is in fact running."); is($api->active_event,'_start', "active_event() returns proper event name"); # kernel_memory_size {{{ my $size; eval { $size = $api->kernel_memory_size() }; is($@, '', "kernel_memory_size() causes no exceptions"); # we can't really test this value much since its going to be different on # every system, and even between runs ok(defined $size, "kernel_memory_size() returns data"); ok($size > 0, "kernel_memory_size() returns non-zero value"); # }}} # event_list {{{ my $events; eval { $events = $api->event_list() }; is($@, '', "event_list() causes no exceptions"); is(ref $events, 'HASH', "event_list() returns hashref"); ok(keys %$events, "event_list() returns populated hashref"); my $id = $sess->ID; is_deeply($events, { $id => [ '_start', '_stop' ] }, "event_list() returns correct list of sessions and events"); # }}} is($api->which_loop(), 'POE::Loop::Select', 'which_loop() loop name check'); } 01-session.t100644001751000144 1364411703316666 15455 0ustar00chrisusers000000000000POE-API-Peek-2.20/t # Tests for session related api. see code block marked "Session fun". use Test::More tests => 52; use warnings; use strict; use POE; use Data::Dumper; use_ok('POE::API::Peek'); my $api = POE::API::Peek->new(); POE::Session->create( inline_states => { _start => \&_start, _stop => sub {}, stub => sub {}, }, heap => { api => $api }, ); POE::Kernel->run(); ############################################### sub _start { my $sess = $_[SESSION]; my $api = $_[HEAP]->{api}; my $cur_sess; # current_session() {{{ eval { $cur_sess = $api->current_session() }; ok(!$@, "current_session() causes no execeptions"); ok(defined $cur_sess, "current_session() returns something"); is(ref $cur_sess, 'POE::Session', 'current_session() returns a POE::Session object'); is($cur_sess, $sess, "current_session() returns the RIGHT POE::Session object"); # }}} # resolve_session_to_id {{{ my $id; eval { $id = $api->resolve_session_to_id() }; ok(!$@, "resolve_session_to_id() causes no exceptions"); is($id, $sess->ID, "resolve_session_to_id() returns the proper id"); # }}} # resolve_session_to_ref {{{ my $tmp_sess; eval { $tmp_sess = $api->resolve_session_to_ref($id); }; ok(!$@, "resolve_session_to_ref() causes no exceptions"); is(ref $tmp_sess, 'POE::Session', 'resolve_session_to_ref() returns a POE::Session object'); is($tmp_sess, $sess, "resolve_session_to_ref() returns the RIGHT POE::Session object"); # }}} # get_session_refcount {{{ my $refcnt; eval { $refcnt = $api->get_session_refcount(); }; ok(!$@, "get_session_refcount() causes no exceptions."); ok(defined $refcnt, "get_session_refcount() returns data"); is($refcnt, 0, "get_session_refcount() returned the proper count"); my $new_refcnt; eval { $new_refcnt = $api->get_session_refcount($sess); }; ok(!$@, "get_session_refcount(session) causes no exceptions."); is($new_refcnt, $refcnt, "get_session_refcount(session) returned the proper count"); eval { $new_refcnt = $api->get_session_refcount($sess->ID); }; ok(!$@, "get_session_refcount(ID) causes no exceptions."); is($new_refcnt, $refcnt, "get_session_refcount(ID) returned the proper count"); # }}} # session_count {{{ my $count; eval { $count = $api->session_count(); }; ok(!$@, "session_count() causes no exceptions."); ok(defined $count, "session_count() returns data."); is($count, 2, "session_count() returns the proper count"); #}}} # get_session_children {{{ my @children; eval { @children = $api->get_session_children(); }; ok(!$@, "get_session_children() causes no exceptions."); is(scalar @children, 0, "get_session_children() returns the proper data when there are no children"); POE::Session->create( inline_states => { _start => sub { my $bool; eval { $bool = $api->is_session_child($sess) }; ok(!$@, 'is_session_child() causes no exceptions'); ok($bool, 'is_session_child() correctly determined parentage of session'); my $new_bool; eval { $new_bool = $api->is_session_child($sess->ID) }; ok(!$@, 'is_session_child() causes no exceptions'); ok($bool, 'is_session_child() correctly determined parentage of session'); is($new_bool, $bool, 'is_session_child() correctly determined parentage of session'); }, _stop => sub {}, } ); @children = (); eval { @children = $api->get_session_children(); }; ok(!$@, "get_session_children() causes no exceptions."); is(scalar @children, 1, "get_session_children() returns the proper data when there is a child session"); is(ref $children[0], 'POE::Session', "data returned from get_session_children() contains a valid child session reference"); my @new_children; eval { @new_children = $api->get_session_children($sess->ID); }; ok(!$@, "get_session_children(ID) causes no exceptions."); is_deeply(\@new_children, \@children, "data returned from get_session_children(ID) contains a valid child session reference"); # }}} # get_session_parent {{{ my $parent = eval { $api->get_session_parent }; ok(!$@, "get_session_parent() causes no exceptions."); ok($parent, "parent returned"); is($parent, $poe_kernel, "our parent is the kernel"); my $new_parent = eval { $api->get_session_parent($sess) }; ok(!$@, "get_session_parent(session) causes no exceptions."); is($new_parent, $parent, "our parent is the kernel"); $new_parent = eval { $api->get_session_parent($sess->ID) }; ok(!$@, "get_session_parent(session) causes no exceptions."); is($new_parent, $parent, "our parent is the kernel"); # }}} # session_memory_size {{{ my $size; eval { $size = $api->session_memory_size() }; ok(!$@, "session_memory_size() causes no exceptions"); # we can't really test this value much since its going to be different on # every system, and even between runs ok(defined $size, "session_memory_size() returns data"); ok($size > 0, "session_memory_size() returns non-zero value"); my $new_size; # we grab the size again because Devel::Size adds a bit of new memory to the # session when we call total_size the first time. eval { $size = $api->session_memory_size($cur_sess); $new_size = $api->session_memory_size($cur_sess) }; ok(!$@, "session_memory_size() causes no exceptions"); ok(defined $new_size, "session_memory_size() returns data"); ok($new_size > 0, "session_memory_size() returns non-zero value"); is($new_size, $size, "session_memory_size: memory size matches between runs"); # Now test with session ID eval { $new_size = $api->session_memory_size($cur_sess->ID) }; ok(!$@, "session_memory_size(ID) causes no exceptions"); is($new_size, $size, "session_memory_size(ID): memory size matches between runs"); # }}} # session_event_list {{{ my @events; eval { @events = $api->session_event_list() }; ok(!$@, "session_event_list() causes no exceptions"); ok(scalar @events, "session_event_list() returns data"); ok(scalar @events > 0, "session_event_list() returns more than one value"); is_deeply(\@events, [ '_start','_stop','stub' ], "session_event_list() returns correct list of events"); # }}} } 06-signals.t100644001751000144 1042311703316666 15427 0ustar00chrisusers000000000000POE-API-Peek-2.20/t # Tests for filehandle related code. See code block labeled "Filehandle fun" use Test::More tests => 26; use warnings; use strict; use POE; use Data::Dumper; use_ok('POE::API::Peek'); my $api = POE::API::Peek->new(); POE::Session->create( inline_states => { _start => \&_start, _stop => \&_stop, sig_handler => \&sig_handler, }, heap => { api => $api }, ); POE::Kernel->run(); ############################################### sub _start { my $sess = $_[SESSION]; my $api = $_[HEAP]->{api}; # get_safe_signals {{{ my @safe_signals; eval { @safe_signals = $api->get_safe_signals }; ok(!$@, 'get_safe_signals() does not cause exceptions'); ok(scalar @safe_signals, "get_safe_signals() returns a list"); # }}} # get_signal_type {{{ my $sig_type; eval { $sig_type = $api->get_signal_type('INT'); }; ok(!$@, 'get_signal_type() causes no exceptions'); is($sig_type, &POE::Kernel::SIGTYPE_TERMINAL, 'get_signal_type() returns proper type for SIG INT'); # }}} # is_signal_watched {{{ my $bool2; eval { $bool2 = $api->is_signal_watched('INT') }; ok(!$@, 'is_signal_watched() causes no exceptions'); ok(!$bool2, 'is_signal_watched() correctly returns that INT is not being watched'); $poe_kernel->sig('INT', 'sig_handler'); my $bool3; eval { $bool3 = $api->is_signal_watched('INT') }; ok(!$@, 'is_signal_watched() causes no exceptions'); ok($bool3, 'is_signal_watched() correctly returns that INT is being watched'); # }}} # signals_watched_by_session {{{ my %signals; eval { %signals = $api->signals_watched_by_session() }; ok(!$@, 'signals_watched_by_session() causes no exceptions'); ok(defined $signals{INT}, 'data returned from signals_watched_by_session() correctly indicates that INT is watched by this session'); is($signals{INT}, 'sig_handler', 'data returned from signals_watched_by_session() indicates that INT is being watched by the correct event'); POE::Session->create( inline_states => { _start => sub { my %new_signals; eval { %new_signals = $api->signals_watched_by_session($sess) }; ok(!$@, 'signals_watched_by_session(session) causes no exceptions'); is_deeply(\%new_signals, \%signals, 'data returned from signals_watched_by_session(session) indicates that INT is being watched by the correct event'); eval { %new_signals = $api->signals_watched_by_session($sess->ID) }; ok(!$@, 'signals_watched_by_session(ID) causes no exceptions'); is_deeply(\%new_signals, \%signals, 'data returned from signals_watched_by_session(ID) indicates that INT is being watched by the correct event'); }, _stop => sub {}, } ); # }}} # signal_watchers {{{ my %watchers; eval { %watchers = $api->signal_watchers('INT'); }; ok(!$@, 'signal_watchers() causes no exceptions'); ok(scalar keys %watchers, "signal_watchers() returns data"); ok(defined $watchers{ $sess }, "signal_watchers() notes that this session is watching INT"); is($watchers{ $sess }, 'sig_handler', 'signal_watchers() notes that the proper event from this session is watching INT'); # }}} # is_signal_watched_by_session {{{ my $bool4; eval { $bool4 = $api->is_signal_watched_by_session('INT'); }; ok(!$@, 'is_signal_watched_by_session() causes no exceptions'); ok($bool4, 'is_signal_watched_by_sesion() correctly notes that this session is watching INT'); POE::Session->create( inline_states => { _start => sub { my $new_bool4; eval { $new_bool4 = $api->is_signal_watched_by_session('INT', $sess->ID); }; ok(!$@, 'is_signal_watched_by_session(session) causes no exceptions'); is($new_bool4, $bool4, 'is_signal_watched_by_sesion(session) correctly notes that this session is watching INT'); eval { $new_bool4 = $api->is_signal_watched_by_session('INT', $sess->ID); }; ok(!$@, 'is_signal_watched_by_session(ID) causes no exceptions'); is($new_bool4, $bool4, 'is_signal_watched_by_sesion(ID) correctly notes that this session is watching INT'); }, _stop => sub {}, } ); # }}} } sub sig_handler { } sub _stop { } 05-filehandle.t100644001751000144 343711703316666 16050 0ustar00chrisusers000000000000POE-API-Peek-2.20/t # Tests for filehandle related code. See code block labeled "Filehandle fun" use Test::More tests => 11; use warnings; use strict; use POE; use Data::Dumper; use_ok('POE::API::Peek'); my $api = POE::API::Peek->new(); POE::Session->create( inline_states => { _start => \&_start, _stop => \&_stop, }, heap => { api => $api }, ); POE::Kernel->run(); ############################################### sub _start { my $sess = $_[SESSION]; my $api = $_[HEAP]->{api}; # handle_count {{{ my $handle_count; eval { $handle_count = $api->handle_count() }; ok(!$@, 'handle_count() causes no exceptions'); is($handle_count, 0, 'handle_count() returns proper count'); # }}} # session_handle_count {{{ my $sess_handle_count; eval { $sess_handle_count = $api->session_handle_count() }; ok(!$@, 'session_handle_count() causes no exceptions'); is($sess_handle_count, 0, 'session_handle_count() returns proper count'); my $new_handle_count; eval { $new_handle_count = $api->session_handle_count($sess) }; ok(!$@, 'session_handle_count(session) causes no exceptions'); is($new_handle_count, 0, 'session_handle_count(session) returns proper count'); eval { $new_handle_count = $api->session_handle_count($sess->ID) }; ok(!$@, 'session_handle_count(ID) causes no exceptions'); is($new_handle_count, 0, 'session_handle_count(ID) returns proper count'); # }}} # is_handle_tracked {{{ use IO::Handle; my $io = IO::Handle->new(); $io->fdopen(fileno(STDIN),'r'); my $bool; eval { $bool = $api->is_handle_tracked($io, 'r') }; ok(!$@, "is_handle_tracked() causes no exceptions"); is($bool, 0, 'is_handle_tracked() properly returns that STDIN is not being tracked'); $io->close(); # }}} } sub _stop { } API000755001751000144 011703316666 14536 5ustar00chrisusers000000000000POE-API-Peek-2.20/lib/POEPeek.pm100644001751000144 5713511703316666 16153 0ustar00chrisusers000000000000POE-API-Peek-2.20/lib/POE/APIpackage POE::API::Peek; { $POE::API::Peek::VERSION = '2.20'; } # ABSTRACT: Peek into the internals of a running POE environment use 5.006001; use warnings; use strict; BEGIN { use POE; my $ver = $POE::VERSION; $ver =~ s/_.+$//; if($ver < '1.300') { die(__PACKAGE__." is only certified for POE version 1.300 and up and you are running POE version " . $ver . ". Check CPAN for an appropriate version of ".__PACKAGE__."."); } } use POE; use Devel::Size qw(total_size); $Devel::Size::warn = 0; use Carp; our @CARP_NOT = qw(__PACKAGE__); # new {{{ sub new { my $class = shift; my $self = { broken_event_queue_bitch => 0, }; return bless $self, $class; } # }}} # id() {{{ sub id { return $poe_kernel->ID } # }}} # Kernel fun {{{ # is_kernel_running {{{ sub is_kernel_running { my $kr_run_warning = ${ $poe_kernel->[ POE::Kernel::KR_RUN() ] }; if($kr_run_warning |= POE::Kernel::KR_RUN_CALLED()) { return 1; } else { return 0; } } #}}} # active_event {{{ sub active_event { return ${ $poe_kernel->[ POE::Kernel::KR_ACTIVE_EVENT() ] }; } #}}} # kernel_memory_size {{{ sub kernel_memory_size { return total_size($poe_kernel); } # }}} # event_list {{{ sub event_list { my $self = shift; my %events; foreach my $session_ref (keys %{ $poe_kernel->[ &POE::Kernel::KR_SESSIONS() ] }) { my $session = $poe_kernel->[ &POE::Kernel::KR_SESSIONS() ]->{ $session_ref }->[ &POE::Kernel::SS_SESSION() ]; next if $session->isa('POE::Kernel'); my $id = $session->ID; my @events = sort keys %{ $session->[ &POE::Session::SE_STATES() ] }; $events{ $id } = \@events; } return \%events; } # }}} # which_loop {{{ sub which_loop { return POE::Kernel::poe_kernel_loop(); } #}}} # }}} # Session fun {{{ # current_session {{{ # the value of KR_ACTIVE_SESSION is a ref to a scalar. so we deref it before # handing it to the user. sub current_session { return ${ $poe_kernel->[POE::Kernel::KR_ACTIVE_SESSION] } } # }}} # get_session_children {{{ sub get_session_children { my $self = shift; my $session = shift || $self->current_session(); my $sid = ref $session ? $session->ID : $session; return $poe_kernel->_data_ses_get_children($sid); } # }}} # is_session_child {{{ sub is_session_child { my $self = shift; my $parent = shift or return undef; my $psid = ref $parent ? $parent->ID : $parent; my $session = shift || $self->current_session(); my $sid = ref $session ? $session->ID : $session; return $poe_kernel->_data_ses_is_child($psid, $sid); } # }}} # get_session_parent {{{ sub get_session_parent { my $self = shift; my $session = shift || $self->current_session(); my $sid = ref $session ? $session->ID : $session; return $poe_kernel->_data_ses_get_parent($sid); } # }}} # resolve_session_to_ref {{{ sub resolve_session_to_ref { my $self = shift; my $sid = shift || $self->current_session()->ID; return $poe_kernel->_data_sid_resolve($sid); } # }}} # resolve_session_to_id {{{ sub resolve_session_to_id { my $self = shift; my $session = shift || $self->current_session(); return $poe_kernel->_data_ses_resolve_to_id($session); } # }}} # get_session_refcount {{{ sub get_session_refcount { my $self = shift; my $session = shift || $self->current_session(); my $sid = ref $session ? $session->ID : $session; return $poe_kernel->_data_ses_refcount($sid); } # }}} # session_count {{{ sub session_count { return $poe_kernel->_data_ses_count(); } # }}} # session_list {{{ sub session_list { my @sessions; my $kr_sessions = $POE::Kernel::poe_kernel->[POE::Kernel::KR_SESSIONS]; foreach my $key ( keys %$kr_sessions ) { next if $key =~ /POE::Kernel/; push @sessions, $kr_sessions->{$key}->[0]; } return @sessions; } # }}} # session_memory_size {{{ sub session_memory_size { my $self = shift; my $session = shift || $self->current_session(); $session = $poe_kernel->_data_sid_resolve($session) unless ref $session; return total_size($session); } # }}}} # session_event_list {{{ sub session_event_list { my $self = shift; my $session = shift || $self->current_session(); my @events = sort keys %{ $session->[ &POE::Session::SE_STATES() ] }; if(wantarray) { return @events; } else { return \@events; } } # }}} # }}} # Alias fun {{{ # resolve_alias {{{ sub resolve_alias { my $self = shift; my $alias = shift or return undef; return $poe_kernel->_data_alias_resolve($alias); } # }}} # session_alias_list {{{ sub session_alias_list { my $self = shift; my $session = shift || $self->current_session(); my $sid = ref $session ? $session->ID : $session; return $poe_kernel->_data_alias_list($sid); } # }}} # session_alias_count {{{ sub session_alias_count { my $self = shift; my $session = shift || $self->current_session(); my $sid = ref $session ? $session->ID : $session; return $poe_kernel->_data_alias_count_ses($sid); } # }}} # session_id_loggable {{{ sub session_id_loggable { my $self = shift; my $session = shift || $self->current_session(); my $sid = ref $session ? $session->ID : $session; return $poe_kernel->_data_alias_loggable($sid); } # }}} # }}} # Event fun {{{ sub event_count_to { my $self = shift; my $session = shift || $self->current_session(); my $sid = ref $session ? $session->ID : $session; return $poe_kernel->_data_ev_get_count_to($sid); } #}}} # event_count_from {{{ sub event_count_from { my $self = shift; my $session = shift || $self->current_session(); my $sid = ref $session ? $session->ID : $session; return $poe_kernel->_data_ev_get_count_from($sid); } #}}} # event_queue {{{ sub event_queue { return $poe_kernel->[POE::Kernel::KR_QUEUE] } # }}} # event_queue_dump {{{ sub event_queue_dump { my $self = shift; my $queue = $self->event_queue; my @happy_queue; my @queue = $queue->peek_items(sub { return 1; }); my $i = 0; foreach my $qitem (@queue) { my $item = {}; my ($priority, $id, $payload) = @$qitem; $item->{ID} = $id; $item->{index} = $i++; $item->{priority} = $priority; my $ev_name = $payload->[POE::Kernel::EV_NAME()]; $item->{event} = $ev_name; $item->{source} = $payload->[POE::Kernel::EV_SOURCE]; $item->{destination} = $payload->[POE::Kernel::EV_SESSION]; my $type = $payload->[POE::Kernel::EV_TYPE()]; my $type_str; if ($type & POE::Kernel::ET_START()) { $type_str = '_start'; } elsif ($type & POE::Kernel::ET_STOP()) { $type_str = '_stop'; } elsif ($type & POE::Kernel::ET_SIGNAL()) { $type_str = '_signal'; } elsif ($type & POE::Kernel::ET_GC()) { $type_str = '_garbage_collect'; } elsif ($type & POE::Kernel::ET_PARENT()) { $type_str = '_parent'; } elsif ($type & POE::Kernel::ET_CHILD()) { $type_str = '_child'; } elsif ($type & POE::Kernel::ET_SCPOLL()) { $type_str = '_sigchld_poll'; } elsif ($type & POE::Kernel::ET_ALARM()) { $type_str = 'Alarm'; } elsif ($type & POE::Kernel::ET_SELECT()) { $type_str = 'File Activity'; } else { if($type & POE::Kernel::ET_POST()) { $type_str = 'User'; } elsif ($type & POE::Kernel::ET_CALL()) { $type_str = 'User (not enqueued)'; } else { $type_str = 'Unknown'; } } $item->{type} = $type_str; push @happy_queue, $item; } return @happy_queue; } #}}} # }}} # Extref fun {{{ # extref_count {{{ sub extref_count { return $poe_kernel->_data_extref_count(); } # }}} # get_session_extref_count {{{ sub get_session_extref_count { my $self = shift; my $session = shift || $self->current_session(); my $sid = ref $session ? $session->ID : $session; return $poe_kernel->_data_extref_count_ses($sid); } # }}} # }}} # Filehandles Fun {{{ # is_handle_tracked {{{ sub is_handle_tracked { my($self, $handle, $mode) = @_; return $poe_kernel->_data_handle_is_good($handle, $mode); } # }}} # handle_count {{{ sub handle_count { return $poe_kernel->_data_handle_count(); } # }}} # session_handle_count {{{ sub session_handle_count { my $self = shift; my $session = shift || $self->current_session(); my $sid = ref $session ? $session->ID : $session; return $poe_kernel->_data_handle_count_ses($sid); } # }}} # }}} # PID Fun {{{ # session_pid_count {{{ sub session_pid_count { my $self = shift; my $session = shift || $self->current_session(); my $sid = ref $session ? $session->ID : $session; my $ver = $POE::VERSION; $ver =~ s/_.+$//; if($ver < '1.350') { return $poe_kernel->_data_sig_pids_ses($sid); } carp "session_pid_count() is not available for POE 1.350 and above\n"; return; } # }}} # }}} # Signals Fun {{{ # get_safe_signals {{{ sub get_safe_signals { return $poe_kernel->_data_sig_get_safe_signals(); } # }}} # get_signal_type {{{ sub get_signal_type { my $self = shift; my $sig = shift or return undef; return $poe_kernel->_data_sig_type($sig); } # }}} # is_signal_watched {{{ sub is_signal_watched { my $self = shift; my $sig = shift or return undef; return $poe_kernel->_data_sig_explicitly_watched($sig); } # }}} # signals_watched_by_session {{{ sub signals_watched_by_session { my $self = shift; my $session = shift || $self->current_session(); my $sid = ref $session ? $session->ID : $session; my %sigs = $poe_kernel->_data_sig_watched_by_session($sid); my %ret; foreach my $k (keys %sigs) { my $ev = $sigs{$k}[0]; $ret{$k} = $ev; } return %ret; } # }}} # signal_watchers {{{ sub signal_watchers { my $self = shift; my $sig = shift or return undef; my %sigs = $poe_kernel->_data_sig_watchers($sig); my %ret; foreach my $k (keys %sigs) { my $ev = $sigs{$k}[0]; $ret{$poe_kernel->alias_resolve($k)} = $ev; } return %ret; } # }}} # is_signal_watched_by_session {{{ sub is_signal_watched_by_session { my $self = shift; my $signal = shift or return undef; my $session = shift || $self->current_session(); my $sid = ref $session ? $session->ID : $session; return $poe_kernel->_data_sig_is_watched_by_session($signal, $sid); } # }}} # }}} 1; =pod =head1 NAME POE::API::Peek - Peek into the internals of a running POE environment =head1 VERSION version 2.20 =head1 DESCRIPTION POE::API::Peek extends the POE::Kernel interface to provide clean access to Kernel internals in a cross-version compatible manner. Other calculated data is also available. My intention is to provide massive amounts of internal data for use in POE debugging. =head1 WARNING B B =head1 METHODS =cut =pod =head2 new my $api = POE::API::Peek->new(); Returns a blessed reference. Takes no parameters. =cut =pod =head2 id my $foo = $api->id(); Obtain the unique id for the kernel. Takes no parameters. Returns a scalar containing a string. =cut =pod =head1 KERNEL UTILITIES =cut =pod =head2 is_kernel_running if($api->is_kernel_running) { # do stuff... } Tell if the POE Kernel is running and active. Returns 1 if the Kernel is running and 0 if it is not. =cut =pod =head2 active_event my $event = $api->active_event(); Get the active event name. Returns a string containing the event name. =cut =pod =head2 kernel_memory_size my $size = $api->kernel_memory_size(); Get the memory footprint of the kernel and consequently the entire POE environment. See the Devel::Size documentation for several caveats involved in this metric. =cut =pod =head2 event_list my $events = $api->event_list(); Gets the list of events for the whole POE environment. Returns a hash with the session IDs as the keys and a list of events as the values. =cut =pod =head2 which_loop my $loop_name = $api->which_loop(); Tell which Loop POE has decided to use. Returns the string name of the Loop module. =cut =pod =head1 SESSION UTILITIES =cut =pod =head2 current_session my $foo = $api->current_session(); Get the POE::Session object for the currently active session. Takes no parameters. Returns a scalar containing a reference. =cut =pod =head2 get_session_children my @children = $api->get_session_children($session_id); my @children = $api->get_session_children(); Get the children (if any) for a given session. Takes one optional parameter, a POE::Session object or ID. If this parameter is not provided, the method defaults to the currently active session. Returns a list of POE::Session objects. =cut =pod =head2 is_session_child if($api->is_session_child($parent, $session_id)) { } if($api->is_session_child($parent, $session)) { } if($api->is_session_child($parent)) { } Determine if POE::Session A is a child of POE::Session B. Takes one mandatory parameter, a POE::Session object which is the potential parent session this method will interrogate. Takes one optional parameter, a POE::Session object which is the session whose parentage this method will determine. If this parameter is not specified, it will default to the currently active session. Returns a boolean. =cut =pod =head2 get_session_parent my $parent = $api->get_session_parent($session_id); my $parent = $api->get_session_parent($session); my $parent = $api->get_session_parent(); Get the parent for a given session. Takes one optional parameter, a POE::Session object or ID. If this parameter is not provided, the method defaults to the currently active session. Returns a POE::Session object. =cut =pod =head2 resolve_session_to_ref my $session = $api->resolve_session_to_ref($session_id); my $session = $api->resolve_session_to_ref(); Obtain a reference to a session given its ID. Takes one optional parameter, a POE::Session ID. If this parameter is not specified, it will default to the currently active session. Returns a reference to a POE::Session object on success; undef on failure. =cut =pod =head2 resolve_session_to_id my $session_id = $api->resolve_session_to_id($session); my $session_id = $api->resolve_session_to_id(); Obtain the session id for a given POE::Session object. Takes one optional parameter, a POE::Session object or ID. If this parameter is not specified, it will default to the currently active session. Returns an integer on success and undef on failure. =cut =pod =head2 get_session_refcount my $count = $api->get_session_refcount($session_id); my $count = $api->get_session_refcount($session); my $count = $api->get_session_refcount(); Obtain the reference count for a given POE::Session. Takes one optional parameter, a POE::Session object or ID. If this parameter is not specified, it will default to the currently active session. Returns an integer. =cut =pod =head2 session_count my $count = $api->session_count(); Obtain a count of how many sessions exist. Takes no parameters. Returns an integer. Note: for various reasons, the Kernel counts as a session. =cut =pod =head2 session_list my @sessions = $api->session_list(); Obtain a list of all the sessions that exist. Takes no parameters. Returns a list populated with POE::Session objects. Note: While the Kernel counts as a session, it has been extracted from this list. =cut =pod =head2 session_memory_size my $size = $api->session_memory_size(); my $size = $api->session_memory_size($session); my $size = $api->session_memory_size($session_id); Get the memory footprint of a session. If no session is provided, the current session is used. See the Devel::Size documentation for several caveats involved in this metric. =cut =pod =head2 session_event_list my @events = $api->session_event_list(); my $events = $api->session_event_list(); my @events = $api->session_event_list($session); my $events = $api->session_event_list($session); my @events = $api->session_event_list($session_id); my $events = $api->session_event_list($session_id); Get the list of events for a session. If no session is provided, the current session is used. =cut =pod =head1 ALIAS UTILITIES =cut =pod =head2 resolve_alias my $session = $api->resolve_alias($session_alias); Resolve a session alias into a POE::Session object. Takes one mandatory parameter, a session alias. Returns a POE::Session object on success or undef on failure. =cut =pod =head2 session_alias_list my @aliases = $api->session_alias_list($session_id); my @aliases = $api->session_alias_list($session); my @aliases = $api->session_alias_list(); Obtain a list of aliases for a POE::Session object. Takes one optional parameter, a POE::Session object or ID. If this parameter is not specified, it will default to the currently active session. Returns a list of strings. =cut =pod =head2 session_alias_count my $count = $api->session_alias_count($session_id); my $count = $api->session_alias_count($session); my $count = $api->session_alias_count(); Obtain the count of how many aliases a session has. Takes one optional parameter, a POE::Session object or ID. If this parameter is not specified, it will default to the currently active session. Returns an integer. =cut =pod =head2 session_id_loggable my $str = $api->session_id_loggable($session_id); my $str = $api->session_id_loggable($session); my $str = $api->session_id_loggable(); Obtain a loggable version of a session id. Takes one optional parameter, a POE::Session object or ID. If this parameter is not specified, it will default to the currently active session. Returns a string. =cut =pod =head1 EVENT UTILITIES # event_count_to {{{ =head2 event_count_to my $count = $api->event_count_to($session_id); my $count = $api->event_count_to($session); my $count = $api->event_count_to(); Get the number of events heading toward a particular session. Takes one parameter, a POE::Session object or ID. if none is provided, defaults to the current session. Returns an integer. =cut =pod =head2 event_count_from my $count = $api->get_session_extref_count($session_id); my $count = $api->event_count_from($session); my $count = $api->event_count_from(); Get the number of events heading out from a particular session. Takes one parameter, a POE::Session object or ID. If none is provided, defaults to the current session. Return an integer. =cut =pod =head2 event_queue my $foo = $api->event_queue(); Access the internal event queue. Takes no parameters. Returns a scalar containing a reference to a POE::Queue::Array object. =cut =pod =head2 event_queue_dump my @queue = $api->event_queue_dump(); Dump the contents of the event queue in a nice understandable fashion. Takes no parameters. Returns a list of queue items. Each item is a hash containing the following entries: =over 4 =item * ID The id number that POE's queue identifies this entry as. =item * index The index into the POE::Queue::Array which holds this entry. =item * priority The priority level this entry has. =item * event The name of this event =item * source What caused this event. Usually a POE::Session. =item * destination Where this event is headed. Usually a POE::Session. =item * type The type of event this is. May have the value User, _start, _stop, _signal, _garbage_collect, _parent, _child, _sigchld_poll, Alarm, File Activity, or Unknown. =back =cut =pod =head1 EXTREF UTILITIES =cut =pod =head2 extref_count my $count = $api->extref_count(); Obtain a count of sessions with extra references. Takes no parameters. Returns an integer. =cut =pod =head2 get_session_extref_count my $count = $api->get_session_extref_count($session_id); my $count = $api->get_session_extref_count($session); my $count = $api->get_session_extref_count(); Obtain the number of extra references a session has. Takes one optional parameter, a POE::Session object or ID. If this parameter is not specified, it will default to the currently active session. Returns an integer. =cut =pod =head1 FILEHANDLE UTILITIES =cut =pod =head2 is_handle_tracked if($api->is_handle_tracked($handle, $mode)) { } Determine if POE is tracking a handle. Takes two mandatory parameters, a filehandle and a mode indicator. Returns a boolean. =cut =pod =head2 handle_count my $count = $api->handle_count(); Obtain a count of how many handles POE is tracking. Takes no parameters. Returns an integer. =cut =pod =head2 session_handle_count my $count = $api->session_handle_count($session_id); my $count = $api->session_handle_count($session); my $count = $api->session_handle_count(); Obtain a count of the active handles for a given session. Takes one optional parameter, a POE::Session object or ID. If this parameter is not supplied, it will default to the currently active session. =cut =pod =head1 PID UTILITIES =cut =pod =head2 session_pid_count my $count = $api->session_pid_count($session_id); my $count = $api->session_pid_count($session); my $count = $api->session_pid_count(); Obtain a count of the process IDs being watched by a session. Takes one optional parameter, a POE::Session object or ID. If this parameter is not supplied, it will default to the currently active session. Since 1.350 of L it is no longer possible to query the number of processes a session is watching. This method is deprecated and will be removed in a future version. =cut =pod =head1 SIGNAL UTILITIES POTENTIAL BREAKAGE NOTE: In POE v1.293 (in particular: svn rev 2916) changed the structure of signals. Previously, the data portion of a signal was simply the name of the event to be called. Now it contains a data portion, continuation style arguments that may be passed on to the signal handler. See the L documentation for more info. =cut =pod =head2 get_safe_signals my @safe_signals = $api->get_safe_signals(); Obtain a list of signals which it is safe for POE to manipulate. Takes no parameters. Returns a list of strings. =cut =pod =head2 get_signal_type my $type = $api->get_signal_type($signal_name); Figure out which type of signal this is. Signals can be one of three types, BENIGN, TERMINAL, NONMASKABLE. The type value returned here, corresponds to subroutine constants SIGTYPE_BENIGN, SIGTYPE_TERMINAL, and SIGTYPE_NONMASKABLE in POE::Kernel's namespace. Takes one mandatory parameter, a signal name. =cut =pod =head2 is_signal_watched if($api->is_signal_watched($signal_name)) { } Determine if a signal is being explicitly watched. Takes one mandatory parameter, a signal name. Returns a boolean. =cut =pod =head2 signals_watched_by_session my %signals = $api->signals_watched_by_session($session); my %signals = $api->signals_watched_by_session(); Get the signals watched by a session and the events they generate. Takes one optional parameter, a POE::Session object or ID. If this parameter is not supplied, it will default to the currently active session. Returns a hash, with a signal name as the key and the event the session generates as the value. =cut =pod =head2 signal_watchers my %watchers = $api->signal_watchers($signal_name); Get a list of the sessions watching a particular signal. Takes one mandatory parameter, a signal name. Returns a hash, keyed by session reference with an event name as the value. =cut =pod =head2 is_signal_watched_by_session if($api->is_signal_watched_by_session($signal_name, $session_id)) { } if($api->is_signal_watched_by_session($signal_name, $session)) { } if($api->is_signal_watched_by_session($signal_name)) { } Determine if a given session is explicitly watching a signal. Takes one mandatory parameter, a signal name. Takes one optional parameter, a POE::Session object or ID. If this parameter is not provided, it will default to the currently active session. Returns a boolean. =head1 AUTHORS sungo Yuval Kogman Chris 'BinGOs' Williams Philip Gwyn =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2012 by Matt Cashner (sungo). This is free software, licensed under: The (three-clause) BSD License =cut __END__ # sungo // vim: ts=4 sw=4 noet release-pod-syntax.t100644001751000144 45011703316666 17227 0ustar00chrisusers000000000000POE-API-Peek-2.20/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); release-pod-coverage.t100644001751000144 76511703316666 17505 0ustar00chrisusers000000000000POE-API-Peek-2.20/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Pod::Coverage 1.08"; plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" if $@; eval "use Pod::Coverage::TrustPod"; plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" if $@; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' });