tmtm's Journal http://use.perl.org/~tmtm/journal/ tmtm's use Perl Journal en-us use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners. 2012-01-25T02:18:35+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 tmtm's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~tmtm/journal/ Class::DBI and Litigation http://use.perl.org/~tmtm/journal/26058?from=rss <p>One rumour that I do feel unfortunately compelled to address is the concept that there is any legal ambiguity or action surrounding Class::DBI.</p><p>I am unaware of any legal issues relating to the code or use of it, and have never been party to any action, or any threatened action, in respect of it, either as plaintiff or as defendant.</p><p>As a director of several UK companies I have been, and currently am, involved in litigaton in relation to other completely unrelated matters, but none of this has ever been connected to open source code or projects in any way.</p><p>Sometimes 2 + 2 really does just equal 4.</p> tmtm 2005-08-03T11:01:29+00:00 journal Today on Gossip Central http://use.perl.org/~tmtm/journal/26025?from=rss <p>I'm faced with quite a dilemma at the moment. There seems to be lots of misinformation going around, apparently mixed with a heady dose of outright lies.</p><p>On the one hand, I'd like to try to clear it all up (even though, really, I know that the world doesn't work that way, and that I wouldn't actually be able to).</p><p>On the other hand, though, to even try to do so would involve violating two principles I believe in:</p><p>1) Don't publicise disputes whilst you're trying to resolve them.</p><p>2) Don't publish private emails.</p><p>Even though some people seem to not believe in these principles, or at least don't follow them, for now I'm going to stick by them.</p><p>The complete disregard for number 2 in many quarters makes it difficult for me to even chat to people privately about a lot of these things at the moment.</p><p>So, for now at least, it looks like everyone will just have to choose whether or not to believe the gossip. And I'll just have to continue to be surprised at some of the people who do.</p> tmtm 2005-08-02T00:34:05+00:00 journal So far but not quite near enough. http://use.perl.org/~tmtm/journal/1803?from=rss <p>Spent most of today hacking on <a href="http://search.cpan.org/search?dist=Class-DBI">Class::DBI</a>. </p><p>Tatsuhiko Miyagawa has pulled out the 'trigger' code that I wrote to allow <a href="http://search.cpan.org/search?dist=Class-DBI-mysql-FullTextSearch">Class::DBI::mysql::FullTextSearch</a> to happen, so I was able to pull that all back out again and replace it with the single line:<br> &nbsp; <tt>use Class::Trigger</tt></p><p>Then I came up with a way to add a pre-insert trigger, which meant I was able to add the first version of constraints, and will now provide a much better way of allowing default values that can't be specified at the database (e.g. MySQL doesn't allow CURDATE() as a default, and you currently have to do much madness to implement this in Class::DBI). </p><p>I also had one of those "blinding flash of the obvious" moments on Christmas Eve, when I realised that, although it's quite unorthodox in database terms, Class::DBI really needs an ON SELECT trigger. So I added that, and now it makes it ludicrously simple to add code to, for example, convert all 'DATE' fields to Date::Simple objects as they get retrieved from the database. </p><p>I just need to finish off the new Cookbook, and I can release this version. </p><p>But before I could do that I got much too waylaid by a nasty memory leak, somewhere within the Class::DBI -&gt; Ima::DBI -&gt; DBI chain. My process to rebuild the Music Database kept getting bigger and bigger and bigger. It took about 2 hours to even find out <i>where</i> it was happening, and I still haven't worked out <i>why</i>. </p><p>There's some sort of nasty collision somewhere in the cached $sth code, but trying to get my head around all those closures, inheritable class-data lookups, and barely documented features of DBI just proved too much for today. </p><p>And tomorrow I really need to finish off some client work<nobr> <wbr></nobr>...</p> tmtm 2001-12-27T22:19:56+00:00 journal Untainting dates http://use.perl.org/~tmtm/journal/1679?from=rss <p>One of my personal bugbears is web forms which make you jump through lots of hoops to enter dates - particularly the ones which make you guess what those hoops are. </p><p>So, for a client job recently which needed a date field, I wrote a 'date' plugin for <a href="http://search.cpan.org/search?dist=CGI-Untaint">CGI::Untaint</a> which used Date::Manip to parse the date in whichever format you entered it ("2001-12-12", "12th December", "last Monday", "third tuesday in March", etc.) and then feed it to <a href="http://search.cpan.org/search?dist=Date-Simple">Date::Simple</a>, so we'd end up with a standard format (with a nicely overloaded stringification for easy entry straight into a database - through <a href="http://search.cpan.org/search?dist=Class-DBI">Class::DBI</a>, of course). [with credit to Simon Burns for the original idea]. </p><p>The client loved it. Everything seemed great. I uploaded <a href="http://search.cpan.org/search?dist=CGI-Untaint-date">the module</a> to CPAN. </p><p>Then I installed it on one my own sites, and everything fell over. Because ironically, the resulting value wasn't taint safe! </p><p>It turns out that Date::Manip isn't taint safe at all, doing lots of shell-type things to work out your timezone. </p><p>This puzzled me for quite some time. And then yesterday I had a brainwave. Recalling Damian's diary entry on <a href="http://www.yetanother.org/damian/diary_September_2001.html#day_20">locally replacing subs</a>, I threw in a:<br> <tt>&nbsp;&nbsp;local *Date::Manip::Date_TimeZone = sub { 'GMT' };</tt> <br>and everything was rosy again! (We only need dates, not times, so this shouldn't even cause any problems anywhere...) </p><p>Which got me to wondering about how to ensure that all my test suites work in a taint clean manner. Although make test can handle the -T option on the shebang line, running the test manually with <tt>perl -Ilib</tt> gives us the old <tt>Too late for "-T" option</tt> error. </p><p>I really need to read up on all the deep magic I can do with ExtUtils::MakeMaker to see if there's some nice way of adding something in there<nobr> <wbr></nobr>... </p><p>UPDATE: </p><p>Doh! </p><p>All I need to do, of course, is <tt>perl -TIlib</tt>. </p><p>Of course, I still want to read up more on the magic of MakeMaker<nobr> <wbr></nobr>...</p> tmtm 2001-12-16T20:38:33+00:00 journal The Great Class::DBI Clean Up http://use.perl.org/~tmtm/journal/1669?from=rss <p>The great Class::DBI clean up continues. </p><p>Today I pulled about 150 lines out of the main module into a support module. This was pretty hairy as it was the code that handled all the 'relationships' between classes - which is pretty important stuff for a module that handles database mappings! </p><p>I originally attempted to do this via mixins - basically just exporting all the methods I needed. But some of the methods over in Class::DBI proper needed to play with all the relationship data too, so I ended up exporting almost every method, including supposedly 'private' ones, which is always a worrying sign. </p><p>Thankfully the hooks I'd added when I was writing the <a href="http://search.cpan.org/search?dist=Class-DBI-mysql-FullTextSearch">Class::DBI::mysql::FullTextSearch module</a> proved their worth. So I was able to take code, such as that for cascading delete, which needed to follow the relationship path, and implemented it trivially in the helper module just registering a delete hook. </p><p>Unfortunately, the other major point in Class::DBI where standard behaviour changes if there are relationships is <tt>create()</tt>. If you try to create with a field set to a related object rather than just its id <br> <tt>&nbsp;&nbsp;CD-&gt;create({ title =&gt; $title, artist =&gt; $artist })</tt> <br>instead of <br> <tt>&nbsp;&nbsp;CD-&gt;create({ title =&gt; $title, artist =&gt; $artist-&gt;id })</tt> <br>then it needs to DWIM. And we have no <tt>pre_create</tt> hook as there is no object at that point we can play with<nobr> <wbr></nobr>:( </p><p>For now, I've just implemented a <tt>_tidy_creation_data</tt> method which does nothing in Class::DBI proper, but which gets overridden when you set up a relationship to one that downgrades embedded objects to their ids. </p><p>I don't like this though, and I need to find a better way<nobr> <wbr></nobr>...</p> tmtm 2001-12-16T00:03:32+00:00 journal "The approximate delay for your decision is about 2.5 years" http://use.perl.org/~tmtm/journal/1601?from=rss <p>This morning I went to hear <a href="http://c2.com/cgi/wiki?TomGilb">Tom Gilb</a> speak. When I first heard he was coming to Belfast, I was quite excited; but then I heard he was speaking on software inspection, which sounded quite dull. It turned out to very interesting, although (or perhaps because?) he only managed to make it through less than 20% of his slides! </p><p>After pointing out the "so obvious, that no-one ever gets it" fact that inspections differ from reviews in that inspections are checking against a well defined 'standard', Tom proceded to give his three rules for inspecting a requirements document: </p><ol> <li>Unambiguous to the intended readership</li> <li>Clear enough to test</li> <li>No design specifications mixed in</li> </ol><p>I've been immersed in the whole XP / Rapid Development culture for so long that I'd almost forgotten that there were people who still used 800 page requirements documents to write their design specs etc. But it's interesting to see the way that XP has taken a lot of the work that people have done in the Big Process Methodology field and totally shifted the goalposts. </p><p> <i>Clear enough to test</i> is a classic example of this. XP pretty much says that requirements *cannot* be untestable, as the requirements get expressed as tests! If something passes all the tests, then it's finished. If it's missing something, then write a test that exposes it. </p><p>As a developer, I've found this to be a great mindset to code under. I'm a complete convert to test-first programming. However, I haven't yet managed to convert clients to the mindset for acceptance testing. It's generally hard enough to get people to tell you what they think they want, without them having to come up with repeatable tests that 'prove' that the system works. I still like the idea though - maybe I just need to come up with a way of presenting it to a client that makes it sound good! </p><p> <i>In other news</i>, it seems my Test vs Overload problem boiled down to the fact that when overloading you need to either provide a sensible method to call for each overloadable thing, or provide a 'fallback'. Adding a fallback made it all work. </p><p>But I also learned in the process that perl treats <br>&nbsp;&nbsp;<tt>print scalar(my($foo) = "bar");</tt> <br>very differently than <br>&nbsp;&nbsp;<tt>print scalar(my $foo = "bar");</tt> </p><p>So Test::More's ok function, which is prototyped $;$, coercing scalar context, treats these differently too... </p><p>I've also had problems recently with Template Toolkit and Class::DBI not playing well together. For the most part, they're a wonderful combination - pass a single Class::DBI object representing a row of your database into your template and you have methods representing each of the columns, as well as more complex structures representing your relationships: <br> <tt>&nbsp;&nbsp;[% FOREACH track = cd.tracks %]<br> &nbsp;&nbsp;&nbsp;&nbsp;- [% track.title %] by [% track.artist.name %]<br> &nbsp;&nbsp;[% END %]</tt> </p><p>One of TT's (many) wonderful features, is that it just DWIMs on the '.' character, giving you a hash element, or array element, or call a method on an object or whatever it needs to do (the above TT code wouldn't change at all if I had a hash of hashrefs instead of an object containing other objects etc..). However, this means that when you pass it a one element list, it will treat it as a long scalar. </p><p>In normal circumstances you can call<nobr> <wbr></nobr>.list on this to force TT to treat it like a list, and access<nobr> <wbr></nobr>.first, or suchlike. But, only if it's unblessed. If it's blessed it'll try to call the first() method instead (and fail if you don't have such). </p><p>Or should I say, 'it used to try', as a couple of posts to the TT list about this, and Hey Presto, Andy has patched everything to just DWIM. </p><p>I really love the world where you can leave the office at night with code that doesn't work, and return in the morning to discover it can, without your code even having been touched in the process<nobr> <wbr></nobr>:)</p> tmtm 2001-12-11T20:18:23+00:00 journal Phone Bills and overloading http://use.perl.org/~tmtm/journal/1581?from=rss <p>Today I got my password for BT's "View My Bill" service. After spending a while playing around with the fact that you can enter names against phone bills and then view the bill with names instead of numbers, I decided I really liked this feature<nobr> <wbr></nobr>... </p><p>... except for all the problems. </p><p>Particularly the way you can enter multiple numbers against the same person or company, except it won't recognise that fact on your bill, so you have to create a different entry in your address book for every number. </p><p>Which would be bad enough, except they also restrict you to 75 entries. </p><p>So, I decided it would be fun to download this, dump it to a local database, and then write a simple front-end to let me do it myself. Which would also go back as far as I wanted and not just my last 3 bills. </p><p>And they conveniently let you download CSV format, so I don't even need to do all the screen-scraping stuff that I started to do before I thought to check! *doh* </p><p>So, I put together a <a href="http://search.cpan.org/search?dist=Data-BT-PhoneBill">simple module</a> to parse that, and decided it would be fun to have an interface that overloaded the iterator: </p><p> <tt> my $bill = Data::BT::PhoneBill-&gt;new($filename);<br> <br> while (my $call = $bill-&gt;next_call) {<br> &nbsp;print $call-&gt;date, $call-&gt;time, $call-&gt;destination,<br> &nbsp;&nbsp;$call-&gt;number, $call-&gt;duration, $call-&gt;cost;<br> &nbsp;}<br> }<br> </tt> </p><p>So I wrote my tests, and tried the code. And everything collapsed. In quite serious fashion: </p><p> <tt> Operation `!': no method found, argument in overloaded package Data::BT::PhoneBill at<nobr> <wbr></nobr>/usr/local/lib/perl5/site_perl/5.6.1/Test/Builder.pm line 255.<br> WHOA! Somehow you got a different number of results than tests ran!<br> This should never happen! Please contact the author immediately!<br> END failed--call queue aborted.<br> </tt> </p><p>After a lot of puzzlement I eventually tracked everything down to a small failing example. It seems Test::Builder doesn't work very well with overloading: </p><p> <tt> #!/usr/bin/perl -w<br> use strict;<br> package Eek;<br> use overload '' =&gt; \&amp;get_next;<br> sub new { bless {} }<br> sub get_next { 1 }<br> <br> package main;<br> use Test::More tests =&gt; 1;<br> ok my $foo = Eek-&gt;new, "We got an Eek";<br> </tt> </p><p>So, playing with all this means I never got to write my database stuff, and I'll probably have to do some "real work" for the rest of the week. </p><p>Oh well.</p> tmtm 2001-12-10T18:30:56+00:00 journal The perils of efficiency http://use.perl.org/~tmtm/journal/1564?from=rss <p>Today I spent a long time banging my head off Class::DBI, and managed to chop another 200 or so lines out of it, in the never-ending clean-up quest. </p><p>Some of it was simple, like discovering that its 'rollback' method looked for the values you'd changed, and reloaded those from the database. So instead I made it just lose all memory of those, and let its normal 'lazy loading' mechanism fetch them the next time you asked for them. </p><p>Other bits were hairier, but deeply satisfying, like removing its support for pseudo-hashes. I don't think anyone actually ever tried to use this, and if they did they're much too sick. Getting rid of this also allowed me to lose two modules from its multiple-inheritance tree. (Not that it ever actually <i>needed</i> them there, due to their (accidental?) mix-in behaviour.) </p><p>But far and away the scariest bit was untangling a twisted maze of parallel class data structures. When you set up a Class::DBI class you tell it information about your database table: not just how to connect to it, but what the columns are, and how to group them. Then, when you call a method corresponding to one of the columns it works out what column groups it's in, and what other columns are in those groups, and fetches all those at the same time, on the assumption that if you've grouped them together well, you'll probably want to get these values soon anyway, and we may as well save a trip to the database. </p><p>So, for efficiency, we had two different data structures - one mapping columns to groups and one mapping groups to columns. In class data. With a lot of little support methods to look after all the fancy cases. </p><p>But, like most things that get implemented for efficiency's sake, it was fast becoming unmaintainable. So, I ripped it all apart to only store the data once, and just look it up both ways around. </p><p>The result? Code that's much easier to maintain and extend, and a performance hit that seems to be less than 0.3%. </p><p>And having done all that, I think I can see a few ways in which the higher level performance of this can be tweaked, probably resulting in a nice net gain, as well as cleaner code. </p><p>Another victory for the <a href="http://c2.com/cgi/wiki?FirstRuleOfOptimization">Rules of Optimisation</a>.</p> tmtm 2001-12-09T22:10:57+00:00 journal it's like shedding your skin http://use.perl.org/~tmtm/journal/1556?from=rss <p>When BlackStar happened, it all seemed to happen too fast. It took over about four and half years of my life, and I can't really differentiate very much of it. (Other than the 'this is where it stops being fun' turning points...) </p><p>So, now that I've moved on, and have a new set of plans for Total World Domination(tm), a few people have suggested I keep a journal of it. </p><p>So, I guess I can do some of that here... </p><p>One thing I'm really keen on resurrecting is The Music Database. This was one of the things I worked on before BlackStar - basically a web front end to the CDDB project (the thing that auto-fills your playlist info when you put a CD in). The grandiose version was to use that as a basis for constructing the music version of <a href="http://www.imdb.com/">IMDB</a>, but before we got anywhere near there we had a big old fight with CDDB, just as they were turning commercial and deciding that all the user-submitted data actually belonged to them. </p><p>So now, five years on, CDDB have fallen into much disfavour, and <a href="http://www.freedb.org/">freedb</a> has picked up the mantle of keeping the whole thing open. And it makes me think this is doable in again. </p><p>So, I've downloaded the latest database, talked to the freedb guys about ways forward, knocked up a <a href="http://search.cpan.org/search?dist=CDDB-File">simple module</a> for parsing their files, and starting playing...</p> tmtm 2001-12-08T11:12:14+00:00 journal