Mocking LWP::UserAgent properly

This is an update to an earlier post I wrote about the adventures I had in creating and using a mock LWP::UserAgent for testing purposes. The ever-vigilant mst overheard a conversation on the same topic, and jumped in. He pointed out that Test::MockObject (and everything using it) overrides UNIVERSAL::isa in a way that hides bugs. Because it can hide bugs, it is definitely not safe to use in a test suite, where you're trying to uncover bugs.

The bottom line

Instead of following my earlier advice, use Test::LWP::UserAgent, a new module which avoids Test::MockObject and offers a better interface (in particular, the nonsense with subtypes is no longer needed) for creating and using mock LWP::UserAgent objects.

On studying programming and programmers

In university, we do a lot of waterfall in courses with project work. It isn't the kind of thing a student would do (to) themselves, so professors feel obligated to give us that experience in class. Research shows that both business and recent graduates wish they'd been taught agile development methodologies in university and college, but course content always lags behind.

At Pythian, we used a mostly-Scrum methodology, with all the benefits and challenges that entails. Read more »

Introducing File::Symlink::Atomic

In Tips & tricks from my 4 months at Pythian, I showed how to give a symlink a new target atomically. I wasn't aware of any module to encapsulate that, so I quickly put together File::Symlink::Atomic.

This module is useful because it eliminates the need to know how to do this safely - simply

use File::Symlink::Atomic

and you get a drop-in replacement for CORE::symlink. It creates a temporary symlink (using File::Temp to get a unique pathname) pointing to your new target, then moves it into place with a rename call. On POSIX systems, the rename system call guarantees atomicity.

I put it on PrePAN to get some advice. I have no clue what that'll do on any non-POSIX systems that have symlinks (if the OS doesn't do symlinks, I can't help you). Is a rename call universally atomic? If not, how can I detect those platforms, and provide that atomic guarantee some other way?

I didn't get any feedback, so I chose to simply release the module. It's now on CPAN. Enjoy!

WordPress theme for

In the past month, a number of people have asked about the theme for this blog. I was particularly flattered that someone even asked where I bought it.

It is just a customized version of Joey Robinson's Minimalist theme. My aim was to keep the same design principles - fast-loading, minimalism, readability - but update it to have a more modern look. One major goal was to have a truly great font via [ccie]@font-face[/ccie] on modern browsers, so I used the Junction font from The League of Movable Type. They're an awesome group of free font designers - you should check out their other fonts too!

I also rewrote the javascript with jQuery, because mootools is ugh.

The new theme is called, unsurprisingly, "Hashbang" - and is now available on Github. Enjoy!

Tips & tricks from my 4 months at Pythian

After working with Yanick Champoux on a few little Perl projects here and there, we finally met face-to-face at YAPC::NA last summer. A few months later, when I was looking for a co-op position, I immediately thought of Pythian. Read more »

SSL security in HTTP::Tiny

