More perl debuggin

I’ve been figuring out more about the perl debugger.  Specifically the watch command now.  At first I thought it was a fairly lame command but it looks like it has more potential than I realised, or at the very least it was instrumental in me figuring out a weird problem we were having with our Catalyst application.

When we took a look at our app’s module version number it came back as 0.00001 despite it plainly being something different.  When we build the module using Module::Install it created the package with the correct version number.  It wasn’t until we tried to display the version number on our pages that we realised everything else thought the version number was 0.00001.  Even a perl -I lib -MCompany::AppName\ 9999 displayed 0.00001.

In the end I loaded up the debugger and added a watch on $Company::AppName::VERSION to see what was happening.

DB<2> w $Company::AppName::VERSION
DB<3> c
Watchpoint 0:   $Company::AppName::VERSION changed:
 old value:  ''
 new value:  '1.01'
10: Company::AppName::Builder->new( appname => __PACKAGE__ )->bootstrap;

DB<3> c
Watchpoint 0:   $Company::AppName::VERSION changed:
 old value:  '1.01'
 new value:  '0.00001'
67:     ${ $package_name . '::AUTHORITY' } = $authority if defined $authority;

DB<3> T
. = Class::MOP::Module::_instantiate_module(ref(Moose::Meta::Class), 0.00001, undef)
$ = Class::MOP::Class::create('Moose::Meta::Class', 'Company::AppName', 'superclasses', ref(ARRAY), 'version', 0.00001)
$ = Moose::Meta::Class::create('Moose::Meta::Class', 'Company::AppName', 'version', 0.00001, 'superclasses', ref(ARRAY))
. = CatalystX::AppBuilder::BUILD(ref(Company::AppName::Builder), ref(HASH))
. = Class::MOP::Method::execute(ref(Moose::Meta::Method), ref(Company::AppName::Builder), ref(HASH))
. = Moose::Object::BUILDALL(ref(Company::AppName::Builder), ref(HASH))
$ = Moose::Meta::Class::new_object(ref(Moose::Meta::Class), ref(HASH))

With the watchpoint installed as soon as the debugger loaded it was possible to see our version number being set, then see it being overwritten with the bogus value.  Each time the value changed the debugger stopped.  The second time I did a stack trace and a little investigation showed the new value was coming from CatalystX::AppBuilder.  We’re using that module to build our apps and it turns out that want you to set a version number and it will set that on your module.  If you don’t specify it you get it’s default 0.00001.  All we need to do is change our builder line to specify the version and our module version is preserved.

Company::AppName::Builder->new( appname => __PACKAGE__, version => $VERSION )->bootstrap;

I had thought watches were only really useful in a local scope when you were perhaps watching a loop to check what was happening with your variables, more as a way to save typing x, but it looks like it’s a lot more useful.

The main thing I haven’t managed to figure out yet is how to keep track of a variable that doesn’t have a globally accessible handle and gets passed about a lot.  Being able to spot changes in that type of variable would be really handy.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s