rhesa's Journal http://use.perl.org/~rhesa/journal/ rhesa'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:22:07+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 rhesa's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~rhesa/journal/ UNIVERSAL::isa oddity? http://use.perl.org/~rhesa/journal/35221?from=rss <p>What's going on here?</p><blockquote><div><p> <tt>&nbsp; &nbsp;my $foo = bless [], 'foo';<br> &nbsp; <br>&nbsp; &nbsp;# yep, it's a foo<br>&nbsp; &nbsp;$foo-&gt;isa('foo') and print "it's a foo";<br> &nbsp; <br>&nbsp; &nbsp;# what about the parent?<br>&nbsp; &nbsp;$foo-&gt;SUPER::isa('foo') and print "Mommy is a foo too";</tt></p></div> </blockquote><p>I suppose it doesn't make much sense to be asking isa() on the superclass, but huh?</p> rhesa 2007-12-28T05:11:49+00:00 journal Squeezebox, with Perl http://use.perl.org/~rhesa/journal/35065?from=rss <p>Today, my Squeezebox (from <a href="http://www.slimdevices.com/">http://www.slimdevices.com/</a>) arrived in the mail. Its streaming server is written in Perl<nobr> <wbr></nobr>:-)</p><p>I've only glanced at the code, but it looks very well layed out, and uses great modules like TT2 and DBIx::Class. And it's all GPL'ed too, nice!</p><p>If you're looking for a good quality, wireless media player, the Squeezebox should be on your list.</p> rhesa 2007-12-08T01:06:00+00:00 journal Two small gripes about MySQL http://use.perl.org/~rhesa/journal/32839?from=rss <ol><li>You can use an aliased column in the GROUP BY clause, but not in the WHERE clause:<blockquote><div><p> <tt>SELECT func(foo) as alias FROM baz GROUP BY alias</tt></p></div> </blockquote><p> works, but</p><blockquote><div><p> <tt>SELECT func(foo) as alias FROM baz WHERE alias='quux'&nbsp; (*)</tt></p></div> </blockquote><p> doesn't. You have to write</p><blockquote><div><p> <tt>SELECT func(foo) as alias FROM baz WHERE func(foo)='quux'</tt></p></div> </blockquote></li> <li>Modifying a column: which phrase will do what I want? <code>ALTER COLUMN</code>, <code>CHANGE COLUMN</code>, or <code>MODIFY COLUMN</code>? I can never remember and have to <a href="http://dev.mysql.com/doc/refman/5.0/en/alter-table.html">look them up</a>.</li></ol> rhesa 2007-03-30T02:01:15+00:00 journal New fbi packages fix denial of service http://use.perl.org/~rhesa/journal/29658?from=rss <p>Normally, security updates are just part of ordinary life. Today's <a href="http://www.debian.org/security/">Debian Security Announcement</a> brought a smile to my face though.</p><blockquote><div><p>[SECURITY] [DSA 1068-1] New fbi packages fix denial of service</p><p>[...]</p><p>We recommend that you upgrade your fbi package.</p></div></blockquote> rhesa 2006-05-20T20:09:17+00:00 journal "Mocking Everything" http://use.perl.org/~rhesa/journal/29535?from=rss <p>It's a saturday morning, and it's my first free weekend in months. I feel like unloading some static. Don't read this, it's silly! My bozo bit seems to be stuck today, so I need a coredump.</p><p>Perl gets a bad rap<br>First item is <a href="http://www.perlmonks.org/index.pl?node_id=547806">this post</a>: it tickles me, because i think it's weird to turn some cracker's actions into bad publicity for one of his tools.</p><p>"Gary told me over a couple of Heinekens [Heineken involved in NASA cracking attempt!!] that he used emacs to type his perl script." -- Anonymous bartender<br>Emacs is evil! Had he used vi, he wouldn't have been caught!</p><p>web frameworks</p><p>Jifty is doomed!<br>Paul Graham <a href="http://paulgraham.infogami.com/blog/morepatents">holds a patent</a> on using continuations to fake subroutines in web applications -- and he suspects they have been made obsolete by Ajax anyway.</p><p>Catalyst lost its Mojo<br>Inspired by the recent upheaval, I'm building a whole new framework from the ground up, and I'm calling it Devil::Fork. It'll take all the bad design decisions of all frameworks in existence, and extends them for all eternity. I'm already making a mockery of MVC with Devil::Fork::Trident.<br>The most important factor in the success of any framework is marketing, so I'm currently sketching Devil::Fork::Pitch. I wonder if <a href="http://en.wikipedia.org/wiki/The_Devil's_Advocate_(film)">Keanu and Al</a> are interested in a sequel...</p><p>When HTML just isn't rich enough<br>I have plans for a gooey toolkit for a richer experience, and this will be its entry in the module list: Devil::Fork::You -- GUi toolkit based on Curses.</p><p>The good guys are winning!<br>Apparently there aren't enough object factories yet. I was quite thrilled when the butchers came in to turn Perl objects inside out. But when a <a href="http://search.cpan.org/perldoc?Moose">moose</a> weazeled its way onto the CPAN, I got worried. And now I see <a href="http://search.cpan.org/perldoc?Class::Methodist">more religion</a> being considered for inclusion!</p><p>Listen, there are only four classes: Nobility, Bourgeoisie, Proletariat and Pariahs. It's worked forever. And they never mix. No need to go tampering with establishment!</p><p>Form validators<br>Another area with lots of false prophets. CGI, Data::Formvalidator, CGI::Untaint, HTML::Widget, and more recently, Class::CGI all claim to make web data access safe. Nonsense! I have the definitive one, and it's going to be released as CGIx::Class. I really hope I can make fun of Ovid, Tony Bowden, Matt Trout _and_ Sebastian Riedel all in one fell swoop!</p><p>Templating systems<br>Haha. That's too funny even for this clown. My work here is done.</p> rhesa 2006-05-06T10:58:31+00:00 journal Perl help for a Master Katrina db at The Katrina Portal http://use.perl.org/~rhesa/journal/26608?from=rss <p>I'm working with a group of people to build a central database for the survivors of Katrina and their relatives (up on <a href="http://www.thekatrinaportal.com/">http://www.thekatrinaportal.com/</a>).</p><p>We could use volunteers and other help with this effort, so <a href="mailto:rhesa@cpan.org">drop me a line</a> if you want to help out.<br>We're specifically looking for scraping experts, and help on the web interface/xml api to get the data back out to others.<br>What we have now is built with CGI::Application and Class:DBI (and HTML::Template::Plugin::Dot), so if you're familiar with those, all the better.</p><p>I'm pasting Britt Blasers request here:</p><p><strong>What we're doing</strong></p><p>Donovan Janus and Rhesa Rozendaal are building a Katrina Data Aggregator at The Katrina Portal, which should go live at by about noon EDT today. The Katrina Portal allows people to enter data like all the others, but its real purpose is for volunteers to copy text information from text lists and to enter it into a structured format.</p><p>Then the site exposes the data through XML-API to any agency that needs it. It can also create overviews of tabular and graphical views for use in decision support for relief management and for the Main Stream Media.</p><p>John Vincenzo has started to re-purpose an existing pattern recognition tool to spider the lists for importing text and starting the data normalization.</p><p>Or, roll your own.</p><p><strong>What we need</strong></p><p>We need one or more Perl coders to help finish John's GREP pattern matcher to spider the lists for importing text. It's based on a tool he built at UBS Warburg in 1996 for pattern recognition in huge ASCII files from the New York Stock Exchange. John is very busy, including the fact that his brother lost everything in Katrina, and is slightly injured.</p><p>The two tasks are to finish the tool and to configure data descriptions for each of the uniquely configured lists, which volunteers can do.</p><p>Can anyone help? Can you hook John up with someone who can?</p><p>That's probably enough for the three of you to totally get it. The rest of this message is background.</p><p>The original plea inspiring the Katrina Portal, from Brian Oberkirch to Doc Searls on Thursday, is attached below. FWIW, our two stateside programmers, Rhett Brown and John Vincenzo, have lost a total of four homes in their immediate families. Donovan Janus in Australia and Rhesa Rozendaal in Norway are working just as hard on the Katrina response.</p><p>Thanks in advance,</p><p>Britt Blaser</p><p>Begin forwarded message:</p><p>&gt; From: Doc Searls<br>&gt; Date: September 1, 2005 3:59:32 AM EDT<br>&gt; To: Britt Blaser<br>&gt; Subject: Fwd: Social Web Help for Slidell Hurricane Victims?<br>&gt;<br>&gt;<br>&gt; I think some of your friends might have ideas.<br>&gt;<br>&gt; ds<br>&gt;<br>&gt;&gt; To: Jason Fried , Dave Winer ,<br>&gt;&gt; , hugh macleod ,<br>&gt;&gt; Craig Newmark , Evan Williams ,<br>&gt;&gt; Dan Cederholm , Doc Searls ,<br>&gt;&gt; Cc: David Parmet<br>&gt;&gt; Subject: Social Web Help for Slidell Hurricane Victims?<br>&gt;&gt; From: Brian Oberkirch<br>&gt;&gt; Date: Thu, 1 Sep 2005 00:06:35 -0500<br>&gt;<br>&gt;&gt; Anyone have any ideas about how I can get this data out &amp; circulating for greater effect? Today, I posted a link to a CNN video. Jennifer Watson posted a comment that she had been looking for her father since Sunday, and through the video was able to find out that he was alive &amp; ok. I want more stories like this, but the requests are buried in comments. How can I amp up the social interaction? Any thinking greatly appreciated. Our little town is crushed. Help us, Obi-Wan. Thanks much. Peace &amp; light.<br>&gt;<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; http://www.lightbox5.com/movabletype/archives/2005/08/lazyweb_dont_fa.html<br>&gt;<br>&gt;&gt;<br>&gt;&gt; LazyWeb, Don't Fail Me Now<br>&gt;<br>&gt;&gt; Over at the Slidell Hurricane Damage blog, I have hundreds of people posting comments asking about loved ones, damage, etc. Many email me, and I post up their inquiries. I'm afraid the requests are hidden away in the comments. Anyone have a quickie Web 2.0 way I can extract and circulate this information to let the hive mind work its magick?<br>&gt;<br>&gt;&gt; Need the social Web bomb squad on this. People need help. I want to help them.<br>&gt;<br>&gt;&gt; Hey Tech Pros, you asked what you could do to help. Here's one thing you could help me with.<br>&gt;<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; Brian Oberkirch<br>&gt;<br>&gt;&gt;</p> rhesa 2005-09-05T23:51:21+00:00 journal Use Perl Journals RSS feed http://use.perl.org/~rhesa/journal/26496?from=rss <p>Anyone know if that feed has changed? Up until Aug 17th, I'd get the latest journal entries, including body. After that date, nothing.</p><p>How do I keep track of who's writing what now? I don't want to have to refresh the home page every hour.</p><p><i>update</i>: ok, the feed's still there, but why is the body gone? I want to see some content! Just the subjects is meaningless.</p> rhesa 2005-08-29T14:28:56+00:00 journal more progress on HTML::Template::Plugin::Dot http://use.perl.org/~rhesa/journal/26311?from=rss <p><a href="http://search.cpan.org/dist/HTML-Template-Pluggable/lib/HTML/Template/Plugin/Dot.pm">HTML::Template::Plugin::Dot</a> is nearing 1.0!</p><p>In the past few days, I've made numerous improvements and bugfixes. The most notable of those is loop support: anything returning an array (or reference to one) can be used in a tmpl_loop:</p><blockquote><div><p> <tt>use HTML::Template::Pluggable;<br>use HTML::Template::Plugin::Dot;<br>use My::Feed;&nbsp; # a Class::DBI object<br> &nbsp; <br>my $tmpl = q{<br>Feed: &lt;tmpl_var feed.name&gt; at &lt;tmpl_var feed.url&gt;<br>Items:&lt;tmpl_loop feed.items:item&gt;<br>&nbsp; &nbsp; "&lt;tmpl_var item.title&gt;" by &lt;tmpl_var item.author&gt; (&lt;tmpl_var item.postdate.dmy&gt;)<br>&lt;/tmpl_loop&gt;<br>};<br> &nbsp; <br>my $t = HTML::Template::Pluggable-&gt;new( scalarref =&gt; \$tmpl );<br> &nbsp; <br>my $feed = My::Feed-&gt;retrieve(1);<br>$t-&gt;param( feed =&gt; $feed );<br> &nbsp; <br>print $t-&gt;output;</tt></p></div> </blockquote><p>Notice how we only pass in the $feed object, and make use of its relationships to display its items. The ':item' suffix works similar to <code>foreach my $item( $feed-&gt;items )</code>. I even provide the equivalent of $_ as an implicit local variable, but I've chosen to name it "this", since that's what web designers would be more familiar with than a bare underscore<nobr> <wbr></nobr>;-)</p><p>The other big improvement is that HTML::Template::Pluggable and<nobr> <wbr></nobr>::Plugin::Dot now pass all of the original HTML::Template tests, which means it can be used as a drop-in replacement.</p><p>The last bit of big news is that CromeDome has released a plugin for CGI::Application that makes the drop-in even smoother! All you need to do is make a small change to your base class, adding CGI::Application::Plugin::HTDot to its @ISA. All your existing code will keep working as before, but the new dot power is available everywhere, ready for you to tap into.</p><p>I'm quite thrilled about my progress, and about CromeDome's plugin<nobr> <wbr></nobr>:-)</p><p>I'm now at a stage where I can go try out all this new power and flexibility. I'm going to see about benchmarking as well; maybe there are performance issues I do not know about yet. But at least it's stable, and that's the important part.</p> rhesa 2005-08-17T01:55:34+00:00 journal Progress on HTML::Template::Plugin::Dot http://use.perl.org/~rhesa/journal/26169?from=rss <p>As you may know, Mark Stosberg and I are working on additions to HTML::Template. Mark has created HTML::Template::Pluggable, which adds a callback system to HTML::Template, similar to the successful one in CGI::Application. This will make creating plugins for HTML::Template a lot simpler.</p><p>He also started on HTML::Template::Plugin::Dot, which hooks into param to provide the magic-dot notation you might know from the Template Toolkit. I am currently enhancing that to allow mixing hashes and objects and more.</p><p>Here's an example script I have just written:</p><blockquote><div><p> <tt>use HTML::Template::Pluggable;<br>use HTML::Template::Plugin::Dot;<br>use My::Feed;&nbsp; # a Class::DBI object<br> &nbsp; <br>my $t = HTML::Template::Pluggable-&gt;new( scalarref =&gt; \ q{<br>&nbsp; &nbsp; Feed: &lt;tmpl_var feed.name&gt; at &lt;tmpl_var feed.url&gt;<br>&nbsp; &nbsp; Items:&lt;tmpl_loop items&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; "&lt;tmpl_var item.title&gt;" by &lt;tmpl_var item.author&gt; (&lt;tmpl_var item.postdate.dmy&gt;)&lt;/tmpl_loop&gt;<br>&nbsp; &nbsp; });<br> &nbsp; <br>my $feed = My::Feed-&gt;retrieve(1);<br>$t-&gt;param( feed =&gt; $feed,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;items =&gt; [ map { {item =&gt; $_} } $feed-&gt;items ] );<br> &nbsp; <br>print $t-&gt;output;</tt></p></div> </blockquote><p>Sample output could look like this:</p><blockquote><div><p> <tt>&nbsp; &nbsp; Feed: Asynchrss at http://www.asynchrss.com<br>&nbsp; &nbsp; Items:<br>&nbsp; &nbsp; &nbsp; &nbsp; "News" by rhesa (21-10-2004)<br>&nbsp; &nbsp; &nbsp; &nbsp; "More" by zsane (04-07-2005)</tt></p></div> </blockquote><p>Hey, that's neat! Now, what if your web designer wants american style dates?</p><blockquote><div><p> <tt> &lt;tmpl_var item.postdate.mdy('/')&gt; </tt></p></div> </blockquote><p>Output:</p><blockquote><div><p> <tt>&nbsp; &nbsp; Feed: Asynchrss at http://www.asynchrss.com<br>&nbsp; &nbsp; Items:<br>&nbsp; &nbsp; &nbsp; &nbsp; "News" by rhesa (10/21/2004)<br>&nbsp; &nbsp; &nbsp; &nbsp; "More" by zsane (07/04/2005)</tt></p></div> </blockquote><p>And no changes to your code whatsoever! Now all you need to tell your designer is what objects he can expect, and what methods he can call. But you have that documented already, right?<nobr> <wbr></nobr>;)</p><p>Obviously we're not intending to redo the Template Toolkit, but I think this feature is a great addition to HTML::Template, and a much-requested one at that. It's still fully backward-compatible too, so none of your existing code will break.</p><p>It should be on CPAN sometime soon, but you can get it from Marks public darcs repo now. I could definitely use some eyeballs on my code, as well as more tests. So get in touch if you're interested!</p> rhesa 2005-08-08T01:28:46+00:00 journal hooked on markjugg http://use.perl.org/~rhesa/journal/26104?from=rss <p>So, first he gives us callbacks in CGI::Application. Soon we'll have them in HTML::Template too. And if that's not enough, he's enabling magic-dot notation as well!</p><p>Three cheers for Mark! Yay Mark, way to go<nobr> <wbr></nobr>:)))))</p><p>Ok, so I thought it would be cool to be able to pass arguments to method calls as well, so you can do, say,</p><blockquote><div><p> <tt> &lt;tmpl_var datetime.strftime(%c)&gt; </tt></p></div> </blockquote><p>And mix method calls and hash-key referencing:</p><blockquote><div><p> <tt> &lt;tmpl_var mock.method.some_key&gt; </tt></p></div> </blockquote><p>That would help, for instance, when that method returns a hashref, or when a hash contains some objects.</p><p>I've got something thrown together at the moment, but it's still crude. These two samples work though<nobr> <wbr></nobr>:)</p> rhesa 2005-08-04T22:15:40+00:00 journal cheap shot? http://use.perl.org/~rhesa/journal/26042?from=rss <p><a href="http://search.cpan.org/src/ITUB/Acme-Class-DBI-NoThreats-0.96/README">http://search.cpan.org/src/ITUB/Acme-Class-DBI-NoThreats-0.96/README</a></p> rhesa 2005-08-02T20:34:14+00:00 journal HTTP spec problem for lwp scripts http://use.perl.org/~rhesa/journal/25952?from=rss <p>I have a script that fetches an rss feed from blogs.com. A couple of days ago it broke. Reason: server is sending gzip encoded content. I felt that was mightly impolite, but it turns out the HTTP spec is on their side:</p><blockquote><div><p>If no Accept-Encoding field is present in a request, the server MAY assume that the client will accept any content coding. In this case, if "identity" is one of the available content-codings, then the server SHOULD use the "identity" content-coding, unless it has additional information that a different content-coding is meaningful to the client.</p></div></blockquote><p> <cite> <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html</a> </cite>, Section 14.3</p><p>Since LWP by default does not send any Accept-Encoding request header, this means sending gzip'ed content is perfectly acceptable. But LWP doesn't handle that, and simply gives us the undecoded content.</p><p>It would seem - to me at least - that the quickest fix to LWP would be to include a 'Accept-Encoding: identity' in the request headers by default:</p><blockquote><div><p>If an Accept-Encoding field is present in a request, and if the server cannot send a response which is acceptable according to the Accept-Encoding header, then the server SHOULD send an error response with the 406 (Not Acceptable) status code.</p></div></blockquote><p> <cite>ibid.</cite><br>(Although I'd have to say that a 406 response would be pretty useless.)</p><p>Unfortunately, with this particular server, that does not do the trick:<br><code><br>[user@host]% GET -H 'Accept-Encoding: identity' -U -e -d http://$blog_id.blogs.com/index.rdf<br>GET http://$blog_id.blogs.com/index.rdf<br>Accept-Encoding: identity<br>User-Agent: lwp-request/2.06</code></p><p><code>Connection: close<br>Date: Thu, 28 Jul 2005 18:46:27 GMT<br>Accept-Ranges: bytes<br>Age: 63019<br>ETag: "1cc057-75c4-427c6400"<br>Server: Apache<br>Content-Encoding: gzip<br>Content-Length: 8956<br>Content-Type: application/rdf+xml<br>Last-Modified: Wed, 20 Jul 2005 14:00:48 GMT<br>Client-Date: Fri, 29 Jul 2005 12:16:46 GMT<br>Client-Peer: 216.129.107.21:80<br>Client-Response-Num: 1<br>X-Cache: HIT from www.sixapart.com<br></code></p><p>If you don't have a plain text version, then where's the 406, guys?</p><p>Which means that it would be nice if LWP could decode the content when it sees the Content-Encoding: gzip header, and if a suitable Compress module is available.</p><p>I'd like to point out that - in my opinion - the content-encoding is a transport detail, and should not have to matter to the user. In other words, I would appreciate LWP to handle that for me transparently.</p><p>Maybe I should send in a patch....</p> rhesa 2005-07-29T12:38:36+00:00 journal "use base" revelation http://use.perl.org/~rhesa/journal/25287?from=rss <p>I always lived with the idea that "use base" was introduced with perl 5.6.0, and that we had to write</p><blockquote><div><p> <tt>&nbsp; require BaseClass;&nbsp; &nbsp; # Thanks, merlyn<nobr> <wbr></nobr>:)<br>&nbsp; use vars qw/@ISA/;<br>&nbsp; @ISA = qw/BaseClass/;</tt></p></div> </blockquote><p>to be compatible with older perls.</p><p>Today I learned (<a href="http://search.cpan.org/dist/base/lib/base.pm">http://search.cpan.org/dist/base/lib/base.pm</a>) that "use base" was introduced with Perl 5.004_04!</p><p>Is this an odd case of cargo cult? Does it mean we can stop doing the "use vars '@ISA'" thing now?</p><p>Who wants their OO code to be compatible with perls older than 5.005?</p><p>And where did I get this notion from that it only became available in 5.6?</p><p>Sometimes it seems that experience just means you're set in your ways....</p> rhesa 2005-06-20T11:33:18+00:00 journal YAY! Debian GNU/Linux 3.1 released http://use.perl.org/~rhesa/journal/25063?from=rss <p><a href="http://www.debian.org/News/2005/20050606">Sarge is now officially stable</a>. I'm pleased with that<nobr> <wbr></nobr>:-)</p> rhesa 2005-06-06T22:53:49+00:00 journal Slartifartbast was a genius! http://use.perl.org/~rhesa/journal/24255?from=rss Credit where credit's due: <a href="http://zsanett.exposuremanager.com/p/winter_norway/ytre_nordfjord18">the Norwegian fjords</a> are truly magnificent. Slartifartbast really deserved his award. <p> Norway may not be <a href="http://www.nytimes.com/2005/04/17/weekinreview/17bawer.html?pagewanted=1&amp;ei=5090&amp;en=44ea05b3e068feb5&amp;ex=1271390400&amp;partner=rssuserland&amp;emc=rss">the richest country in the world</a>, but it sure is <a href="http://zsanett.exposuremanager.com/p/panorama/vagsoypanorama125">astonishingly beautiful</a>. </p><p> With a <a href="http://zsanett.exposuremanager.com/p/maaloey_mountains/maaloeymountains7">view like this</a>, right from our balcony, I consider us pretty well off. And I definitely don't need an expensive car when <a href="http://zsanett.exposuremanager.com/p/winter_norway/rhesa_hesten18">I can walk in the snow</a>.</p> rhesa 2005-04-18T13:47:20+00:00 journal POE woe http://use.perl.org/~rhesa/journal/24253?from=rss <p>This is more likely an issue with Parallel::UserAgent, but I couldn't resist that title<nobr> <wbr></nobr>;)</p><p>I'm using POE::Component::Client::UserAgent to fetch multiple RSS feeds. Every once in a while, one of the servers is down, so that request times out with a 500 error. The problem I have is that all requests that are queued behind this one also time out with a 408 error!</p><p>I don't feel like starting a bug hunt on monday morning; and this one looks like it's going to be hard<nobr> <wbr></nobr>:(</p> rhesa 2005-04-18T13:06:08+00:00 journal "Look ma, no hands" http://use.perl.org/~rhesa/journal/24238?from=rss I got <a href="http://www.rhesa.com/rhesacat8.jpg">a tool</a> to help me with the tedious parts of programming. It's called a CAT (Cat Aided Typing) device. <br> It <a href="http://www.rhesa.com/rhesacat9.jpg">runs out of power</a> quickly though. Recharging can take up to 10 hours! rhesa 2005-04-17T12:24:17+00:00 journal Yay! DBIx::Counter initial release. I'm officially on CPAN. http://use.perl.org/~rhesa/journal/24211?from=rss <p>Had some good feedback on module-authors and the code-review-ladder lists (thanks, Bart, Mark, Stephen and Smylers<nobr> <wbr></nobr>:^), and decided to take the plunge.</p><p><a href="http://search.cpan.org/~rhesa/DBIx-Counter-0.01/lib/DBIx/Counter.pm">http://search.cpan.org/~rhesa/DBIx-Counter-0.01/lib/DBIx/Counter.pm</a></p><p>Now for some advertising... Where do I go to announce my precious code to the world?<nobr> <wbr></nobr>:-)</p> rhesa 2005-04-15T22:09:59+00:00 journal RFC: DBIx::Counter - persistent counter class http://use.perl.org/~rhesa/journal/24172?from=rss <p>Hi,</p><p>I've been a CPAN consumer for so long, I thought it's about time to start contributing.<br>I wrote a little module that does exactly the same as File::CounterFile, but with a database as storage engine.<br>It came into this world after a thread on www.experts-exchange.com; so there's at least one interested user for it.</p><p>Granted, it's nothing earth-shattering, but it's simple and generic enough to be useful outside my usual work, and it presents me with a manageable package to start my CPAN career.<br>Before I go all the way by applying for a PAUSE account and uploading it, I would like to put it to public scrutiny first. I'd like to know I'm doing things properly from the start.</p><p>Here's my list of questions:<br>- what about the module name? is it good?<br>- code review would be nice<br>- documentation: clear enough?<br>- tests: for a module this simple?<br>- exception handling: should I do this myself, or let DBI throw them?</p><p>The archive is here: http://www.rhesa.com/DBIx-Counter-0.01.tar.gz</p><p>Thanks for your attention!</p><p>Rhesa</p><p>Here's the pod:</p><p>NAME<br> &nbsp; &nbsp; &nbsp; &nbsp; DBIx::Counter - Manipulate named counters stored in a database</p><p>SYNOPSIS<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; use DBIx::Counter;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $c = new DBIx::Counter('my counter',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dsn =&gt; 'dbi:mysql:mydb',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; login =&gt; 'username',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; password =&gt; 'secret'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print $c-&gt;value;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;inc;</p><p>DESCRIPTION<br> &nbsp; &nbsp; &nbsp; &nbsp; This module creates and maintains named counters in a database. It has a<br> &nbsp; &nbsp; &nbsp; &nbsp; simple interface, with methods to increment and decrement the counter by<br> &nbsp; &nbsp; &nbsp; &nbsp; one, and a method for retrieving the value. It supports operator<br> &nbsp; &nbsp; &nbsp; &nbsp; overloading for increment (++), decrement (--) and stringification ("").<br> &nbsp; &nbsp; &nbsp; &nbsp; It should perform well in persistent environments, since it uses the<br> &nbsp; &nbsp; &nbsp; &nbsp; connect_cached and prepare_cached methods of DBI. The biggest advantage<br> &nbsp; &nbsp; &nbsp; &nbsp; over its main inspiration - File::CounterFile - is that it allows<br> &nbsp; &nbsp; &nbsp; &nbsp; distributed, concurrent access to the counters and isn't tied to a<br> &nbsp; &nbsp; &nbsp; &nbsp; single file system.</p><p> &nbsp; &nbsp; &nbsp; &nbsp; Connection settings can be set in the constructor, or by using the<br> &nbsp; &nbsp; &nbsp; &nbsp; package variables $DSN, $LOGIN and $PASSWORD and $TABLENAME. The table<br> &nbsp; &nbsp; &nbsp; &nbsp; name is configurable, but the column names are currently hard-coded to<br> &nbsp; &nbsp; &nbsp; &nbsp; counter_id and value. The following SQL statement can be used to create<br> &nbsp; &nbsp; &nbsp; &nbsp; the table:</p><p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CREATE TABLE counters (<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter_id varchar(64) primary key,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value int not null default 0<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );</p><p> &nbsp; &nbsp; &nbsp; &nbsp; This module attempts to mimick the File::CounterFile interface, except<br> &nbsp; &nbsp; &nbsp; &nbsp; currently it only supports integer counters. The locking functions in<br> &nbsp; &nbsp; &nbsp; &nbsp; File::CounterFile are present for compatibility only: they always return<br> &nbsp; &nbsp; &nbsp; &nbsp; 0.</p><p>METHODS<br> &nbsp; &nbsp; &nbsp; &nbsp; new Creates a new counter instance. First parameter is the required<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter name. Second, optional, argument is an initial value for the<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter on its very first use. It also accepts named parameters for<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the dbi connection string, dbi login and dbi password, and the table<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name:</p><p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dsn - overrides $DBIx::Counter::DSN<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; login - overrides $DBIx::Counter::LOGIN<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; password - overrides $DBIx::Counter::PASSWORD<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tablename - overrides $DBIx::Counter::TABLENAME</p><p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Examples:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $c = new DBIx::Counter('my counter');<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $c = new DBIx::Counter('my counter',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dsn =&gt; 'dbi:mysql:mydb',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; login =&gt; 'username',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; password =&gt; 'secret'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $c = new DBIx::Counter('my counter',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 42,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dsn =&gt; 'dbi:mysql:mydb',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tablename =&gt; 'gauges'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );</p><p> &nbsp; &nbsp; &nbsp; &nbsp; inc increases the counter by one.</p><p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;inc;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # or using overload:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $c++;</p><p> &nbsp; &nbsp; &nbsp; &nbsp; dec decreases the counter by one.</p><p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;dec;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # or using overload:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $c--;</p><p> &nbsp; &nbsp; &nbsp; &nbsp; value<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; returns the current value of the counter.</p><p> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print $c-&gt;value;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # or using overload:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print $c;</p><p>SEE ALSO<br> &nbsp; &nbsp; &nbsp; &nbsp; File::CounterFile</p><p>AUTHOR<br> &nbsp; &nbsp; &nbsp; &nbsp; Rhesa Rozendaal, .</p><p>COPYRIGHT AND LICENSE<br> &nbsp; &nbsp; &nbsp; &nbsp; Copyright (C) 2005 by Rhesa Rozendaal</p><p> &nbsp; &nbsp; &nbsp; &nbsp; This library is free software; you can redistribute it and/or modify it<br> &nbsp; &nbsp; &nbsp; &nbsp; under the same terms as Perl itself, either Perl version 5.8.2 or, at<br> &nbsp; &nbsp; &nbsp; &nbsp; your option, any later version of Perl 5 you may have available.</p> rhesa 2005-04-13T23:26:50+00:00 journal