| 1 | package Acme::OneHundredNotOut; | ||
| 2 | our $VERSION = "100"; | ||
| 3 | |||
| 4 | =pod | ||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Acme::OneHundredNotOut - A raise of the bat, a tip of the hat | ||
| 9 | |||
| 10 | =head1 TEXT | ||
| 11 | |||
| 12 | I have just released my 100th module to CPAN, the first time that anyone | ||
| 13 | has reached that target. As some of you may know, I am getting ready to | ||
| 14 | go back to college and reinvent myself from being a programmer into | ||
| 15 | being a missionary. I don't forsee that many more Perl modules coming | ||
| 16 | out of this. | ||
| 17 | |||
| 18 | Of course, this doesn't mean that I'm going to abjure usage of Perl | ||
| 19 | forever; any time there's a computer and something I need automated, out | ||
| 20 | will come the Swiss Army Chainsaw and the job will get done. In fact, we | ||
| 21 | recently needed to manipulate some text from a mission handbook to | ||
| 22 | translate it into Japanese, and Perl was there handling and collating | ||
| 23 | all that. | ||
| 24 | |||
| 25 | But 100 modules is a convenient place to stop and take stock, and I hope | ||
| 26 | that those of you who have benefitted from my modules, programs or | ||
| 27 | writing about Perl will forgive me a certain spot of self-indulgence as | ||
| 28 | I look back over my CPAN career, especially since I feel that the | ||
| 29 | diversity of modules that I've produced is a good indication of the | ||
| 30 | diversity of what can be done with Perl. | ||
| 31 | |||
| 32 | Let's begin, then, with some humble beginnings, and then catch up on | ||
| 33 | recent history. | ||
| 34 | |||
| 35 | =head2 The Embarrassing Past | ||
| 36 | |||
| 37 | Contrary to popular belief, I was not always a CPAN author. I started | ||
| 38 | writing modules in 1998, immediately after reading the first edition of | ||
| 39 | the Perl Cookbook - yes, you can blame Nat and Tom for all this. The | ||
| 40 | first module that I released was L<Tie::DiscoveryHash>, since I'd just | ||
| 41 | learnt about tied hashes. As with many of my modules, it was an integral | ||
| 42 | part of another software project which I actually never finished, and | ||
| 43 | now can't find. | ||
| 44 | |||
| 45 | The first module that I ever B<wrote> (but, by a curious quirk of fate, | ||
| 46 | precisely the fiftieth module I released) was called L<String::Tokeniser>, | ||
| 47 | which is still a reasonably handy way of getting an iterator over | ||
| 48 | tokenising a string. (Someone recently released C<String::Tokenizer>, | ||
| 49 | which makes me laugh.) This too was for an abortive project, C<webperl>, | ||
| 50 | an application of Don Knuth's WEB system of structured documentation to | ||
| 51 | Perl. However, given the code quality of these two modules, it's perhaps | ||
| 52 | just as well that the projects never saw the light of day. | ||
| 53 | |||
| 54 | There are a few other modules I'd rather like to forget, too. | ||
| 55 | C<Devel::Pointer> was a sick joke that went badly wrong - it allowed | ||
| 56 | people to use pointers in Perl. Some people failed to notice that | ||
| 57 | referring to memory locations directly in an extremely high-level | ||
| 58 | language was a dangerous and silly thing to do, and actually used the | ||
| 59 | damned thing, and I started getting requests for support for it. Then at | ||
| 60 | some point in 2001, when I should really have known better, I developed | ||
| 61 | an interest in Microsoft's .NET and the C# language, which I still think | ||
| 62 | is pretty neat; but I decided it might be a good idea to translate the | ||
| 63 | Mono project's tokenizer and parser into Perl, ending up with | ||
| 64 | L<C::Sharp>. I never got around to doing the parser part, or indeed | ||
| 65 | anything else with it, and so it died a lonely death in a dark corner of | ||
| 66 | CPAN. L<GTK::HandyClist> was my foray into programming graphical | ||
| 67 | applications, which started and ended there. L<Bundle::SDK::SIMON> was | ||
| 68 | actually the slides from a talk on my top ten favourite CPAN modules - | ||
| 69 | except that this changes so quickly over time, it doesn't really make | ||
| 70 | much sense any more. | ||
| 71 | |||
| 72 | Finally, L<Array::FileReader> was an attempt to optimize a file access | ||
| 73 | process. Unfortunately, my "optimization" ended up introducing more | ||
| 74 | overheads than the naive solution. It all goes to show. Since then, | ||
| 75 | Mark-Jason Dominus, another huge influence in the development of my CPAN | ||
| 76 | career, has written C<Tie::File>, which not only has a better name but | ||
| 77 | is actually efficient too. | ||
| 78 | |||
| 79 | =head2 The Internals Phase | ||
| 80 | |||
| 81 | 1999-2000 were disastrous years for me personally but magnificent years | ||
| 82 | Perl-sonally. Stuck in a boring job and a tiny flat in the middle of | ||
| 83 | Tokyo, I had plenty of time to get stuck into more Perl development. I | ||
| 84 | felt that getting involved with C<perl5-porters> would be a good way of | ||
| 85 | gettting to know more about Perl, and so I needed a hobby horse - an | ||
| 86 | issue of Perl's development that I cared about. Since I was in Japan and | ||
| 87 | working a lot with non-Latin text, Unicode support seemed a good thing | ||
| 88 | to work on, and so L<Unicode::Decompose> appeared, while I fixed up a | ||
| 89 | substantial part of the post-5.6 core Unicode support. | ||
| 90 | |||
| 91 | I'd recommend this way to anyone who wants to get more involved in the | ||
| 92 | Perl community, although I was very lucky in terms of who else happened | ||
| 93 | to be around at the time: Gurusamy Sarathy was extremely gracious in | ||
| 94 | helping me turn my fledgling C code into something fit for the Perl | ||
| 95 | core, and he also helped me understand the C<perl5-porters> etiquette | ||
| 96 | (yes, there was some at the time) and what makes a good patch, while | ||
| 97 | Jarkko Hietaniemi was always good for suggestions of interesting things | ||
| 98 | for keen people to work on. Seriously, get involved. If I can do it, | ||
| 99 | anyone can. | ||
| 100 | |||
| 101 | Anyway, this fixation with understanding the Perl 5 internals, and | ||
| 102 | especially the Perl 5 compiler, (due to yet another of my Perl | ||
| 103 | influences, the great Malcolm Beattie) led to quite a torrent of | ||
| 104 | modules, from L<ByteCache>, an implementation of just-in-time | ||
| 105 | compilation for Perl modules, through L<B::Flags> and L<B::Tree> to help | ||
| 106 | visualising the Perl op tree, to L<uninit>, L<B::Generate>, L<optimizer> | ||
| 107 | and L<B::Utils> for modifying it. | ||
| 108 | |||
| 109 | =head2 Perl About The House | ||
| 110 | |||
| 111 | Now we abandon chronological order somewhat and take a look at the | ||
| 112 | various areas in which I've used Perl. One of these areas has been the | ||
| 113 | automation of everyday life: checking my bank balance with | ||
| 114 | L<Finance::Bank::LloydsTSB> (the first Perl module to interface to | ||
| 115 | personal internet banking, no less) and my phone bill with a release of | ||
| 116 | Tony Bowden's L<Data::BT::PhoneBill>. | ||
| 117 | |||
| 118 | L<Finance::Bank::LloydsTSB> was meant to go with L<Finance::QIF>, my | ||
| 119 | Quicken file parser, to produce another now-abandoned idea, a Perl | ||
| 120 | finances manager. It seemed that I'm only capable of producing modules, | ||
| 121 | not full standalone applications - or at least, it seemed that way until | ||
| 122 | I produced L<Bryar>, my blogging software, based on the concepts from | ||
| 123 | Rael Dornfest's C<blosxom> and beginning my adventures with Andy | ||
| 124 | Wardley's Template Toolkit. Bryar also tuned me in to the | ||
| 125 | Model-View-Controller framework idea, of which more later. | ||
| 126 | |||
| 127 | Another project I briefly played with was a personal robot, using the | ||
| 128 | C<Sphinx>/C<Festival> speech handling and recognition modules from | ||
| 129 | Cepstral and Kevin Lenzo. I didn't have X10, so I couldn't shout | ||
| 130 | "lights" into the air in a wonderfully scifi way, but I could shout | ||
| 131 | "mail" and have a summary of my inbox read to me, "news" to get the | ||
| 132 | latest BBC news headlines, and "time" to hear the time. Of course, | ||
| 133 | getting computers to tell the time nicely takes a little bit of work. I | ||
| 134 | don't like "It's eleven oh-three pee em", since that's not what someone | ||
| 135 | would say if you asked them the time. I wanted my robot to say "It's | ||
| 136 | just after eleven", and that's what L<Time::Human> does. Shame about the | ||
| 137 | localisation. | ||
| 138 | |||
| 139 | =head2 Messing About With Classes | ||
| 140 | |||
| 141 | One of the things that continues to amaze me about Perl is its | ||
| 142 | flexibility; the way you can change core parts of its operation, even | ||
| 143 | from pure Perl. This lead to quite a few modules, many of which were | ||
| 144 | mere proofs of concept. | ||
| 145 | |||
| 146 | L<Sub::Versive>, for instance, was the first module on CPAN to handle | ||
| 147 | pre- and post-hooks for a subroutine; it has since been joined by a | ||
| 148 | plethora of imitators. It was written, though, in response to a peculiar | ||
| 149 | scenario. I was writing a module (C<Safety::First>) which provided | ||
| 150 | additional built-in-like functions for Perl to encourage and facilitate | ||
| 151 | defensive programming and intelligible error reporting. ("Couldn't open | ||
| 152 | file? Why not?") These built-ins had to be available from every | ||
| 153 | package, which meant playing with C<UNIVERSAL::AUTOLOAD>. But what if | ||
| 154 | another package was already using C<UNIVERSAL::AUTOLOAD>? Hence, | ||
| 155 | C<Sub::Versive> wrapped it in a pre-hook. Of course, with the | ||
| 156 | interesting bit of the problem solved, C<Safety::First> was abandoned. | ||
| 157 | |||
| 158 | L<Class::Dynamic> was an interesting attempt to provide support for code | ||
| 159 | references in C<@ISA>, analogous to code references in C<@INC>. It | ||
| 160 | works, but of course I could never find any practical use for it. | ||
| 161 | |||
| 162 | L<Class::Wrap> was written as a lazy profiler. A certain application I | ||
| 163 | was writing for my employer of the time, Kasei, made use of the (IMHO | ||
| 164 | evil) C<Mail::Message> module. How do we isolate all calls to that | ||
| 165 | class? There are plenty of modules out there for instrumenting | ||
| 166 | individual methods, including of course C<Sub::Versive>. But the whole | ||
| 167 | class? C<Class::Wrap> takes a wonderfully brute-force but workable | ||
| 168 | approach to the problem. A real profiler, however, can be constructed | ||
| 169 | from L<Devel::DProfPP>, which is sort of a profiler toolkit. | ||
| 170 | |||
| 171 | I wrote a couple of other modules with Kasei in this category, | ||
| 172 | particularly while working on our Plucene port of the Lucene search | ||
| 173 | engine. (I guess I could claim C<Plucene> as one of my 100 modules, but | ||
| 174 | that would be to deny Marc Kerr the recognition he deserves for the work | ||
| 175 | he put in to packaging, documenting and providing tests for my insane | ||
| 176 | and scrambled code.) I wrote L<Bit::Vector::Minimal>, for instance, as I | ||
| 177 | ported C<org.apache.lucene.util.BitVector>; L<Tie::Array::Stored>, which | ||
| 178 | I'm amazed wasn't already implemented on CPAN, provided the Perl | ||
| 179 | equivalent of C<org.apache.lucene.util.PriorityQueue>. | ||
| 180 | L<Lucene::QueryParser>, of course, does what it says on the tin. (I also | ||
| 181 | produced a couple of add-ons for Plucene after leaving Kasei when I was | ||
| 182 | doing a bit of Plucene consultancy: | ||
| 183 | L<Plucene::Plugin::Analyzer::PorterAnalyzer> and | ||
| 184 | L<Plucene::Plugin::WeightedQueryParser>.) | ||
| 185 | |||
| 186 | Another module produced in the course of writing Plucene was | ||
| 187 | L<Class::HasA>, a handy little utility module which works well with Tony | ||
| 188 | Bowden's C<Class::Accessor> and merely dispatches certain method calls | ||
| 189 | to objects contained within your object. | ||
| 190 | |||
| 191 | And speaking of C<Class::Accessor>, L<Class::Accessor::Assert> would | ||
| 192 | have been a godsend while writing Plucene, as it's a version of accessor | ||
| 193 | handling which typechecks what you're putting into the accessor slots. | ||
| 194 | When you're converting a typed language into an untyped one, occasional | ||
| 195 | checks that you're handling the right kind of object don't go amiss. I | ||
| 196 | learnt my lesson eventually, though, and wrote the module after Plucene | ||
| 197 | was done. | ||
| 198 | |||
| 199 | Another Java-influenced module was C<Attribute::Final>, which was written | ||
| 200 | for my book Advanced Perl Programming as an example of both attributes | ||
| 201 | and messing about with the class module - by marking some subtourines as | ||
| 202 | C<:final>, you get an error if a derived class attempts to override it. | ||
| 203 | As with many of my proof-of-concept modules, this isn't something I'd | ||
| 204 | ever use myself, but I know others have used it. I'll let you into a | ||
| 205 | secret - over the past few months I've settled on giving modules a | ||
| 206 | version number of C<0.x> if I've never used them myself and C<1.x> if I | ||
| 207 | have. | ||
| 208 | |||
| 209 | Java wasn't the only language to influence my Perl coding activities. | ||
| 210 | Ruby is a wonderful little language I first encountered in Japan, but | ||
| 211 | didn't really get into until around 2003. Of course, when you see | ||
| 212 | another language has dome good ideas, you steal them, which is what I | ||
| 213 | did with L<rubyisms>, L<SUPER>, and L<Class::SingletonMethod> - all of | ||
| 214 | which, by the way, are B<excellent> examples of what you can do to the | ||
| 215 | behaviour of Perl just from pure Perl. C<SUPER> is the kind of module | ||
| 216 | I've so often wanted to use in production code but never dared. | ||
| 217 | |||
| 218 | =head2 Smart Perl | ||
| 219 | |||
| 220 | My views on human-computer interface and computer usability have been | ||
| 221 | unchanged since I wrote C<Tie::DiscoveryHash> way back in the mists of | ||
| 222 | time. The underlying principle behind that module was simple: the user | ||
| 223 | should B<never> tell the computer anything it already knows or can | ||
| 224 | reasonably be expected to work out. C<Tie::DiscoveryHash> was all about | ||
| 225 | having the computer find out stuff for itself. | ||
| 226 | |||
| 227 | This has influenced a number of my modules, which have focussed on | ||
| 228 | trying to make everything as simple as possible for the user (or more | ||
| 229 | usually, for the programmer using my modules) and then a bit simpler. | ||
| 230 | |||
| 231 | So, for instance, I found the whole process of keeping values persistent | ||
| 232 | between runs of Perl a bit of a nightmare - I could never remember the | ||
| 233 | syntax for tying to C<DB_File>, and I would always forget to use the | ||
| 234 | extremely handy C<MLDBM> module. I just wanted to say "keep this | ||
| 235 | variable around". L<Attribute::Persistent> does just that, cleanly and | ||
| 236 | simply. It even works out a sensible place to put the database, so you | ||
| 237 | don't have to. | ||
| 238 | |||
| 239 | Similarly, L<Config::Auto> works out where your application might keep a | ||
| 240 | configuration file, works out what format it's in, parses it, and hands | ||
| 241 | you back a hash. No muss, no fuss. And more importantly, no need to even | ||
| 242 | think about writing a config file parser again. It's done once, forever. | ||
| 243 | L<Getopt::Auto> applies the same design principles to handling command | ||
| 244 | line arguments - I hate forgetting how to use C<Getopt::Long>. | ||
| 245 | |||
| 246 | Other attempts at making things simple for the end-user weren't that | ||
| 247 | successful. As part of writing my (first) mail archiving and indexing | ||
| 248 | program, C<Mail::Miner>, of which more later, I wanted a nice way for | ||
| 249 | users to specify a time period in which they're looking for mails - "a | ||
| 250 | week ago", "sometime last summer", "near the beginning of last month" - | ||
| 251 | and so on. L<Date::PeriodParser> would take these descriptions and turn | ||
| 252 | them into a start and end time in which to search. Except, of course, | ||
| 253 | that this is a very hard thing to do and requires a lot of heuristics, | ||
| 254 | and while I started off quite well, as ever, I got distracted with other | ||
| 255 | interesting and considerably more tractable problems. | ||
| 256 | |||
| 257 | =head2 Mail Handling | ||
| 258 | |||
| 259 | A good number of my Perl modules focussed on mail handling, so many that | ||
| 260 | I was actually able to get a job basically doing mail processing in | ||
| 261 | Perl. It all started with L<Mail::Audit>. I was introduced to | ||
| 262 | F<procmail> at University, and it was useful enough, but it kept having | ||
| 263 | locking problems and losing my mail, and I didn't really understand it, | ||
| 264 | to be honest, so I wanted to write my mail filtering rules in Perl. | ||
| 265 | C<Mail::Audit> worked well for a couple of years before it grew into an | ||
| 266 | obese monster. I actually only use a very old version of C<Mail::Audit> | ||
| 267 | on my production server. | ||
| 268 | |||
| 269 | As part of the attempt to slim it back down again, I abstracted out one | ||
| 270 | of the major parts of its functionality, delivering an email to a local | ||
| 271 | mailbox. Now I only use mbox files, so it was reasonably easy for me, | ||
| 272 | but people wanted me to add Maildir and whatever to C<Mail::Audit>, so I | ||
| 273 | kicked it all out to L<Mail::LocalDelivery> instead. | ||
| 274 | |||
| 275 | But I found that I still wasn't able to filter my mail adequately and | ||
| 276 | find the stuff I needed from it. Attachments were a big problem, since | ||
| 277 | they both made ordinary search with C<grep> or C<grepmail> much slower, | ||
| 278 | and they weren't always easy to find anyway. So I wrote something to | ||
| 279 | remove attachments from mail and stick them in a database, and while I'm | ||
| 280 | at it, index mail for quick retrieval. And then it grew to identifying | ||
| 281 | "interesting" features of an email and searching for them too, and then | ||
| 282 | L<Mail::Miner> was born. | ||
| 283 | |||
| 284 | Finally, I got into web display of archived email, and needed a way of | ||
| 285 | displaying threads. Amazingly, nobody had coded up JWZ's mail threading | ||
| 286 | algorithm in Perl yet, so I did that too: L<Mail::Thread>. | ||
| 287 | |||
| 288 | But then I decided that C<Mail::*> was in a very sick state. I had been | ||
| 289 | working with the mail handling modules from CPAN - including my own - | ||
| 290 | and grown to hate them; they were all too slow, too complicated, too | ||
| 291 | buggy or all three. It was time for action, and the Perl Email Project | ||
| 292 | was born. | ||
| 293 | |||
| 294 | L<Email::Simple> was the first thing to come out of this, and is | ||
| 295 | a fantastic way of just getting at the bits you need from an email. It's | ||
| 296 | much simpler, and therefore much faster, than its more fully-featured | ||
| 297 | cousins on CPAN. L<Email::MIME> was its natural successor, which added | ||
| 298 | rudimentary MIME handling, and spawned two subsidiary modules, | ||
| 299 | L<Email::MIME::ContentType> and L<Email::MIME::Encodings> in order to | ||
| 300 | keep C<Email::MIME> itself focussed on the "do one thing and do it well" | ||
| 301 | principle. | ||
| 302 | |||
| 303 | Of course we then had to replace C<Mail::Audit>, so | ||
| 304 | L<Email::LocalDelivery> and L<Email::Filter> appeared. This is another | ||
| 305 | module I don't use, because my C<Mail::Audit> setup works and I'm | ||
| 306 | terrified of breaking it and losing all my mail. But I'm told that | ||
| 307 | C<Email::Filter> works just fine too. | ||
| 308 | |||
| 309 | By this stage, C<Mail::Miner> was getting crufty. It was replaced by a much | ||
| 310 | more modular and beautiful L<Email::Store>; this is extended with | ||
| 311 | plug-in modules like L<Email::Store::Summary>, L<Email::Store::Plucene> | ||
| 312 | and L<Email::Store::Thread>. I had to write the plug-in framework | ||
| 313 | myself, since neither C<Module::Pluggable> or C<Class::Trigger> did | ||
| 314 | quite what I wanted, and so the C<Email::Store> project also produced | ||
| 315 | L<Module::Pluggable::Ordered>. | ||
| 316 | |||
| 317 | Now C<Email::Store> naturally uses C<Email::Simple> objects, since | ||
| 318 | it's the most efficient mail representation class on CPAN. | ||
| 319 | Unfortunately, C<Email::Store> also wants to make use of some modules on | ||
| 320 | CPAN like C<Mail::ListDetector> which don't want to know about | ||
| 321 | C<Email::Simple> objects and want to talk C<Mail::Internet> or whatever. | ||
| 322 | To get around this, I wrote L<Email::Abstract> which provides module | ||
| 323 | writers with an interface to B<any> kind of mail object, so they don't | ||
| 324 | have to force a particular representation on their users. | ||
| 325 | |||
| 326 | =head2 Linguistics | ||
| 327 | |||
| 328 | I'm actually a linguist by training, not a computer programmer, | ||
| 329 | graduating from the school of Oriental Studies with second and third | ||
| 330 | year options in Japanese linguistics. I'd like to think that my work at | ||
| 331 | Kasei was as much about linguistic and textual analysis as it was about | ||
| 332 | mail munging. With that in mind, I wrote a few language-related modules | ||
| 333 | during my time with them. | ||
| 334 | |||
| 335 | The first important module, which I started work on while I was playing | ||
| 336 | with C<Mail::Miner>, was L<Lingua::EN::Keywords>. This started life as a | ||
| 337 | relatively naive algorithm for picking common words out of a text in an | ||
| 338 | attempt to provide some keywords to describe what the text is "about", and | ||
| 339 | has matured into quite a handy little automatic topic recognition | ||
| 340 | module. Its natural counterpart is L<Lingua::EN::NamedEntity>, which | ||
| 341 | B<is> still a naive algorithm but sometimes those are the best ones. | ||
| 342 | |||
| 343 | This module has a bit of story behind it. While analysing mails we were | ||
| 344 | trying to find people, places, times, and other things we could link | ||
| 345 | together into a knowledge base. The technical term for this is named | ||
| 346 | entity extraction. I find a useful library to do this, called C<GATE>. | ||
| 347 | It's written in Java, which meant using C<Inline::Java>, and is | ||
| 348 | extremely slow and complex. At the same time, I was writing a chapter on | ||
| 349 | computational linguistics with Perl in Advanced Perl Programming, and | ||
| 350 | wanted to talk about named entity extraction. Unfortunately, I only had | ||
| 351 | one module which did this, L<GATE::ANNIE::Simple>, and it was a hack. If | ||
| 352 | you're going to talk about a subject, it makes sense to compare and | ||
| 353 | contrast different solutions, and Tony had already been saying "why | ||
| 354 | don't you just write something to pull out capitalized phrases, for | ||
| 355 | starters?" I did this, intending to use it as a baseline, but of course | ||
| 356 | it's much faster than C<GATE> and not noticably less accurate. Ho hum. | ||
| 357 | |||
| 358 | Another thing those wacky computational linguists do a lot of is | ||
| 359 | working with n-gram streams. In every discipline, there's a particular | ||
| 360 | hammer you can use to solve any given problem. In data mining, it's | ||
| 361 | called market basket analysis. In computational linguistics, it's | ||
| 362 | maximal entropy. You look at the past stream of n characters (that's an | ||
| 363 | n-gram) and work out how hard it is to see what's coming next. | ||
| 364 | |||
| 365 | For instance, if I feed you the 4-gram C<xylo> the chances of a C<p> | ||
| 366 | next are very high. The chances of a C<e>, or indeed anything else, are | ||
| 367 | pretty low. Low entropy area. But if I feed you C<then>, it's really not | ||
| 368 | easy to guess the next letter, since we're likely to be at the end of a | ||
| 369 | word and the next word might be anything; high entropy. That's how you | ||
| 370 | use maximal entropy to find word breaks in unsegmented text, and there's | ||
| 371 | a huge amount of other cool stuff you can do with it. | ||
| 372 | |||
| 373 | I swear the day I wrote L<Text::Ngram>, there were no other modules on | ||
| 374 | CPAN which extracted n-grams, but as soon as I released it it looked | ||
| 375 | like there were three or four there all along. (Including one from | ||
| 376 | Jarkko, no less.) Anyway, I wanted to see if I could still remember how | ||
| 377 | to write XS modules, especially since I'd just written a book about it. | ||
| 378 | |||
| 379 | L<Lingua::EN::Inflect::Number> is a terrible hack, but it works. I | ||
| 380 | needed it to make C<Class::DBI::Relationship> (of which more later) | ||
| 381 | more human-friendly. L<Lingua::EN::FindNumber> is another hack written | ||
| 382 | for APP; I was a little surprised that C<Lingua::EN::Words2Nums>, which | ||
| 383 | is a fantastic module in its own right, can turn English descriptions of | ||
| 384 | numbers into digits, but it can't actually pull the numbers out of a | ||
| 385 | text in the first place. So I fixed that. | ||
| 386 | |||
| 387 | =head2 Text Munging, and Some More Mail Stuff | ||
| 388 | |||
| 389 | Applying my linguistic experience to the problems of intelligent mail | ||
| 390 | indexing, searching and displaying led to churning out another set of | ||
| 391 | modules. | ||
| 392 | |||
| 393 | The first problem was what to do with search results. You know those | ||
| 394 | little snippets that Google and other search engines display when you | ||
| 395 | search for some terms? They contextualise the terms in the body of the | ||
| 396 | document and highlight them in a snippet that best represents how | ||
| 397 | they're used in the document. This is actually a really hard problem, | ||
| 398 | and it took me several goes to get L<Text::Context> right. It uses | ||
| 399 | L<Text::Context::EitherSide> as an "emergency" contextualizer if it | ||
| 400 | can't get anything right at all, but the algorithm itself is a bit of a | ||
| 401 | swine. I actually had to prototype this module in Ruby to get my | ||
| 402 | thinking clear enough to code it up in Perl... | ||
| 403 | |||
| 404 | L<Text::Quoted> was another mail display problem - it's nice to | ||
| 405 | display different layers of quoted text in an email in different | ||
| 406 | colours. Identifying the quoted text isn't that hard, but working out | ||
| 407 | a particular bit nests is also surprisingly tricky. So I sorted it out. | ||
| 408 | |||
| 409 | The next problem I had to solve lead on from this. Suppose you've got | ||
| 410 | some mail, which is plain text, and you're going to display it as HTML. | ||
| 411 | Along the way, you want to turn any URIs into links, (maybe using | ||
| 412 | something like L<URI::Find::Schemeless::Stricter> to find things which | ||
| 413 | look like URLs, but which doesn't think that numbered lists are IP | ||
| 414 | addresses) escape any non-HTML-safe characters, highlight search terms, | ||
| 415 | put different quoted regions in different colours, and maybe do other | ||
| 416 | things too. The thing is, you have to be very careful about the order in | ||
| 417 | which you do this. Once you've escaped the HTML, you might mess up your | ||
| 418 | colouring of quoted text, but if you've turned the URIs into links | ||
| 419 | first, you'll mess them up when you escape all the HTML entities. | ||
| 420 | L<Text::Decorator> allows you to do all these transformations in a nice, | ||
| 421 | safe way, "layering" things like URI escaping, highlighting, and so on, | ||
| 422 | and then rendering to text or HTML or whatever when all the layers have | ||
| 423 | been applied. | ||
| 424 | |||
| 425 | C<Text::Decorator> was written in a meta-programming system I wrote | ||
| 426 | called L<pool>, which I should probably use more. It writes the boring | ||
| 427 | bit of OO classes for you given a simple description of the methods and | ||
| 428 | attributes. | ||
| 429 | |||
| 430 | Oh, and if you're not contextualising search terms in a mail snippet, | ||
| 431 | you probably just want to display the original content rather than the | ||
| 432 | first few lines, which invariablely contain lots of quoting of another | ||
| 433 | message. L<Text::Original>, extracted from the code of the Mariachi | ||
| 434 | project and so actually only packaged by me and written by Richard Clamp | ||
| 435 | and Simon Wistor, does just this. | ||
| 436 | |||
| 437 | L<WWW::Hotmail> was an attempt to solve the problem of how to import all | ||
| 438 | the mail a user already has into our archiving program, a problem Gmail | ||
| 439 | is now dealing with. Actually, Gmail's currently dealing with pretty | ||
| 440 | much all the problems we looked at last year. It's quite funny, really. | ||
| 441 | |||
| 442 | =head2 SIMON Hits The Web | ||
| 443 | |||
| 444 | I hate web programming. HTML is boring, CGI is boring, and I tried | ||
| 445 | avoiding it for as long as I could. This stopped when I worked for | ||
| 446 | Oxford University, handling their webmail service, which lead to | ||
| 447 | L<Bundle::WING>. Also at Oxford, I had to work with C<AxKit>, which | ||
| 448 | caused me innumerable headaches but I finally got some working XSP | ||
| 449 | applications written, not without writing the | ||
| 450 | L<Apache::AxKit::Language::XSP::ObjectTaglib> and | ||
| 451 | L<AxKit::XSP::Minisession> helper modules. I also did some playing | ||
| 452 | around with C<mod_perl>, thanks to the rather wonderful I<mod_perl | ||
| 453 | Cookbook>, and came up with L<Apache::OneTimeURL> when, during a | ||
| 454 | particularly paranoid phase, I wanted to give out my physical address | ||
| 455 | in URLs that would self-destruct after a single reading. | ||
| 456 | |||
| 457 | After leaving, though, I discovered the C<Class::DBI>/Template Toolkit | ||
| 458 | pair which has dominated my web programming since then. If you haven't | ||
| 459 | played with these two modules yet, you really need to, since they | ||
| 460 | work so well together, and with other modules like C<CGI::Untaint>, that | ||
| 461 | they simplify so much of web and database work. I extended | ||
| 462 | C<CGI::Untaint> with a bunch of extra patterns while at Kasei and | ||
| 463 | afterwards, including L<CGI::Untaint::ipaddress>, | ||
| 464 | L<CGI::Untaint::upload> and L<CGI::Untaint::html>, | ||
| 465 | I also wrote a whole plethora of C<CDBI> extensions: | ||
| 466 | L<Class::DBI::AsForm>, L<Class::DBI::Plugin::Type>, | ||
| 467 | L<Class::DBI::Loader::GraphViz> (reflecting my penchant for data | ||
| 468 | visualization), and L<Class::DBI::Loader::Relationship>, which applies | ||
| 469 | the "as simple as possible and a bit simpler" approach to defining data | ||
| 470 | relationships. | ||
| 471 | |||
| 472 | The whole culmination of C<CDBI>, TT, and all these other technologies | ||
| 473 | came when I sat down and wrote L<Maypole>, a Model-View-Controller | ||
| 474 | framework with, again, emphasis on making things very simple to get | ||
| 475 | working. The Perl Foundation's sponsorship of Maypole development has | ||
| 476 | been one of the proudest achievements in my CPAN career, and lead not | ||
| 477 | only to a stonking big manual, loads of examples, but also | ||
| 478 | L<Maypole::Authentication::UserSessionCookie> and L<Maypole::Component>. | ||
| 479 | |||
| 480 | Template Toolkit and XML came back together again in a recent project | ||
| 481 | where I've had render some XML as part of a Maypole application. | ||
| 482 | Amazingly, there wasn't an XSLT filter for the Template Toolkit, so | ||
| 483 | L<Template::Plugin::XSLT> was born. | ||
| 484 | |||
| 485 | =head2 Games, Diversions and Toys | ||
| 486 | |||
| 487 | It was only when I got back from Japan that I learnt to play Go. How | ||
| 488 | stupid was that. For a year I had access to some of the best Go clubs | ||
| 489 | and professional teacher and players in the world, and then I only pick | ||
| 490 | the bloody game up when I get back to England. Anyway, any computer | ||
| 491 | programmer who learns to play go, and they all do soon or later, | ||
| 492 | eventually decides to do something about the pitiful state of computer | ||
| 493 | Go. It's quite ridiculous that the game's been around for thousands of | ||
| 494 | years and the best computer programs we've devised regularly get beaten | ||
| 495 | resoundingly by small children. Anyway, I did my bit, producing | ||
| 496 | L<Games::Go::GMP> and L<Games::Go::SGF> as utility libraries, before | ||
| 497 | working on L<Games::Goban> to represent the state of the game. | ||
| 498 | |||
| 499 | But then while working for Kasei we discovered another addictive | ||
| 500 | diversion: poker. Computer poker isn't that great either, and I wanted | ||
| 501 | to write some robots to play on the internet poker servers; | ||
| 502 | L<Games::Poker::HandEvaluator> was the first product there, with the | ||
| 503 | hard work done by a GNU library, and L<Games::Poker::OPP> being the | ||
| 504 | interface to the network protocol. The comments to that module contain a | ||
| 505 | large number of Prisoner references, for no apparent reason. C<OPP> | ||
| 506 | needed a way of representing the state of a poker game, so I wrote | ||
| 507 | L<Games::Poker::TexasHold'em> to do that. And also because it was a | ||
| 508 | fantastic abuse of the C<'> package separator. | ||
| 509 | |||
| 510 | Oh, and another of my early modules that refused to die was | ||
| 511 | L<Oxford::Calendar>, which converts between the academic calendar and | ||
| 512 | the rest of the world's. It all counts, you know. | ||
| 513 | |||
| 514 | =head2 The Future | ||
| 515 | |||
| 516 | I've had mixed feelings on Perl 6, starting with my very public | ||
| 517 | nightmare at its announcement in 1999, (Hey, I'd just written a book on | ||
| 518 | Perl 5 internals, and now they're telling me it's obsolete.) and then my | ||
| 519 | very public repentance in 2000, at which point I was very excited about | ||
| 520 | the whole thing. So much so, that I produced vast numbers of design | ||
| 521 | documents for the language, most of which now ignored, but that's OK, | ||
| 522 | and set to work helping Dan design the core of the interpreter too. In | ||
| 523 | fact, I somehow managed to do so much work on it that, after a hacking | ||
| 524 | session together at O'Reilly in Boston in 2001, Dan let me be the | ||
| 525 | release pumpking of L<parrot>, a job I did until life got busy in 2002. | ||
| 526 | I'm extremely happy to have been involved in that, and hope I didn't | ||
| 527 | start the project off on too much of a bad footing. It looks to be doing | ||
| 528 | fine now, at least. | ||
| 529 | |||
| 530 | I was still interested in how they're going to make the Perl 6 parser | ||
| 531 | work, (I still am, but don't have enough time to throw at the problem) | ||
| 532 | and with my linguistic background I've always been interested in writing | ||
| 533 | parsers in general. So early on I started trying to write a | ||
| 534 | L<Perl6::Tokener>, which is now unfortunately quite obsolete, with the | ||
| 535 | intention of writing a parser later on. For most of 2002, my whiteboard | ||
| 536 | at home was covered with sketches of the Perl 6 grammar. | ||
| 537 | |||
| 538 | Then I found out that the parser is actually going to be dynamic - you | ||
| 539 | can reconfigure the grammar at runtime. Hey, I thought, that's going to | ||
| 540 | be fun. At this point, you can't use an ordinary state-table parser like | ||
| 541 | C<yacc>, as Perl has done so far, because that pre-computes the | ||
| 542 | transitions up front. Instead, you have to use a proper state machine | ||
| 543 | without pre-computed tables. But I couldn't find any parsers which | ||
| 544 | worked on that basis, so I wrote one, L<shishi>, prototyping it in Perl | ||
| 545 | with L<Shishi::Prototype> first. | ||
| 546 | |||
| 547 | This work has been largely ignored, unfortunately, but that's because | ||
| 548 | mainly I haven't had the time to do interesting user-facing stuff on top | ||
| 549 | of it so that it can be shown off. I tried porting C<Parse::RecDescent> | ||
| 550 | to it (using L<Parse::RecDescent::Deparse> to figure out what C<P::RD> | ||
| 551 | was doing) to produce a much faster recursive descent parser, but when I | ||
| 552 | heard that Damian Conway was funded to work on C<Parse::FastDescent> and | ||
| 553 | C<Parse::Perl>, (yes, I have a prototype of that too) I decided to leave | ||
| 554 | him to it. After all, why should I do the work and have other people get | ||
| 555 | paid for it? These modules did not materialise, but then, a failure on | ||
| 556 | his part does not constitute necessity on mine. | ||
| 557 | |||
| 558 | While I was messing with Parrot, I wanted to get other languages running | ||
| 559 | on the VM too, including Python, so I wrote L<Python::Bytecode> to take | ||
| 560 | apart the Python bytecode format so that it can be reassembled as Parrot | ||
| 561 | IMCC. Thankfully, Dan's taken this over, updated it for the latest | ||
| 562 | version of Python, and seems to be making good use of it converting | ||
| 563 | Python libraries to Parrot. | ||
| 564 | |||
| 565 | =head2 And the final joke... | ||
| 566 | |||
| 567 | I'm fond of a good joke, the Parrot April Fool's Joke being my pinnacle, | ||
| 568 | but I have mixed feelings about the C<Acme::> namespace on CPAN. I don't | ||
| 569 | know why. The thing is that I'd prefer modules which are funny because | ||
| 570 | they're clever, rather than modules which claim to be funny because | ||
| 571 | they're copies of other modules that claim to be funny. So my | ||
| 572 | contributions to C<Acme::*> have been deadly serious. | ||
| 573 | |||
| 574 | L<Acme::Dot>, for instance, is another example of how much you can warp | ||
| 575 | Perl's syntax without resorting to source filters. You can call methods | ||
| 576 | Ruby-style with the dot operator. But it's still the dot operator. You | ||
| 577 | work that one out. | ||
| 578 | |||
| 579 | And my other contribution to C<Acme::*> - and my hundredth module? Well, | ||
| 580 | you've just finished reading it. | ||
| 581 | |||
| 582 | =head1 AUTHOR | ||
| 583 | |||
| 584 | Simon Cozens, C<simon@cpan.org>. | ||
| 585 | |||
| 586 | =cut | ||
| 587 | |||
| 588 | "Thanks and blessings to you all. | ||
| 589 | Goodbye, baby, and amen."; | ||
| 590 |