Showing posts with label Template::ShowStartStop. Show all posts
Showing posts with label Template::ShowStartStop. Show all posts

Jun 4, 2010

Using ref to fix 5 year old bug

So I haven't been hacking perl for 5 (or more) years but I forked Template::ShowStartStop from Template::Timer which is that old. since I forked it this test has bugged me since I didn't really understand the test, the section of code it referred to or the actual problem.

This is an approximation of the error you'd get.
Couldn't render template "undef error - Can't call method "name" on
unblessed reference at /usr/lib/perl5/site_perl/5.8.0/Template/Timer.pm line
66. "
This error is actually a copy from bug #15457 but I happen to know it's basically the same error you'd get with an eval.

So what's the problem? can you spot it? ( original timer code )

Ugh! That's ugly, let's take a cue from Perl Best Practices and format it as a tabular ternary instead. Now we can read it...

Bug #13225 suggests a problem with eval and the following fix (which I translated into something more similar to the current code).

well that should fix our eval problem... since an eval will be a reference of type SCALAR. but what happens if it's a reference not of type ARRAY or SCALAR? then we'll still get that error.

According to the ref function documentation
If the referenced object has been blessed into a package, then that package name is returned instead. You can think of ref as a typeof operator.
what this means is I could check what type of object it was that I was normally getting. In order to do this I put $what into the output I get. I found out that most of the time $what is a Template::Document. So now I optimized my code for that situation.

See the thing is that we really don't want $what->name method to be called unless it's a Template::Document which actually has that method. I'm not sure that I'm not missing any tests at this point, but I'm pretty confident that, at least, this kind of bug won't crash my module anymore.

Mar 13, 2010

Iron Man and introductions

So I've decided to "compete" in the Iron Man competition.

My name is Caleb Cushing, I'm a 25 year old, unemployed, student, living in the Greater Lansing, MI, USA, area. I've been programming perl for approximately 6 months. This includes a lot of off time, time to relearn the language from the class I took a couple years ago (and learn modern perl), learning Catalyst and DBIC, all of which is an ongoing process. I would guess I've been writing useful code for about 4 months and even that is a slow going process as I've still got a lot to learn.

Previously, I was the tree maintainer for Funtoo, and tried spinning my own fork of Funtoo/Gentoo, it needed more devs than me to survive though. I now use Arch Linux. After an arch/perl user who went by aCiD2 moved to OS X I adopted most of his perl AUR (arch user repository) packages in addition to ones I had created myself. I now have over 200 CPAN packages on AUR in Arch's PKGBUILD format.

I'm a contributer to Catalyst::Manual and I created Template::ShowStartStop by forking Template::Timer.

I'm sure I'll become more active as time goes on, and have more interesting posts than this one.