Friday, January 02, 2015

My First Day on the CPAN Pull Request Challenge

So yesterday, I started on the CPAN Pull Request Challenge. I was assigned the module Devel::StackTrace::WithLexicals, so, I read the doc and installed it.

The doc references two other modules’ influence: Devel::StackTrace and PadWalker

So I figured I’d have a look at those first. Combining two examples from the doc for Devel::StackTrace, I wrote this:


use strict;
use warnings;

use Devel::StackTrace;

sub foo {

sub bar {
    my $trace = Devel::StackTrace->new();
    print $trace->as_string(); # like carp


Which gave me this:

$ ./
Trace begun at line 13
main::bar('bing', 1234) called at line 9
main::foo('bing') called at line 17


Next I looked at the doc for PadWalker. Based on the example provided, I wrote:


use strict;
use warnings;

use PadWalker qw(peek_my);

sub foo {
    my $abc = 123;


    print "magic! $abc\n";

sub bar {
    my $h = peek_my(1);


Which yields:

$ ./
magic! 124

So bar() increments foo()’s lexical variable $abc. What kind of witchcraft is this?!?

These are both very interesting modules. Changing lexicals from another scope defeats the purpose of a lexical, but as the doc points out, it can be useful for debugging purposes.

I reviewed the documentation for Devel::StackTrace::WithLexicals and the code, both of which can be viewed online at meta::cpan. In the left column are the links “Source (raw)” and “Browse (raw)” which are both handy to use when viewing the source.

Nothing immediately jumped out at me after reviewing the pull request ideas so I decided to contact the author to see if he had anything specific he’d like to see done. The author’s contact info is usually provided in the Author section of the documentation.

This is the email I sent:


I have volunteered in the CPAN Pull Request Challenge
and have been assigned your module Devel::StackTrace::WithLexicals to
contribute to if possible.

Ideas include, but aren't limited to:

I'd like to know if you are receptive to contributions to this module and if
you had any particular needs or wishes.  I am willing to contribute with any
aspect (features, bugs, testing, documentation, etc.)  If you are ok with
contributions (pending your approval of course) but you don't have anything
specific in mind, I will review the PR Ideas list myself and see if I can find
a way to contribute.

Thank you,
David M. Bradford

This morning I received a positive response from the author. Time to get to work!

1 comment:

Maxim Vuets said...

Thanks for the nice write up. I like the way you demonstrate a module you've got. Very good attitude, keep it up! (-: