drhyde's Journal http://use.perl.org/~drhyde/journal/ drhyde'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:05:08+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 drhyde's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~drhyde/journal/ Bryar security hole http://use.perl.org/~drhyde/journal/39045?from=rss Bryar 3.0 has a security hole which 3.1 fixes. Yeah yeah, I know, I said I'd abandoned this blog. But this is *important*, damnit! drhyde 2009-05-28T22:06:10+00:00 journal Leaving use.perl (for real this time) http://use.perl.org/~drhyde/journal/39016?from=rss <p>I'm gonna stop blogging here. Not because of the nice grey background or the lack of rounded corners or not being able to upload images that other people have whined about. I'm mostly irritated at being occasionally logged out between me reading someone's journal entry and me posting a comment. And even worse, at the same sometimes happening while I write a journal entry. I could put up with that while this place still had a "critical mass" of people whose journals I regularly read, but as more and more of them go elsewhere, the irritation becomes more important. </p><p>So I'm taking my perl blogging to <a href="http://www.cantrell.org.uk/david/journal/index.pl/keyword_perl">part of my main blog</a>. There's a <a href="http://www.cantrell.org.uk/david/journal/index.pl/keyword_perl?format=rss">perl-specific RSS feed</a>. Or if you want other geeky stuff as well, use the '<a href="http://www.cantrell.org.uk/david/journal/index.pl/keyword_geeky">geeky</a>' <a href="http://www.cantrell.org.uk/david/journal/index.pl/keyword_geeky?format=rss">keyword</a>. </p><p>The first new entry is there, with a nifty hack for doing #includes in POD.</p> drhyde 2009-05-21T19:24:27+00:00 journal Leaving use.perl http://use.perl.org/~drhyde/journal/39008?from=rss So, to those of you who are leaving use.perl for shinier (if not greener) pastures - where are you all going? Having everyone in one place with one user interface was ever so convenient, even if the user interface doesn't have rounded corners. drhyde 2009-05-20T14:19:02+00:00 journal Book review: The Satyricon of Petronius Arbiter http://use.perl.org/~drhyde/journal/38961?from=rss <p>This is rightly hailed as a classic, being one of the clearest accounts of day-to-day Roman life for those outside the nobility and political and military elite during the Empire. And of course it is a fine example of political satire, with many subtle and not-to-subtle digs at public figures and writers of the era. All of this makes it a great <em>academic</em> read. And as such, I enjoyed it. </p><p>Unfortunately, it's a lousy novel. That's not the author's fault, but is simply because large chunks of the text have been lost over the last 1900 years so there are jarring gaps. While we can, to a limited extent, reconstruct parts of it, all that tells us is what the broad arc of the story might have been. You could cut chunks out of any good story, and then largely rebuild the tale, but if you were to read it with those chunks missing (which is the case with my copy of the Satyricon, which lacks even the briefest of inline notes about the missing sections) it would still not be a good read. It's almost a pity that the practice of translators/editors filling in the blanks themselves hasn't taken off, at least for mass-market paperbacks. But then, I suppose, there <em>isn't</em> a mass-market because it's not about some ghastly footballer or pig-faced slag from Essex. </p><p>This is, unfortunately, one only for those with an academic interest in the era.</p> drhyde 2009-05-12T14:43:10+00:00 journal Bug fixes and hot chicks http://use.perl.org/~drhyde/journal/38865?from=rss <p>New versions of Devel-CheckOS, Number-Phone-UK, and CPAN-FindDependencies recently. The first two fix some rather subtle bugs, the last just updates a dependency to require a new version of Parse::CPAN::Packages that doesn't conflict with the latest Moose. </p><p>And the hot chicks? Well, from <a href="http://rt.cpan.org//Ticket/Display.html?id=45310">my RT.CPAN queue</a>: "hello My name is miss Mabel Dagba i saw your profile here<nobr> <wbr></nobr>... today and became intrested in you". Awesome! Someone who wants to spend time with me, in hot steamy evenings of bug-fixing!</p> drhyde 2009-04-25T11:55:28+00:00 journal cpXXXan bugfix http://use.perl.org/~drhyde/journal/38847?from=rss <p>Oops. In cases where the most recent version of a distribution was a developer-only release it was preferring to index that than the public release, but also realising that it shouldn't index developer-only releases. End result: Module-Build 0.32 not being indexed because the most recent version is 0.32_01, and so all kinds of modules that depend on it not working from this 'ere mirror. </p><p>Fixed now.</p> drhyde 2009-04-22T16:07:51+00:00 journal More Easter hackage - CPAN::FindDependencies update http://use.perl.org/~drhyde/journal/38792?from=rss <p>A year to the day after Ian Tegebo sent me a patch for CPAN::FindDependencies, I've finally applied it, hacked on it a bit, and released it. </p><p>With Ian's magic, it can now resolve dependencies for distributions where there's no META.yml but there is a Makefile.PL. Since this involves downloading stuff form the intertubes and executing it, this feature is disabled by default. </p><p>Obviously, I won't enable this on <a href="http://deps.cpantesters.org/">deps.cpantesters.org</a>.</p> drhyde 2009-04-11T17:43:46+00:00 journal Easter hackage http://use.perl.org/~drhyde/journal/38789?from=rss <p>So, about 2000 years ago, Jesus died so that we could have a four day weekend. What a nice chap! </p><p>I spent the first of those four days cleaning up my RT.CPAN queues and fixing some problems that CPAN-testers had found with my modules - see the shiny new versions of File::Overwrite and Palm::Treo680MessagesDB. </p><p>Unfortunately, these were problems that only showed up on Windows. Even with the excellent <a href="http://strawberryperl.com/">Strawberry Perl</a>, Windows is incredibly hard to use, so this was very frustrating. I think I'd actually rather have not had the time, as it ended up just being a few hours of misery. So the bastard was kidding all along, he didn't die so I could have a <em>nice</em> four day weekend. DAMN YOU JESUS.</p> drhyde 2009-04-11T13:54:15+00:00 journal Announcing the CP5.6.2AN http://use.perl.org/~drhyde/journal/38755?from=rss <p>I think I've worked all the serious bugs out of the CP5.6.2AN, so as of this afternoon, my perl 5.6.2 testing machine is using <a href="http://cp5.6.2an.barnyard.co.uk/">http://cp5.6.2an.barnyard.co.uk/</a> as its CPAN mirror. It is a BackPAN with a custom 02packages file which lists the modules in the latest version of each distribution to have a PASS result in the CPAN-testers database for perl 5.6.2. </p><p>Because it's an up-to-date backpan I can still ask it for things like A/AU/AUTHOR/New-Dist-1.0.tar.gz and test them (even if there's no passes in the database, so no entries in the index), but when the Build.PL or Makefile.PL specifies Some::Module as a dependency, it will look in the index and find a version of that module that works on the perl I'm testing with, so even if the most recent version of Some::Module doesn't work on 5.6.2, I can still test to see whether New-Dist does. Hurrah! </p><p>There's also a version for perl 5.8.8, and I can very quickly add other versions on request. </p><p>Both sites update shortly after 6am every morning, and source code is available <a href="http://www.cantrell.org.uk/cgit/cgit.cgi/cpxxxan/">here</a>. If you would like to clone my git repo, email me to ask for the username/password. </p><p>The aim of this project is to minimise the pain if for some reason you are stuck on an old version of perl. This includes 5.8.x, as there are now modules where the latest version only works on perl 5.10.</p> drhyde 2009-04-04T16:15:09+00:00 journal QA Hackathon: CPXXXAN is almost ready http://use.perl.org/~drhyde/journal/38731?from=rss <p>At the recent QA Hackathon in Birmingham (which was great - many thanks to Birmingham.pm for organising it, and to the hotel for having a rubbish network so I actually worked instead of dicking around on IRC) I worked on my idea for the Comprehensive Perl $version Archive Network, or CPXXXAN for short, mostly so I can make jokes about hot module-on-module action. </p><p>It is intended to be a set of CPAN "mirrors" which only contain distributions which pass their tests on a particular version of perl, with their 02packages index files set up correctly so that if, eg, you go to the mirror for perl 5.6.2, you'll get DBI 1.604, <a href="http://bbbike.radzeit.de/~slaven/cpantestersmatrix.cgi?dist=DBI;maxver=1">which works</a>, instead of DBI 1.607, <a href="http://cpansearch.perl.org/src/TIMB/DBI-1.607/Makefile.PL">which doesn't</a>. </p><p>While you might think that this is pointless - the argument is that "people who don't upgrade perl won't want to upgrade modules" - consider that recent releases of some distributions now require perl 5.10, even though that's only just over a year old. 5.6.2 just makes a convenient test case. </p><p>In Birmingham, I tested it and got it all working on my laptop, using a subset of the data (specifically, distributions beginning with DBI or DBD). Now I'm building the 5.6.2 index for the whole of the CPAN. It's taking a very long time, but I'm not that concerned, as I'm unlikely to update the indices more than once a month. Even so, any Clues about how to make my SQL more efficient would be most welcome. See <a href="http://www.cantrell.org.uk/cgit/cgit.cgi/cpxxxan/tree/schema.sql">the schema</a> and <a href="http://www.cantrell.org.uk/cgit/cgit.cgi/cpxxxan/tree/build02packages.pl">the query</a> that figures out what the most recent passing distribution is and what modules are in it. </p><p>All the code if in my git repo, email me if you want access.</p> drhyde 2009-03-31T20:04:26+00:00 journal Palm::ProjectGutenberg http://use.perl.org/~drhyde/journal/38710?from=rss <p>A few days ago I released a hacky script that re-formatted e-books from <a href="http://gutenberg.org/">Project Gutenberg</a> so they worked better on a small screen and then used a third-party utility to convert them to Palm Doc format. </p><p>To make it easier for non-geeks to install, I've re-written it as a module on the CPAN (with a supporting script that gets installed at the same time) which uses Palm::Doc instead. </p><p> <strong>BEHOLD!</strong> <a href="http://search.cpan.org/search?query=projectgutenberg">Palm::ProjectGutenberg</a>.</p> drhyde 2009-03-27T11:01:12+00:00 journal XML::Tiny update http://use.perl.org/~drhyde/journal/38685?from=rss XML::Tiny has gained a feature. It now has a sort-of DOMmish interface. drhyde 2009-03-22T21:20:00+00:00 journal Converting to git http://use.perl.org/~drhyde/journal/38613?from=rss <p>I wanted to be abe to commit to my CVS repository while I was offline - eg while using my laptop on a train. But CVS doesn't support that, and to make it pretend to support it would involve some quite monstrous hacks. Of the commonly used VCSes, only git supports offline commits, so I decided to try that instead. There are some excellent instructions <a href="http://kernel.org/pub/software/scm/git/docs/v1.4.4.4/cvs-migration.html">here</a> which mostly Just Work. </p><p>Mostly. </p><p>There are two small flaws. First, it died importing <a href="http://drhyde.cvs.sourceforge.net/viewvc/drhyde/perlmodules/Number-Phone/lib/Number/Phone/UK/Data.pm?view=log">this file</a>. I couldn't be bothered to analyse why, and just deleted it and its history from the local copy I'd made of the repository (I used rsync to suck it down from Sourceforge). Contrary to the documentation, 'git cvsimport' does <em>not</em> carry on where it left off if it gets interrupted half way through, so once I'd deleted the offending file I had to also delete the broken git repo and start again. Once it had finished I then added the most recent version of the file to the git repo in the usual way. So I lost the history of that file. Thankfully it doesn't matter in this case. </p><p>The second flaw is a minor one. It tells you to delete the repo's contents leaving just the<nobr> <wbr></nobr>.git directory, thus making it a "bare" repository. But it doesn't tell you that you have to edit<nobr> <wbr></nobr>.git/config and set the "bare" variable to true. If you don't do that, you'll get spurious warnings when you do a 'git push'. </p><p>First impressions of using git as "CVS with offline commits" are good. It works very well for a single user editing code in various different places throughout the day. I have yet to experiment with multiple concurrent edits. While I'm sure it works well if you use git in a distributed fashion, I still don't <em>quite</em> trust it to work in a similar fashion to CVS, with multiple users pushing changes to a central repository. But if I have any problems, you can be sure I'll grumble here about them.</p> drhyde 2009-03-07T20:40:10+00:00 journal Embarrassment http://use.perl.org/~drhyde/journal/38581?from=rss <p>I am embarrassed - nay, ashamed! - to have to confess that I didn't bother to run the code through all my various CPAN-testing machines before releasing it, and so I let something escape which only works on perl 5.10. Aaiieeeee! </p><p>Mind you, you'll only notice the bug on 64-bit platforms and there's not a lot of 64 bit perl 5.8 or 5.6 around.</p> drhyde 2009-03-03T10:38:40+00:00 journal Module updates http://use.perl.org/~drhyde/journal/38555?from=rss <p>I fixed a fairly major bug in File::Find::Rule::Permissions (it was interpreting the 'other' access bits as being permissions for all users, as opposed to all except the owner and users in the owning group) and also added tests. Yes, it now has real tests. OK, so they're all mocked up because to do <em>real</em> real tests you'd need to be root so you could create files with weird owner/group/permission combinations. Actually, they're not all mocked up, because if you're stupid enough to run the tests as root then exactly the same tests run for real. </p><p>Second, I've fixed a cosmetic bug in Number::Phone::UK, and added some stuff to Number::Phone::Country (thanks to Michael Schout) so that it can tell you what the national and international dialling prefixes are for any country. There's also the usual UK phone number allocations database update.</p> drhyde 2009-02-26T18:11:37+00:00 journal More on purity http://use.perl.org/~drhyde/journal/38302?from=rss <p>Lyle pointed out another problem with how <a href="http://deps.cpantesters.org/">CPANdeps</a> detects distributions that contain both XS and a "pure perl" alternative implementation. Some distros name the pure-perl implementation Blah::PP or something similar, instead of Blah::PurePerl. Unfortunately, PP can mean a few other things too. The only way to get this absolutely right is to manually examine all distributions that look like they might contain some non-perl code, so rather than do that and build a database that the application can use (a database that would go out of date overnight), I took the lazy route and just wrote up some <a href="http://deps.cpantesters.org/static/purity.html">explanatory notes</a> on exactly how the "purity" option works. </p><p>For authors who want to help my heuristic show the right result for your modules, then all you need to do is include the string "pureperl" (it's case-insensitive) in your MANIFEST file.</p> drhyde 2009-01-16T13:12:43+00:00 journal Purity bugfix in CPANdeps: argh /x! http://use.perl.org/~drhyde/journal/38071?from=rss Lyle pointed me at a bug in CPANdeps when you tell it to report on whether modules are "pure perl" or not. It got it wrong for Finance::IIF. I eventually tracked it down to this code in the parser for MANIFEST files<nobr> <wbr></nobr>... <p><nobr> <wbr></nobr><code>... =~ /<nobr> <wbr></nobr>...( |$)/ix</code> </p><p>which looks for some stuff, followed by either a space or the end of a line. It uses<nobr> <wbr></nobr>/x so I can break the regex over multiple lines and have comments in it. But of course,<nobr> <wbr></nobr>/x makes the regex parser not only ignore those extra newlines and the leading spaces I put on the following lines so that my code is nicely indented, it also makes it ignore that rather important space that I actually want to look for. Gragh! Replaced it with \s. Which was, of course, wrong, as \s also matches (some) end of lines. So now it's \x20.</p> drhyde 2008-12-11T15:38:07+00:00 journal Perl isn't dieing http://use.perl.org/~drhyde/journal/38039?from=rss <p>Perl isn't dieing, but it tells me that it wishes it was. Last night it went out on the piss with Python and Ruby (PHP was the designated driver) and it did rather too many cocktails. It isn't quite sure what happened, but it woke up in the gutter in a puddle of its own fluids and its head hurts a lot. </p><p>It asked me to ask you all to keep the volume down.</p> drhyde 2008-12-06T18:15:43+00:00 journal EPIC IBM FAIL http://use.perl.org/~drhyde/journal/37737?from=rss <a href="http://use.perl.org/~drhyde/journal/36984">A few months ago</a> I posted about how GNU Hurd CPAN-testers had over-taken VMS and were catching up with OS/2. Well,<nobr> <wbr></nobr>...<blockquote><div><p> <tt>&gt; select count(*) c, os from cpanstats group by os order by c desc;<br>3071,'HP-UX'<br>607,'SCO'<br>350,'MirOS BSD'<br>323,'GNU Hurd'<br>230,'OS390/zOS'<br>...<br>87,'AIX'<br>...<br>18,'OS/2'<br>...</tt></p></div> </blockquote><p>Oh dearie me. Fittingly, the next vendor in the Hurders' sights is SCO.</p> drhyde 2008-10-25T13:00:45+00:00 journal CPANdeps efficiency improvements http://use.perl.org/~drhyde/journal/37736?from=rss <p> <a href="http://deps.cpantesters.org/">CPANdeps</a> has been getting more heavily used recently, and all of the users hitting my shonky code have been occasionally DOSsing the server. That's because the old code would eat up to 134MB of memory to generate a set of results. And that's because I was using Parse::CPAN::Packages to convert from module names to package names. That reads the entire 02packages file into memory and converts it into a very large data structure. </p><p>The new version of the code stores that in the database instead, so instead of using 134MB I now only use 25MB per request. This means that I'm hitting the database harder, but even so, things should still run a lot better because even serving 25 requests in parallel (the maximum it's configured to do) it will only need 625MB, so you won't all be fighting over swap space. </p><p>I would like to thank Jonathan Rockway once again for writing the excellent CPANdeps test suite which lets me be confident that the site still works just as it did before. His test suite is available on the CPAN as <a href="http://search.cpan.org/search?query=angerwhale">Angerwhale</a><nobr> <wbr></nobr>:-)</p> drhyde 2008-10-25T12:43:42+00:00 journal CPANdeps can now ignore developer builds of perl http://use.perl.org/~drhyde/journal/37580?from=rss <p>The CPAN-testers sometimes use developer releases of perl. This helps in two ways. First of all, it notifies authors of things that might be about to change in the next stable release of perl so that they can fix them before real users are effected. Second, it helps find freshly created bugs in bleadperl. But ordinary users don't care about that, as they only use stable releases. And so <a href="http://deps.cpantesters.org/">CPANdeps</a> has grown a new feature. As well as filtering to only look at results for a particular version of perl, you can also filter to only look at <em>stable releases</em>. This is the default setting. If you want to include test results from developer releases of perl, you need to explicitly turn that on. </p><p>This is subtlely different from just selecting a version of perl. If you choose 5.8, for example, you would get test results from the unstable 5.8.9-to-be as well as the ones that you actually care about. If you choose 5.10.0, you would get test results for 5.10.0-patch-12345 which was very shortly <em>before</em> the stable release. </p><p>Also please note the new canonical hostname for CPANdeps, <a href="http://deps.cpantesters.org/">deps.cpantesters.org</a>. This, and the fact that the <a href="http://drhyde.cvs.sourceforge.net/drhyde/perlcpandeps/">source code is available</a>, means that when I eventually lose interest, someone else can take over maintenance.</p> drhyde 2008-09-30T23:21:06+00:00 journal Bits of Bryar are going away http://use.perl.org/~drhyde/journal/37399?from=rss <p>If anyone here is using the <a href="http://search.cpan.org/~dcantrell/Bryar-3.0/">Bryar</a> blogging tool, originally written by Simon Cozens and now maintained by me, and has any objection to me deleting the following components, please yell now! </p><ul> <li>mod_perl support</li> <li>DBI support</li> <li>Flatfile::Dated</li> </ul><p>I have decided to clear out a load of dead code. mod_perl support isn't maintained anyway. I have decided that DBI and Flatfile::Dated are dead because: </p><ul> <li>I don't use them</li> <li>there are no tests for them</li> </ul><p>This is as part of a big clean-up which will also include making sure that there is adequate test coverage.</p> drhyde 2008-09-10T15:43:04+00:00 journal Keeping things in perspective http://use.perl.org/~drhyde/journal/37356?from=rss <p>There's been lots of kerfuffle recently about the CPAN-testers. Two people in particular have been complaining very loudly. A tiny number of other people have chimed in briefly alongside them. </p><p>Genuine problems have been identified, and either fixed quickly or at least a plan to fix them in the long term has been explained. And yet the loud complaints continue. </p><p>I wonder what those people expect. As far as I'm concerned, having half a dozen out of nearly 7000 "customers" complain demonstrates that the sky isn't falling in. Doubly so when you count the number of people who write to testers to thank them for their work. Why, I'd need to take my socks off to count all those who have told me that what I'm doing is useful and that they're grateful for it! </p><p>Given humans' tendency to only speak up when they don't like something and to keep schtum when they're happy (just look at any restaurant review site that lets the hoi polloi post!), I think that shows that we're both getting it right almost all the time, and providing a useful service. </p><p>Even so, let me reiterate here what I've said elsewhere - if any of you don't want me to send you reports, please email me to let me know.</p> drhyde 2008-09-04T22:06:18+00:00 journal Segfault! Panic! http://use.perl.org/~drhyde/journal/37008?from=rss <p>Oops, I made perl segfault. All I was trying to do was assign a closure (which in turn calls another closure, which<nobr> <wbr></nobr>...) to a typeglob. It's especially irritating to me because this happens in 5.8.8 but not in 5.10.0, and happened right after I'd advised someone on IRC to avoid 5.10 until 5.10.1 came out*<nobr> <wbr></nobr>:-) </p><p>The only reason I needed to assign my code to a typeglob is because I need a subroutine name so I can use it to <code>sort</code> by. It would really help if <code>sort</code> would take a subroutine reference but it doesn't it takes a block or a subroutine <em>name</em>. Grump. </p><p>Interestingly, if I twiddle things around a little bit, (eg adding a completely unrelated Data::Dumper::Dumper call) the segfault is sometimes there sometimes not. Sometimes I get "panic: memory wrap", sometimes a segfault, sometimes both, and sometimes "Bizarre copy of ARRAY in aassign at<nobr> <wbr></nobr>.../Test/More.pm line 795". Yay Heisenbug! </p><p>* I've got no particular reason for that, other than the usual paranoia about<nobr> <wbr></nobr>.0 releases of <em>any</em> software</p> drhyde 2008-07-24T16:36:08+00:00 journal Come on VAX-herders! http://use.perl.org/~drhyde/journal/36984?from=rss <p>Yesterday, GNU HURD overtook VMS in the CPAN-testers league table<nobr> <wbr></nobr>... </p><p> <code> &gt; select count(*) c, os from cpanstats group by os order by c desc; <br>... <br>136,'OSF' <br>87,'AIX' <br>68,'Dragonfly BSD' <br>19,'BSD OS' <br>18,'OS/2' <br>10,'GNU Hurd' <br>8,'VMS' </code> </p><p>So come on VAX-herders! Your honour is at stake! The OS/2 crowd had better watch out too. Loyal IBM corporate drones should be ashamed to be almost caught up by the smelly GNU hippies!</p> drhyde 2008-07-22T15:07:18+00:00 journal CPU::Z80::Assembler is all grown-up now http://use.perl.org/~drhyde/journal/36952?from=rss After I wrote CPU::Emulator::Z80, I needed an assembler so I could do anything with it. Rather than use any of the pre-existing ones, I thought it would be a good idea to write one in perl. So I did, and the ugly hack that was <a href="http://search.cpan.org/~dcantrell/CPU-Z80-Assembler-1.0/">CPU::Z80::Assembler version 1</a> was the result. And boy is it ugly. <p>I wasn't really expecting anyone to use it other than myself, but Paulo Custodio did, and he found bugs, and he <a href="https://rt.cpan.org/Public/Bug/Display.html?id=36991">sent patches, with tests</a>. He suggested some other improvements too, and I handed over maintenance to him. <a href="http://search.cpan.org/~pscust/CPU-Z80-Assembler-2.01/">Version 2</a> gone done grown up, with a real lexer/parser, proper #include files and everything. </p><p>I'm very grateful.</p> drhyde 2008-07-18T13:47:14+00:00 journal CPANdeps can now highlight non-perl dependencies http://use.perl.org/~drhyde/journal/36393?from=rss <p>At the user's request, <a href="http://cpandeps.cantrell.org.uk/">CPANdeps</a> has sprouted another tentacle. There's now a ticky box which, if enabled, makes it also fetch MANIFEST files for the entire dependency tree, and highlight any modules (actually distributions) that don't look like they're pure perl. The heuristic is simple. We assume that a distribution is pure perl unless it contains a file that ends in<nobr> <wbr></nobr>.xs,<nobr> <wbr></nobr>.c or<nobr> <wbr></nobr>.h, or it depends on Inline::*. But if there is any file in the distro whose name contains the string 'pureperl' (case-insensitive, naturally), then we assume that the distribution contains a pure perl version as well as the C-ish version. </p><p>If there's any other things I should look for, please use the "report bugs" link on the website.</p> drhyde 2008-05-12T17:51:22+00:00 journal CPANdeps downtime http://use.perl.org/~drhyde/journal/36037?from=rss <p>My apologies for the recent downtime on CPANdeps - it's Yahoo's fault. Their web crawler suddenly stopped obeying robots.txt, and so tried to spider all of the CPAN's dependencies. And on top of that, they're making requests every few seconds instead of every few minutes like a good robot should. Given that it takes more than a few seconds to generate the dependency tree, things went pear-shaped. Arseholes. </p><p>They're now banned with a mod_rewrite rule, and just for good measure I've limited the number of concurrent webby requests.</p> drhyde 2008-04-03T00:20:25+00:00 journal How useful closures are! http://use.perl.org/~drhyde/journal/35732?from=rss <p>As some of you may be aware, I'm working on a pure-perl Z80 emulator. Why? &lt;shrug&gt; Why not! And we can't go letting the <a href="http://search.cpan.org/search?query=Acme%3A%3A6502&amp;mode=all">6502 boys</a> have all the fun! </p><p>It also makes a very good example of how useful closures can be. Here's just one example. </p><p>The Z80 is an 8 bit processor, with several 8 bit registers. But it also has some 16 bit "reigster pairs", which are made up of two 8 bit registers that can be treated as a single larger register. For example, the 8 bit register B and C can be combined to make a 16 bit register BC. Any operation that changes B or C also changes BC, and vice versa. Now, to implement them, I could have lots of hairy logic so that any instruction that operates on BC actually operates on both B and C. But that would lead to lots of duplication of code, for all the register pairs, and for all the instructions that operate on 'em. </p><p>I already have a<nobr> <wbr></nobr>::Register8 class for an 8 bit register, and a Register16 class for real 16 bit registers such as the Program Counter (a register that points at the next instruction to execute) which store a value and have get() and set() methods. So, I thought, instead of putting lots of hairy logic in the instructions themselves, I could move it into the registers so I'd only have to write it once. The Register* classes already have a 'value' field for storing the register's current value. So I changed Register16 to have either a value field or a pair of 'get' and 'set' fields, depending on how the register was initialised in perl. If it has a value field, then get() and set() simply operate on that. But if instead it has get/set fields, then get() and set() call those code-refs instead. </p><p>So now, I can create a 16 bit register pair like this<nobr> <wbr></nobr>... </p><p> <code> my $BC = CPU::Emulator::Z80::Register16-&gt;new(<br> &nbsp;&nbsp;get =&gt; sub {<br> &nbsp;&nbsp;&nbsp;&nbsp;return 256 * $self-&gt;register('B')-&gt;get() +<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$self-&gt;register('C')-&gt;get()<br> &nbsp;&nbsp;},<br> &nbsp;&nbsp;set =&gt; sub {<br> &nbsp;&nbsp;&nbsp;&nbsp;my $value = shift;<br> &nbsp;&nbsp;&nbsp;&nbsp;$self-&gt;register('B')-&gt;set($value &gt;&gt;8);<br> &nbsp;&nbsp;&nbsp;&nbsp;$self-&gt;register('C')-&gt;set($value &amp; 0xFF);<br> &nbsp;&nbsp;}<br> );<br> </code> </p><p>and then as far as implementing the actual Z80 instructions goes, I can just get() and set() sixteen bit registers with a single method call, instead of doing all the multiplication, shifting, bitmasking and so on every time. Note that I use a variable <code>$self</code> inside the two anonymous subroutines without declaring it with <code>my</code>. This isn't a bug. That is the <code>$self</code> in the code that creates the anonysubs. It has nothing to do with whatever <code>$self</code> might be inside a Register16 class's get() or set() method. </p><p>But there are actually several register-pairs, so I went one step further. Instead of repeating that chunk of code several times, once for each pair, I did this: </p><p> <code> $AF&nbsp;=&nbsp;_derive_register16($self,&nbsp;qw(A&nbsp;F));<br> $BC&nbsp;=&nbsp;_derive_register16($self,&nbsp;qw(B&nbsp;C));<br> $DE&nbsp;=&nbsp;_derive_register16($self,&nbsp;qw(D&nbsp;E));<br> <br><nobr> <wbr></nobr>...<br> <br> sub&nbsp;_derive_register16&nbsp;{<br> &nbsp;&nbsp;my($self,&nbsp;$high,&nbsp;$low)&nbsp;=&nbsp;@_;<br> &nbsp;&nbsp;return&nbsp;CPU::Emulator::Z80::Register16-&gt;new(<br> &nbsp;&nbsp;&nbsp;&nbsp;get&nbsp;=&gt;&nbsp;sub&nbsp;{<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;256&nbsp;*&nbsp;$self-&gt;register($high)-&gt;get()&nbsp;+<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$self-&gt;register($low)-&gt;get()<br> &nbsp;&nbsp;&nbsp;&nbsp;},<br> &nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;=&gt;&nbsp;sub&nbsp;{<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my&nbsp;$value&nbsp;=&nbsp;shift;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$self-&gt;register($high)-&gt;set($value&nbsp;&gt;&gt;8);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$self-&gt;register($low)-&gt;set($value&nbsp;&amp;&nbsp;0xFF);<br> &nbsp;&nbsp;&nbsp;&nbsp;},<br> &nbsp;&nbsp;);<br> }<br> </code> </p><p>In this case, I pass <code>$self</code> and the names of two 8 bit registers to the <code>_derive_register16</code> function. That function then creates and returns a Register16 now "closing over" <em>3</em> variables. </p><p>Closures rock. By combining objects and closures I have ended up writing a <em>lot</em> less code. And by reducing the amount of duplication in my code, when I inevitably find a bug, I'll have just one place to fix it, instead of having to remember all the hundred places where I twiddle register pairs. If you ever find yourself writing the same code over and over again just with minimally different data, this is a useful technique. </p><p>You can see what I'm up to on this project by looking at the <a href="http://drhyde.cvs.sourceforge.net/drhyde/perlmodules/CPU-Emulator-Z80/">CVS repository</a>.</p> drhyde 2008-02-23T15:16:35+00:00 journal What I want in 5.12 http://use.perl.org/~drhyde/journal/35417?from=rss <p>I want Lchown to go into the core. </p><p>Unfortunately, I can't justify it. Well, I can. It would help to get rid of one of the more commonly asked questions on the rsnapshot-discuss mailing list. But really, that's not reason enough to bloat the core even more.</p> drhyde 2008-01-18T11:34:54+00:00 journal