| 1 | package POE::Component::Proxy::TCP::PoeDebug; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | require Exporter; | |||||||||
| 6 | 2 | @ISA = qw(Exporter); | |||||||||
| 7 | 2 | @EXPORT = qw(set_level get_level dbprint | |||||||||
| 8 | ); | ||||||||||
| 9 | |||||||||||
| 10 | 2 | $VERSION = '0.01'; | |||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use POE; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | # Debugging utils for proxy module tester | ||||||||||
| 15 | # Andrew V. Purshottam 17 Jun 2004 | ||||||||||
| 16 | # to do: | ||||||||||
| 17 | # - evolve this into proper module with exporter and other crap (done) | ||||||||||
| 18 | # - create kind of shared poe utils for your poe stuff. | ||||||||||
| 19 | # - move design discussion and debugging levels into a POD | ||||||||||
| 20 | # - create symbolic constants for levels. | ||||||||||
| 21 | |||||||||||
| 22 | # dbprint is designed to run from inside or outside | ||||||||||
| 23 | # a poe session, with or without a $heap->{self}->{name} | ||||||||||
| 24 | # I really do not understand Perl and POE well enough | ||||||||||
| 25 | # to write a good debug print subroutine, if you have better one | ||||||||||
| 26 | # _that works nicely with POE sessions_, please | ||||||||||
| 27 | # mail it to me or submit it against this source | ||||||||||
| 28 | # as a feature improvement (once I get this crap up | ||||||||||
| 29 | # on source forge or similar.) | ||||||||||
| 30 | |||||||||||
| 31 | # debug levels | ||||||||||
| 32 | # -1 - not used as arg to dbprint, so used as debug level means print nothing ever. | ||||||||||
| 33 | # 0 - error, print even when not debugging | ||||||||||
| 34 | # 1 - lifecycle trace events, generally only happen once | ||||||||||
| 35 | # 2 - per "line" or user event type events | ||||||||||
| 36 | # 3 - repeated stuff that can happen many times per run | ||||||||||
| 37 | # 4 - per character or similar can happen lots of times (eg per char) | ||||||||||
| 38 | # 5-20 - tedious inner loop of algorithm or nasty dumps | ||||||||||
| 39 | # 100 - only turn on in emergency lots of crap, recursive dump of strutures | ||||||||||
| 40 | |||||||||||
| 41 | # dbprint($level_num, exp ...) - print debugging info | ||||||||||
| 42 | 2 | $main::debug_level = 0; # shutup by default. | |||||||||
| 43 | |||||||||||
| 44 | 1 | ▶ | sub set_level{ | ||||||||
|
Subroutine
set_level: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 45 | 1 | my $level = shift; | |||||||||
| 46 | 1 | $main::debug_level = $level; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | sub get_level { | ||||||||
|
Subroutine
get_level: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 50 | 0 | return $main::debug_level; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | |||||||||||
| 54 | # dbprint($level, $string1, $String2, ...) print strings | ||||||||||
| 55 | # with helpful context prefix if $level <= $main::debug_level | ||||||||||
| 56 | 302 | ▶ | sub dbprint { | ||||||||
|
Subroutine
dbprint: called CC=9 SCAR=43.1
Pod
undocumented
| |||||||||||
| 57 | 302 | my $level = shift; | |||||||||
| 58 | 302 | ▶ | return unless $level <= $main::debug_level; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | # yeah this context grabbing crap is awful, maybe someday | ||||||||||
| 60 | # I will make more beautiful, or maybe a decent perl OO / introspection | ||||||||||
| 61 | # system will make it unnecessary (as it is almost in python). | ||||||||||
| 62 | 0 | my ($kernel, $session, $session_id, $alias, $heap, $self, $type, $name); | |||||||||
| 63 | 0 | my $info_string = "trace:"; | |||||||||
| 64 | 0 | $kernel = $poe_kernel; | |||||||||
| 65 | 0 | ▶ | if (defined $kernel) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | $info_string = "POE trace:"; | |||||||||
| 67 | 0 | $session = $kernel->get_active_session(); | |||||||||
| 68 | 0 | ▶ | if (defined $session) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | $session_id = $session->ID; | |||||||||
| 70 | 0 | $info_string .= "ses:$session_id:"; | |||||||||
| 71 | 0 | my @aliases = $kernel->alias_list( $session ); | |||||||||
| 72 | 0 | ▶ | if (@aliases) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 0 | $alias = $aliases[0]; | |||||||||
| 74 | 0 | $info_string .= "$alias:"; | |||||||||
| 75 | } | ||||||||||
| 76 | 0 | $heap = $session->get_heap(); | |||||||||
| 77 | 0 | ▶ | if (defined $heap) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | ▶ | if (exists($heap->{self})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | $self = $heap->{self}; | |||||||||
| 80 | 0 | $type = ref($self); | |||||||||
| 81 | 0 | $info_string .= "$type:"; | |||||||||
| 82 | 0 | ▶ | if (exists($self->{name})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | $name = $self->{name}; | |||||||||
| 84 | 0 | $info_string .= "$name:"; | |||||||||
| 85 | } | ||||||||||
| 86 | } | ||||||||||
| 87 | } | ||||||||||
| 88 | } | ||||||||||
| 89 | } else { | ||||||||||
| 90 | 0 | $info_string = "outside POE:"; | |||||||||
| 91 | } | ||||||||||
| 92 | 0 | print $info_string, " "; | |||||||||
| 93 | 0 | foreach my $x (@_) { | |||||||||
| 94 | 0 | print $x; | |||||||||
| 95 | } | ||||||||||
| 96 | 0 | print "\n"; | |||||||||
| 97 | |||||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 2 | 1; | |||||||||
| 101 | |||||||||||
| 102 | __END__ | ||||||||||