[Omaha.pm] Debugger (or Carp?): How can I detect the creation of a key in a hash object?

Jay Hannah jhannah at omnihotels.com
Thu Jul 6 16:36:36 PDT 2006


Wow. Got it. tie'd that hash to JayDebug subclass (see previous email),
ran the program and POW!:

---
key [INBOUND] is being set to [HASH(0x8c338dc)] at
/usr/lib/perl5/site_perl/Omni/MVC/JayDebug.pm line 7
        JayDebug::STORE('JayDebug=HASH(0x8bdd9b8)', 'INBOUND',
'HASH(0x8c338dc)') called at
/usr/lib/perl5/site_perl/Omni/MVC/Control/Multiplex/Buffers.pm line 359
 
Control::Multiplex::Buffers::process_backlog('Control::Multiplex::Buffer
s=HASH(0x8bdd91c)', 'INBOUND') called at
/usr/lib/perl5/site_perl/Omni/MVC/Control/Multiplex/Buffers.pm line 334
 
Control::Multiplex::Buffers::write('Control::Multiplex::Buffers=HASH(0x8
bdd91c)', 'INBOUND',
'D00181HDRA2|GDSWB|SGAR7|HRSOM|IAT857114|GMT061542|MSN1801485A...')
called at /usr/lib/perl5/site_perl/Omni/MVC/Control/Multiplex.pm line
460
        Control::Multiplex::write('Control::Multiplex=HASH(0x8bdd850)',
'INBOUND',
'D00181HDR2|GDSWB|SGAR7|HRSOM|IAT857114|GMT061542|MSN1801485A...')
called at /usr/lib/perl5/site_perl/Omni/MVC/Model/Pegasus/Comserver.pm
line 199
 
Model::Pegasus::Comserver::read('Model::Pegasus::Comserver=HASH(0x8b7c82
8)', 'PALS-2', 'Control::Multiplex::Payload::USW=HASH(0x8c33654)')
called at /usr/lib/perl5/site_perl/Omni/MVC/Control/Multiplex.pm line
636
        Control::Multiplex::_read('Control::Multiplex=HASH(0x8bdd850)',
'FileHandle=GLOB(0x8c24160)',
'Control::Multiplex::Payload::USW=HASH(0x8c33654)') called at
/usr/lib/perl5/site_perl/Omni/MVC/Control/Multiplex/Buffer.pm line 139
 
Control::Multiplex::Buffer::mux_input('Control::Multiplex::Buffer::FIFO=
HASH(0x8c24268)', 'IO::Multiplex=HASH(0x8bdde14)',
'FileHandle=GLOB(0x8c24160)', 'SCALAR(0x8c23c5c)') called at
/usr/lib/perl5/site_perl/5.8.7/IO/Multiplex.pm line 631
        IO::Multiplex::loop('IO::Multiplex=HASH(0x8bdde14)') called at
/usr/lib/perl5/site_perl/Omni/MVC/Control/Multiplex.pm line 573
        Control::Multiplex::loop('Control::Multiplex=HASH(0x8bdd850)')
called at /usr/lib/perl5/site_perl/Omni/MVC/Model/Pegasus/Comserver.pm
line 216
 
Model::Pegasus::Comserver::run('Model::Pegasus::Comserver=HASH(0x8b7c828
)') called at com.pl line 59
---

That's the most beautiful chunk of garbledygook I've seen today. :)

Buffers.pm line 359 was indeed my problem. I fixed the bug by adding the
top test:

   unless (exists $self->{outbound}->{$label}) {
      # This isn't even an outbound label! You can't process the backlog
on this
      # label!    DO NOT DELETE these 3 lines. The test below this one
will autovivify
      # {outbound}->{$label} into existance if you get rid of this
block. That's
      # very bad, and will cause com.pl to die elsewhere. -jhannah
20060706
      return undef;
   }
   unless (exists $self->{outbound}->{$label}->{waiting_to_be_sent}) {
      # No backlog exists.
      return undef;
   }

And here's a debugger demo of the bug behavior:

---
main::(j2.pl:2):        my $j = { a => {} };
   DB<2> n
main::(j2.pl:3):        if (exists $j->{a}->{b}->{c}) {
   DB<2> n
main::(j2.pl:7):        exit;
   DB<2> x $j
0  HASH(0x823f04c)
   'a' => HASH(0x823f064)
      'b' => HASH(0x823f034)
           empty hash
---

Wow. I sort of understand tie's now. :)  I wonder, historically, how
Perl ended up with tie's and its OO model (bless, etc.)? Lots of overlap
there? TIMTOWTDI indeed.

j


More information about the Omaha-pm mailing list