I've used the Perl programming language for years, but always as something akin to an interpreted 'C' (albeit with those handy native hashes and regular expressions). I never bothered to learn the perl object model, I didn't look past its reputation for bolted on funkiness. And it seemed irrelevant for my purposes anyway, since I'd always limited my perl use to smallish tasks, addressable with and quick and dirty hacks.
Recently, Jeff asked me to look at enhancing the automated backups for some of his network services, and I started down the path of throwing together 'the simplest thing that could possibly work', in perl. But I noticed two things early on:
So I punted on the reinvention effort (scheduling some time to work out desired config tweaks for the existing app), and I decided the time had come to figure out if perl objects add useful value for me when scaling up.
To that end, I peeled off a piece of the reinvented application I'd started. This is the piece that deals with naming the output store (i.e., directory) for a daily backup. As part of that naming process, it also automatically handles moving off old daily backups to weekly or monthly archives as appropriate. I refactored this functionality into two classes, a NameRotator that knows naming rules and how they apply, and a NamerCmds that knows how to carry out primitive naming operations (create, list, move, delete) in the target context. Since I tend to run on Linux and code on Windows, I subclassed target specific NamerCmds to enable testing on each of those targets.
The bottom line is that it worked well, with hardly a trace of perl funkiness. This object approach yielded the benefits you'd expect. The NameRotator class provided a clean encapsulation of naming rules and their application, while NamerCmds subclassing provided useful extensibility without touching base functionality. A client makes use of the functionality with just a bit of straightforward code
$whelper = WinNamer->winNamerCmds("c:\\bak", "svcs");
$todaysBackupName = NameRotator->new( $whelper, "err.log" )->setNextName();
So, now I may be more inclined toward using Perl like an interpreted java...
(The finished functionality works as a motivating example that likely would have helped me
ramp up more directly on Perl objects. I put the write up at http://www.differentchairs.com/NameRotator.html)
posted at: 13:16 | path: | permanent link to this entry
All content copyright © 2004-2010 by steve hardy