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.

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.

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.

Wordpress theme for hashbang.ca

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 @font-face on modern browsers, so I used the Junction font from The League of Movable Type.

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.

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.

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.

A pastebin with almost no user interface

I’ve always favoured pastebins that let you bin a paste and nothing more – p.defau.lt and sprunge.us spring to mind. I’ve made a Perl almost-clone of sprunge.us: https://p.hashbang.ca 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.

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

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.

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.

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.

On the government's internet surveillance plans

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

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.

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.

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…

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.

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.

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.

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.