I was asked to add SSL support to a client library, while also moving from home-grown manual HTTP code to a proper module. HTTP::Tiny was ideal because it is pure-Perl, a core module since 5.14 (so it'll be maintained), and it's just one .pm file, making it easy to ship.

An application server that supported SSL was provided for testing purposes, but the SSL certificate didn't match the hostname - HTTP::Tiny correctly rejected connections. I needed to be able to control the settings sent to the underlying IO::Socket::SSL object used for the encrypted connection so I could turn off security features for testing. As I worked on that, David Golden offered invaluable feedback, which greatly improved the design of the features added to HTTP::Tiny.

As of 0.018, HTTP::Tiny is more configurable, and has a simple interface for easily making SSL connections more secure. Read more »

Wherein I realize the bliss of writing init scripts with Daemon::Control

Init scripts are annoying little things - almost entirely boilerplate. Here's how I learned to stop struggling, and love Daemon::Control to control my daemons.

The module really is as simple as the synopsis - you describe the daemon, have it write an init script (which actually just runs your Daemon::Control script) for you, then update-rc.d and you're golden. It really is that simple. Read more »

A pastebin with almost no user interface

I've always favoured pastebins that let you bin a paste and nothing more - and spring to mind. I've made a Perl almost-clone of now runs WWW::Hashbang::Pastebin, a simple pastebin written with Dancer and DBIx::Class that does nothing but store your text and show it back to you. The only feature beyond that is if you append a +, you'll get line numbering (no syntax highlighting). You can use an anchor to jump to any line (click the line number), and the number for that line will be highlighted.

To interact with the pastebin, just POST with paste content in p and get the URL back in the X-Pastebin-URL HTTP header (and in the body, so curl-ing will Just Work):

curl -F 'p=<-' < /var/log/syslog

Or, use the Perl client, which provides a command-line tool to do the same thing (and also fetch paste content, given an ID).

Dist::Zilla::Plugin::Twitter gets an OAuth update

My pluginbundle for Dist::Zilla includes, among other things, the Twitter plugin so I can brag on Twitter every time I release a module. Mysteriously, it broke one day. Looking at the code, I realized that it was sending my username and password to authenticate. I remember being uneasy with that at the time I set it up, but I quickly forgot, and continued along blithely. OAuth is an authorization standard that allows users to avoid giving their username & password to a potentially-untrusted application. Using OAuth has been requested since 2011, and the 401 Unauthorized error I got indicates that now it is mandatory for Twitter.

David Golden offered to let me maintain the module, and I'm a sucker, so... :D Read more »

Consistency and direction in pagination

Today, I discovered yet again one of the cardinal sins of user interface design - inconsistency. A blog had two pagination interfaces on one page - and they had opposite directionality. For one, older posts were to the left; for the other, older posts were to the right. This is an obvious and egregious error, and the solution is to make them operate in the same direction, or better yet, remove one. Read more »

Broken busybox can cause DHCP timeouts on Android

Apparently, when your Android device's busybox installation gets broken for whatever reason, this doesn't cause your phone to come to a screeching, grinding halt. The breakage is much more subtle. For me, the only symptoms were:

  • the standard busybox installers available on Android market couldn't install busybox (this may not be related, who knows!)
  • wifi stopped working - the phone couldn't connect to the AP

Read more »

Applying fair dealing exceptions to TPMs

James Gannon points out that "Critics of the TPM provisions in Bill C-11 often claim to have a "balanced" solution for TPM protection: to create an exception that allows hacking for legal purposes." That's certainly correct, however, he proceeds to misconstrue what that suggestion actually means Read more »

On the government's internet surveillance plans

Minister Vic Towes responded to Privacy Commissioner Jen Stoddart's open letter Friday:

Toews was quick to shoot down Stoddart's concerns in an ongoing battle that pits the government against consumer advocates and privacy experts. "Our approach strikes an appropriate balance between the investigative powers used to protect public safety and the necessity to safeguard the privacy of Canadians," Toews said in a statement Thursday in response to Stoddart's letter.

"As technology evolves, many criminal activities - such as the distribution of child pornography - become much easier. We are proposing measures to bring our laws into the 21st Century and provide police with the tools they need to do their job."
CBC News

Read more »

On Bill C-11, Another Act To Amend The Copyright Act

Between April 2006 and March 2011, Canada was governed by a minority Conservative government, meaning the government needed the co-operation of the opposition parties to pass legislation. Despite a lot of talk about minority governments necessarily yielding instability, having a minority government forestalled the worst of the Conservatives' plans. In the last federal election in March, the Conservative Party won a majority of the seats in Parliament - meaning they have enough votes to pass any legislation they want, barring opposition within their own party. Given Prime Minister Stephen Harper's iron-fisted control over his caucus, that's unlikely. Read more »

Mocking LWP::UserAgent

Important update: Don't follow this advice, follow that advice!

chromatic mentioned how to use dependency injection in You're Already Using Dependency Injection. Although I had read that when he posted it, I hadnt actually ever done it. That is, until today. Read more »

My 4 months at DRDC

Earlier this year, I posted a short entry about having accepted a job offer from Defence Research & Development Canada (DRDC). Over the past four months, I've had a great supervisor, a relaxed workplace, and challenging work. As you might imagine, working at a defence research lab is quite different from anything I'd done previously. I knew that was going to be the case, but I was still surprised at how little of my prior knowledge applied to The Real World Of Real Work. But first, what awesome, classified, doomsday devices did I get to work on? Well... Read more »

Trimming whitespace in gedit with Perl

With gedit plugins, you can turn this simple text editor into a lightweight IDE. It's fast, has good syntax highlighting, and can have code completion, shell integration, and many similar feature you might expect from an IDE. One feature it lacked was trimming whitespace from files. I searched for plugins to do this, and found several, but none of them quite met my expectations, because none were configurable. I typically want my files to end with one and only one newline. Of course, the solution is Perl. Read more »

Revising perlopentut

At YAPC::NA 2011, I whined about the lack of codification of tribal knowledge in Perl. One area that's ripe for fixing is the documentation on open. There's a section in perlfunc for open, and a tutorial: perlopentut. That tutorial is where I've started my campaign to have the tutorials and FAQs give good advice. Read more »

Thoughts on future conferences

YAPC::NA 2011 was great (read about it: 1, 2, 3), and I enjoyed almost every minute. I have only a few gripes, collected here in no particular order:

  • You can never have enough power in the conference halls. Never.
  • Yes, a four-day conference would be great. Give it a try!
  • Make the area immediately outside the conference halls a comfortable place to sit and/or mingle. Having an area for hacking at the other end of the building isn't good enough, it needs to be right there. And close the doors so the talking doesn't distract attendees listening to talks (or the speakers).
  • The auction is a problem. It should absolutely not interrupt prime socializing/networking time. Make it a silent auction for the run-of-the-mill items, limit the live part to a half-hour of the big-ticket items, and don't be so desperate for large donations - it's unseemly, exclusionary, and probably raises less money than many smaller donations.

I heard about these from other attendees as well.

However, I want to thank the organizers and volunteers for putting together a really really good conference. I was impressed with how smoothly things went, and I all the attendees I spoke to were highly complementary of the event as a whole.

YAPC::NA day three

Miyagawa strikes again

On day three (read about days one and two), I spent most of my time socializing and networking rather than attending talks. Read more »