hook phase debugging must traverse to find line number

igotimac at gmail.com igotimac at gmail.com
Mon Nov 3 17:59:57 UTC 2008

Reviewers: djabberd,

Extra logging was added in:


This new logging makes calls to B::svref_2object, which is apparently
some part of the perl compile that allows you to traverse the call stack
and figure out who called you.

Example debug output:

For phase [PresenceCheck] invoking hook 1 of 2 defined at:

There seems to be a problem however in some cases.  I'm not exactly sure
why.  But in some case:


returns the correct line number



causes an error: (Can't locate object method "first" via package

Example callback of this case:

For phase [AlterPresenceAvailable] invoking hook 3 of 3 defined at:

So, it seems that instead of blindly calling
'$cv->ROOT->first->first->line', the code needs to traverse these
B::LISTOP objects to the proper depth to find a B::COP object from which
we can get the line number.

Please review this at http://codereview.appspot.com/7732

Affected files:

Index: lib/DJabberd/VHost.pm
--- lib/DJabberd/VHost.pm	(revision 819)
+++ lib/DJabberd/VHost.pm	(working copy)
@@ -259,9 +259,13 @@
              # the filename. This gives us both the filename and line  
number it's defined
              # on, giving the user a very clear pointer to which subref  
will be invoked --kane
              my $cv = B::svref_2object($hk);
+            my $bcop = $cv->ROOT->first;
+            while(! $bcop->isa("B::COP")){
+              $bcop = $bcop->first;
+            }
                  "For phase [@$phase] invoking hook $depth of $hook_count  
defined at: ".
-                $cv->FILE .':'. $cv->ROOT->first->first->line
+                $cv->FILE .':'. $bcop->line

More information about the Djabberd mailing list