<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>Yet another perl hacker.</description><title>bluefeet</title><generator>Tumblr (3.0; @arandeltac)</generator><link>http://blog.bluefeet.net/</link><item><title>Fixing Pixelated Images on the iPhone</title><description>&lt;p&gt;When an iPhone with a retina display (iPhone 4+) displays an image on a web page that image’s size is doubled, so each pixel in the image actually takes up 4 pixels and looks pixelated.  This looks unprofessional and tacky.  Here’s an example of a 245x80 image:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://media.tumblr.com/tumblr_lykvmjAi0S1r6sju9.png" width="245" height="80"/&gt;&lt;/p&gt;

&lt;p&gt;You’ll have to load this page on an iPhone to see the problem in the above image.  The pixels in the image have jagged edges and the photo overall looks blurry.&lt;/p&gt;

&lt;p&gt;To get around this all you need to do is double your image size and explicitly set the image size in the &lt;code&gt;&lt;img ...&gt;&lt;/code&gt; tag to its original non-doubled size.  So, in our example the image is now 490x160, but we set the img tag as &lt;code&gt;&lt;img src="..." width="245" height="80"&gt;&lt;/code&gt;.  Here’s what it now looks like with the image stored at double resolution:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://media.tumblr.com/tumblr_lykvk1ffsA1r6sju9.png" width="245" height="80"/&gt;&lt;/p&gt;

&lt;p&gt;Now it looks crisp on the iPhone.&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16716377857</link><guid>http://blog.bluefeet.net/post/16716377857</guid><pubDate>Sun, 29 Jan 2012 13:01:00 -0800</pubDate><category>iPhone</category><category>Responsive Design</category><category>Images</category></item><item><title>Adding Responsive Design to Tumblr Themes</title><description>&lt;p&gt;If you’re using a single-column fluid layout theme in Tumblr then adding &lt;a href="http://en.wikipedia.org/wiki/Responsive_design"&gt;responsive design&lt;/a&gt; is dead-easy.  If you’re using a more complex theme, that is not fluid width and single-column, then you’ll have to put a lot more work in, but it is still well worth the effort.&lt;/p&gt;

&lt;p&gt;By default Tumblr overrides your theme with a mobile-friendly theme when your blog is accessed by a phone.  Here’s what my site looks like when Tumblr does this:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://media.tumblr.com/tumblr_lykuqgO2lu1r6sju9.png" width="320" height="480"/&gt;&lt;/p&gt;

&lt;p&gt;The override theme is incredibly basic and provides no extra functionality.  You loose your custom design that sets you apart, you loose Disqus comments, etc.&lt;/p&gt;

&lt;p&gt;The first step then is to disable Tumblr’s override mobile theme.  To do this, go in to the “Customize appearance” tool for your theme.  Once open, scroll down in the left-hand pane and open the “Advanced” section.  Under here there is a checkbox titled “Use optimized mobile layout”.  Uncheck this and click save at the top.  Now your theme will always be used.  Load up your site on your phone and have a look.  Here’s mine at this step:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://media.tumblr.com/tumblr_lykupyRuVW1r6sju9.png" width="320" height="480"/&gt;&lt;/p&gt;

&lt;p&gt;At this point this appears to be a step backwards - you’ve now made your site less usable.  In order for people to use your site now they have to zoom in and scroll left to right for each line they want to read.  If we left our site in this state it would be a miserable fail.  You can fix this by adding this line just before the &lt;code&gt;&lt;head&gt;&lt;/code&gt; tag in your theme’s HTML:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&lt;meta name="viewport"
    content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This “viewport” meta tag is telling the browser to not zoom out.  By default mobile browsers zoom out enough so that the site can have a display width comparable to a desktop.  For fixed-width sites there is no better solution, but for fluid width sites (or sites that only have a max-width, but not a min-width) disabling this auto-zoom provides a much better experience.&lt;/p&gt;

&lt;p&gt;So, with this meta tag added, the site now looks like this:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://media.tumblr.com/tumblr_lykuq7w3zz1r6sju9.png" width="320" height="480"/&gt;&lt;/p&gt;

&lt;p&gt;Now the site looks very close to Tumblr’s mobile override theme, but with all your customizations and custom design enabled.  Not bad!  There are still some issues, such as the body padding being too thick at this resolution.  But, overral this is a great step forward.&lt;/p&gt;

&lt;p&gt;Now we can make a few more adjustments by using CSS3 media queries.  Media queries allow us to craft CSS that is applied only in certain situations.  In this case we want the padding around the body to be reduced if the width of the site is below a certain level.  Adding this line to the CSS does just that:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;@media screen and (max-width: 480px) {
    body { padding: 5px; }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, when accessed with a browser that reports a width of 480px or less (which in my testing is iPhone in both portrait and landscape mode) then the site looks like this:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://media.tumblr.com/tumblr_lykuvp0jOi1r6sju9.png" width="320" height="480"/&gt;&lt;/p&gt;

&lt;p&gt;Much better!  Now when the site is accessed by a phone, the padding is reduced from 30px to 5px and we take better advantage of our screen real-estate.&lt;/p&gt;

&lt;p&gt;Now you should have the tools to take your own Tumblr blog to the next level and make it friendlier for your visitors.&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16711262728</link><guid>http://blog.bluefeet.net/post/16711262728</guid><pubDate>Sun, 29 Jan 2012 11:39:00 -0800</pubDate><category>Tumblr</category><category>Responsive Design</category><category>HTML</category></item><item><title>Adding Syntax Highlighting to Tumblr Posts</title><description>&lt;p&gt;I’ve just moved my blog to &lt;a href="http://www.tumblr.com"&gt;Tumblr&lt;/a&gt;.  One thing that most my posts have are code examples.  Here’s how I added this to my Tumblr blog.  Go in to the customization section of your blog where you can configure the theme.  Once there, click the “Edit HTML” button and add this somewhere before the ending &lt;code&gt;&lt;/head&gt;&lt;/code&gt; tag:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&lt;link rel="stylesheet" href="http://yandex.st/highlightjs/6.1/styles/solarized_light.min.css"&gt;
&lt;script src="http://yandex.st/highlightjs/6.1/highlight.min.js"&gt;&lt;/script&gt;
&lt;script&gt;hljs.initHighlightingOnLoad();&lt;/script&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Adjust “solarized_light.min.css” to point to whatever &lt;a href="http://softwaremaniacs.org/soft/highlight/en/"&gt;highlight.js&lt;/a&gt; theme you’d like to use.  The themes can be viewed on the &lt;a href="http://softwaremaniacs.org/media/soft/highlight/test.html"&gt;highlight.js test page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The only problem I’ve run in to is with tumblr’s infinite scrolling feature.  Since highlight.js is applying syntax highlighting when the page first loads then any code blocks that are loaded as you scroll will not get highlighted.  I’m sure there is a way around this, but for now I just disabled this feature in my blog’s preferences.&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16530609774</link><guid>http://blog.bluefeet.net/post/16530609774</guid><pubDate>Thu, 26 Jan 2012 10:56:00 -0800</pubDate><category>highlight.js</category><category>tumblr</category></item><item><title>Check out SQL::Abstract::Query</title><description>&lt;p&gt;During the last few months I’ve been working on the CPAN distribution &lt;a href="https://metacpan.org/module/SQL::Abstract::Query"&gt;SQL::Abstract::Query&lt;/a&gt;.  The drive for doing this is that &lt;a href="https://metacpan.org/module/DBIx::ResultSet"&gt;DBIx::ResultSet&lt;/a&gt; (another module of mine) currently has lack-luster support for auto-incrementing IDs, has a custom and inflexible solution for GROUP BY, and has no support for JOINs.&lt;/p&gt;

&lt;p&gt;To solve the first problem, with lack of good auto-incrementing ID support I wanted to make a generic module that would allow anyone to retrieve these IDs and could be used independently from DBIx::ResultSet.  So, I set out to build DBIx::AutoID.  I quickly found that there is a huge myriad of complexities to do this right for all the different databases out there.  In the end I came to the conclusion that I need some way for an INSERT to be represented as an object so that DBIx::AutoID can modify it, if it needs to, before it is executed so that the ID may be returned.&lt;/p&gt;

&lt;p&gt;The second two issues, bad support for GROUP BY and none for JOINS, really just required extending SQL::Abstract and overriding its behavior.&lt;/p&gt;

&lt;p&gt;So, take a look at SQL::Abstract::Query on CPAN and let me know what you think.  I’d really like to get some feedback.  There is a large list of &lt;a href="https://metacpan.org/module/SQL::Abstract::Query#TODO"&gt;TODOs&lt;/a&gt;, but I’m confident that the interface as it is now won’t change much, just the internal guts need some work here and there.&lt;/p&gt;

&lt;p&gt;Expect DBIx::AutoID (with inspiration from DBIx::Class) to be on CPAN in a few weeks as well.  Then, I’ll get around to updating DBIx::ResultSet with all these new and more powerful features.&lt;/p&gt;

&lt;p&gt;PS: The current development work is being done on the &lt;a href="https://github.com/bluefeet/SQL-Abstract-Query"&gt;SQL-Abstract-Query github repository&lt;/a&gt;.&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16523338672</link><guid>http://blog.bluefeet.net/post/16523338672</guid><pubDate>Mon, 19 Sep 2011 19:47:00 -0700</pubDate><category>CPAN</category><category>Perl</category><category>SQL::Abstract</category><category>SQL</category><category>SQL::Abstract::Query</category></item><item><title>Using DBI Effectively: bind_columns()</title><description>&lt;p&gt;One of the most under-utilized features of DBI is is the bind_columns() method.  The majority (as in everyone) that I show bind_columns() to have never seen it before or used it.  Here’s what it looks like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;my $sth = $dbh-&gt;prepare('SELECT name, email FROM users');
$sth-&gt;execute();
$sth-&gt;bind_columns( \my( $name, $email ) );

while ($sth-&gt;fetch()) {
    print "$name: $email\n";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;bind_columns() takes a list of scalar references as its arguments.  The form you see above with \my(…) is just a little known Perl-ism shortcut for:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;my ($name, $email);
$sth-&gt;bind_columns( \$name, \$email );
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There are two important reasons why bind_columns() is so awesome:&lt;/p&gt;

&lt;p&gt;First, it greatly reduces the complexity of the code within the while() loop since you do not have to lookup in to an array ($sth-&gt;fetchrow_array()), de-reference an array ($sth-&gt;fetchrow_array()), or de-reference a hash-ref ($sth-&gt;fetchrow_hashref()).  Instead the values themselves are available via appropriately named scalars.&lt;/p&gt;

&lt;p&gt;Secondly, when using bind_columns() DBI is re-using the same scalars every time a fetch() is done which is much faster than creating an array or hash every fetch and typically causes the values to be copied one less time than normal.  Benchmark it yourself - bind_columns() can make a huge difference when processing large sets of data.&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16523564065</link><guid>http://blog.bluefeet.net/post/16523564065</guid><pubDate>Tue, 16 Aug 2011 22:13:00 -0700</pubDate><category>Perl</category><category>DBI</category></item><item><title>Chained Git Hooks</title><description>&lt;p&gt;So I’ve be wrestling with getting chained git hooks working.  I’m surprised that Git doesn’t support this out-of-the-box as it seems very short-sighted.  Here’s a Perl script I implemented to get this working:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/usr/bin/env perl
use strict;
use warnings;

use autodie;
use File::Temp qw( tempfile );
use IPC::Cmd qw( run );

if (@ARGV and $ARGV[0] eq 'wrapper') {
    shift( @ARGV );

    my $hook_filename = shift( @ARGV );
    my $temp_filename = shift( @ARGV );

    open( STDIN, '&lt;', $temp_filename );

    exec($hook_filename, @ARGV);
}

my $hook_type = $0;
$hook_type =~ s{^.+/}{};

my $git_dir = $ENV{GIT_DIR} || `git rev-parse --git-dir`;
chomp( $git_dir );
my $hook_dir = $git_dir . "/hooks";

opendir( my $dh, $hook_dir );
my @hooks = sort grep { /^${hook_type}_/ } readdir( $dh );
closedir( $dh );

my ($temp_fh, $temp_filename) = tempfile(UNLINK =&gt; 1);
while (my $line = &lt;STDIN&gt;) {
    print $temp_fh $line;
}
close( $temp_fh );

foreach my $hook (@hooks) {
    my ($success, $error) = run( command =&gt; [
        $0, 'wrapper',
        "$hook_dir/$hook", $temp_filename,
        @ARGV,
    ]);
    print join('', @$full_buf);

    if (!$success) {
        die "Error running hook: " . $hook . ": $error\n";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, what you do is put this somewhere you can get at (perhaps just drop it in your hooks directory with the name “chained_hook”), chmod 755 it, and then symlink all your hooks to it, for example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ln -s chained_hook applypatch-msg
ln -s chained_hook commit-msg
ln -s chained_hook post-commit
ln -s chained_hook post-receive
ln -s chained_hook post-update
ln -s chained_hook pre-applypatch
ln -s chained_hook pre-commit
ln -s chained_hook pre-rebase
ln -s chained_hook prepare-commit-msg
ln -s chained_hook update
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Each of these chained hooks will now look for sub-hooks with the name “hookname_subhookname”.  So, you could add a “post-receive_email” and “post-receive_foo” hooks and both will be called, in sorted order, by the post-receive hook.&lt;/p&gt;

&lt;p&gt;So, I’m wondering - do people think this is a good solution?  Are there better solutions?  Is there a simpler way to write this script?&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16523765444</link><guid>http://blog.bluefeet.net/post/16523765444</guid><pubDate>Tue, 02 Aug 2011 08:50:00 -0700</pubDate><category>Git</category><category>Perl</category><category>Hooks</category></item><item><title>Adding Files to Subversion With @ in Their Name</title><description>&lt;p&gt;I just ran in to this today.  If you try to do this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;svn add this\@that
svn: warning: 'this' not found
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In order to ‘svn add’ a file with a ‘@’ character in it you must end the add command with an ‘@’ character, as in:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;svn add this\@that\@
A          this@that
&lt;/code&gt;&lt;/pre&gt;</description><link>http://blog.bluefeet.net/post/16523983333</link><guid>http://blog.bluefeet.net/post/16523983333</guid><pubDate>Thu, 21 Jul 2011 08:26:00 -0700</pubDate><category>Subversion</category><category>Ampersat</category></item><item><title>Presentation: Moose Best Practices</title><description>&lt;p&gt;I wrote this for the &lt;a href="http://thousand-oaks-perl.org"&gt;TO.pm&lt;/a&gt; meeting on August 11th, 2010:&lt;/p&gt;

&lt;p&gt;&lt;iframe src="http://www.slideshare.net/slideshow/embed_code/4965855" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16524039401</link><guid>http://blog.bluefeet.net/post/16524039401</guid><pubDate>Fri, 13 Aug 2010 14:57:00 -0700</pubDate><category>Moose</category><category>Best Practices</category><category>Perl</category><category>CPAN</category><category>OO</category></item><item><title>Presentation: Tools of the CPAN Ninja</title><description>&lt;p&gt;I wrote this for the &lt;a href="http://thousand-oaks-perl.org"&gt;TO.pm&lt;/a&gt; meeting on June 10th, 2010:&lt;/p&gt;

&lt;p&gt;&lt;iframe src="http://www.slideshare.net/slideshow/embed_code/4465387" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16524078577</link><guid>http://blog.bluefeet.net/post/16524078577</guid><pubDate>Thu, 10 Jun 2010 08:22:00 -0700</pubDate><category>Perl</category><category>CPAN</category><category>Ninja</category></item><item><title>BLOBs, Synonyms, and DBD::Oracle</title><description>&lt;p&gt;INSERTing, UPDATEing, and SELECTing LOBs (CLOB/BLOB) in Oracle using Perl can be a PITA.  Case in point: 2 years ago a fellow coworker ended up writing some extremely complex code using ora_lob_write(), etc, when all he really needed to do was use bind_param() and declare that the blob column is a blob so that DBD::Oracle would know to treat is specially.  At the time I believe he did try something like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;my $sth = $dbh-&gt;prepare(q[
    INSERT INTO some_table (color, blob_data)
    VALUES (?, ?)
]);
$sth-&gt;bind_param( 1, 'red' );
$sth-&gt;bind_param( 2, $data_for_blob, {ora_type =&gt; ORA_BLOB } );
$sth-&gt;execute();
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But then an error like “DBD::Oracle::st execute failed: ORA-04043: object some_table does not exist (DBD SUCCESS: OCIDescribeAny(view)/LOB refetch)” was raised.  Which made no sense since some_table is very much an object and any number of SQL operations work on it… when BLOBs are not involved.  In the end he ended up having to write code that was triple the size to get around this issue.&lt;/p&gt;

&lt;p&gt;So, 2 years later and a little hair pulling, I come to figure out by luck that the problem is that the underlying DBD::Oracle code, that makes dealing with BLOBs simple, fails when you are using a synonym in your insert.  All we had to do is fully spell out the table name, and it works!&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;my $sth = $dbh-&gt;prepare(q[
    INSERT INTO some_schema.some_table (color, blob_data)
    VALUES (?, ?)
]);
$sth-&gt;bind_param( 1, 'red' );
$sth-&gt;bind_param( 2, $data_for_blob, {ora_type =&gt; ORA_BLOB } );
$sth-&gt;execute();
&lt;/code&gt;&lt;/pre&gt;</description><link>http://blog.bluefeet.net/post/16524137739</link><guid>http://blog.bluefeet.net/post/16524137739</guid><pubDate>Thu, 03 Jun 2010 15:29:00 -0700</pubDate><category>Perl</category><category>DBI</category><category>Oracle</category><category>DBD::Oracle</category><category>Blob</category><category>Synonym</category></item><item><title>Generating Constants in Perl</title><description>&lt;p&gt;The other day @ $work I was throwing together a module that creates constants based on a fairly static table in the database.  Of course I didn’t want to hard code the contants, I wanted them to be magically created by what was in the database.  For the sake of this example I had a table called “toy_categories” where each record has a unique ID (toy_category_id) and a name that can only be letters and underscores.  The data would look something like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ID  NAME
--  --------------
12  dolls
 7  action_figures
92  education
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And the resulting constants would look something like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;TOY_CATEGORY_DOLLS = 12
TOY_CATEGORY_ACTION_FIGURES = 7
TOY_CATEGORY_EDUCATION = 92
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you read the core perl documents you might be lead to think that the &lt;a href="http://perldoc.perl.org/constant.html"&gt;constant&lt;/a&gt; pragma is the way to go.  This is not the case - just because a particular library is distributed with Perl does not mean its a good tool, instead it usually means that the library cannot be removed or substantially modified for backwards-compatibility reasons.  In my experience most core libraries are to be avoided - there are much better solutions on CPAN.&lt;/p&gt;

&lt;p&gt;So, the CPAN solution to constants is &lt;a href="http://search.cpan.org/perldoc?Readonly"&gt;Readonly&lt;/a&gt;.  This module hooks in to Perl’s ability to mark a variable as read-only, much like how variables can be flagged as tainted or scalars as UTF.  Make sure you grab &lt;a href="http://search.cpan.org/perldoc?Readonly::XS"&gt;Readonly::XS&lt;/a&gt; as well to get the full benefit of read-only variables without the performance hit.&lt;/p&gt;

&lt;p&gt;So, if you were to create a module for these constants you might do something like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;package MyApp::Constants::ToyCategories;
use strict;
use warnings;

use Readonly;
use Exporter qw( import );

our @EXPORT = qw(
    $TOY_CATEGORY_DOLLS
    $TOY_CATEGORY_ACTION_FIGURES
    $TOY_CATEGORY_EDUCATION
);

Readonly our $TOY_CATEGORY_DOLLS =&gt; 12;
Readonly our $TOY_CATEGORY_ACTION_FIGURES =&gt; 7;
Readonly our $TOY_CATEGORY_EDUCATION =&gt; 92;

1;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And then in some module you can access these constants:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;use MyApp::Constants::ToyCategories;

if ($toy-&gt;category_id() == $TOY_CATEGORY_EDUCATION) {
    my $response = ask_question('Are you an educator?');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, like I said, I don’t want to hardcode the constants.  I want them to be dynamically created by records in my toy_categories table which resides in my database.  Its actually pretty simple to do this with some tricky evals:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;package MyApp::Constants::ToyCategories;
use strict;
use warnings;

use Readonly;
use Exporter;
use Exporter qw( import );

our @EXPORT;

{
    my $dbh = code_that_returns_a_dbi_handle();
    my $sth = $dbh-&gt;prepare(q[
        SELECT toy_category_id, name
        FROM toy_categories
    ]);
    $sth-&gt;execute();
    $sth-&gt;bind_columns( \my( $id, $name ) );
    while ($sth-&gt;fetch()) {
        _export_variable( "toy_category_$name" =&gt; $id );
    }
}

sub _export_constant {
    my ($variable, $value) = @_;

    $variable = '$' . uc($variable);

    my ($error, $failed);
    {
        local $@;
        $failed = not eval(
            "Readonly our $variable =&gt; \$value"
        );
        $error = $@;
    }
    if ($failed) {
        die "Unable to create constant $variable: $error";
    }
    push @EXPORT, $variable;
}

1;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;What’s going on here?  Let’s start at the top:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;use Exporter qw( import );
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is the least intrusive way of using exporter and doesn’t pollute your namespace nearly as much as ‘use base qw( Exporter );’ does and is friendlies to other modules.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;my $dbh = code_that_returns_a_dbi_handle();
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Replace this with whatever you use to get a DBI database handle.  Take a look at &lt;a href="http://search.cpan.org/perldoc?DBIx::Connector"&gt;DBIx::Connector&lt;/a&gt; for a great alternative to doing this directly with DBI.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;my $sth = $dbh-&gt;prepare(q[
    SELECT toy_category_id, name
    FROM toy_categories
]);
$sth-&gt;execute();
$sth-&gt;bind_columns( \my( $id, $name ) );
while ($sth-&gt;fetch()) {
    ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I’m a big fan of writing my DBI selects in this fashion with bind_columns() because it tends to be the fastest way to get the data (versus fetchrow_hashref, etc) and tends to lead to the simplest code within the while loop since it just needs to use $id and $name versus $row-&gt;{$id} and $row-&gt;{name} (for example).&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;_export_variable( "toy_category_$name" =&gt; $id );
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;While all of the code within _export_variable() could just be inlined right in the spot, that’s bad design.  If you can get a piece of your code generalized and moved to a subroutine, do it.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$variable = '$' . uc($variable);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Constants should always, due to convention, be uppercase.  It is very important that you code to popular conventions because other people will most likely be working on your code later and if you come from a common expectation of how various things are done they will have an easier time ramping up to your code.  I try to code to the Modern Perl / CPAN conventions.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;my ($error, $failed);
{
    local $@;
    $failed = not eval ...;
    $error = $@;
}
if ($failed) { ... }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This bit of code was taken from &lt;a href="http://blog.woobling.org/2009/09/trytiny.html"&gt;nothingmuch’s blog entry&lt;/a&gt; where he announces &lt;a href="http://search.cpan.org/perldoc?Try::Tiny"&gt;Try::Tiny&lt;/a&gt; which provides a safe way to handle eval errors.  Read up there if you want to understand why the code was written this way.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$failed = not eval("Readonly our $variable =&gt; \$value");
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;While this code is several blocks deep in scope, this constant will exist in the package’s scope since it is being declared with ‘our’.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;push @EXPORT, $variable;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And finally we add the variable to the list of variables that will be exported.&lt;/p&gt;

&lt;p&gt;That’s it.  After this was implemented I thought it was so useful, simple, but requiring the knowledge of a few tricks, that I’d share it with ya’all.  Enjoy!&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16524288583</link><guid>http://blog.bluefeet.net/post/16524288583</guid><pubDate>Fri, 21 May 2010 16:29:00 -0700</pubDate><category>Perl</category><category>Constants</category></item><item><title>YAPC::NA 2010 Talks are Being Approved</title><description>&lt;p&gt;I just got my approval for the two proposals I had submitted for this coming &lt;a href="http://conferences.mongueurs.net/yn2010/"&gt;YAPC::NA 2010&lt;/a&gt;!  I’m very excited.  This will be my first time doing any sort of talk at a YAPC.  I’ve been wanting to do this for years and I am very grateful that the organizers of the conference considered me.  Over the last few years I’ve been trying to hone my presentation skills by presenting various topics almost monthly at the &lt;a href="http://thousand-oaks-perl.org"&gt;Thousand Oaks Perl Mongers&lt;/a&gt; and &lt;a href="http://losangeles.pm.org/"&gt;Los Angeles Perl Mongers&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The first talk is a five-minute lighting talk about how to clone yourself in Perl.  For those that are unaware: lighting talks are a great YAPC tradition where around a dozen speakers will present 5-minute or less talks.  These talks range from very advanced computer science topics, down to the silly, and sometimes bizarre.&lt;/p&gt;

&lt;p&gt;The other talk I’m doing is a 40-minute lecture/discussion showing examples of writing concise code.  This will be an extended version of the similar presentation that I’ve given at mongers.  I’ll be delving in to real-world cases where writing code in a more concise manner, reduces &lt;a href="http://petdance.com/perl/technical-debt/"&gt;technical dept&lt;/a&gt;, leads to more robust code, and a whole lot more.&lt;/p&gt;

&lt;p&gt;See you at YAPC!&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16524366173</link><guid>http://blog.bluefeet.net/post/16524366173</guid><pubDate>Sat, 17 Apr 2010 23:36:00 -0700</pubDate><category>Perl</category><category>YAPC</category><category>Talks</category><category>2010</category></item><item><title>Cassandra Presentation</title><description>&lt;p&gt;I wrote this for the &lt;a href="http://thousand-oaks-perl.org"&gt;TO.pm&lt;/a&gt; meeting on April 14th, 2010:&lt;/p&gt;

&lt;p&gt;&lt;iframe src="http://www.slideshare.net/slideshow/embed_code/3739718" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16524392862</link><guid>http://blog.bluefeet.net/post/16524392862</guid><pubDate>Thu, 15 Apr 2010 19:06:00 -0700</pubDate><category>Cassandra</category><category>Apache</category><category>Perl</category><category>CPAN</category><category>Presentation</category></item><item><title>Robust DBI Transaction and Connection Handling</title><description>&lt;blockquote&gt;&lt;b&gt;Edit:&lt;/b&gt; It turns out there is already a module on CPAN that does exactly what I talked about here.  Its called &lt;a href="http://search.cpan.org/perldoc?DBIx::Connector"&gt;DBIx::Connector&lt;/a&gt;.  I haven’t tried it yet, but it looks like the guy that wrote it designed it with input from the DBIC guys.&lt;/blockquote&gt;

&lt;p&gt;I’m a big fan of &lt;a href="http://search.cpan.org/perldoc?DBIx::Class"&gt;DBIx::Class&lt;/a&gt;.  Among DBIC’s many great features is its superb transaction and connection handling via &lt;a href="http://search.cpan.org/perldoc?DBIx::Class::Storage::DBI"&gt;DBIx::Class::Storage::DBI&lt;/a&gt;.  When I’m using raw DBI I feel like I’m missing these core components.  I should always be able to expect robust transaction and connection handling.&lt;/p&gt;

&lt;p&gt;I started playing around with creating a new CPAN module (something like DBIx::Robust, DBIx::Transaction, etc…) but each time I dove in to it I kept coming to the conclusion that DBIC’s DBI storage drivers provide everything I need and I would just be shooting myself in the foot by either porting DBIx::Class::Storage::DBI to a DBIC independent API or by writing it from scratch.&lt;/p&gt;

&lt;p&gt;Before I go any further, let me show you how attractive and awesome DBIC’s storage layer is:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Transactions may be nested, even without savepoints.&lt;/li&gt;
&lt;li&gt;Transaction savepoints can automatically be tracked allowing for reliable and incremental rollbacks.&lt;/li&gt;
&lt;li&gt;The appropriate DateTime::Format class is automatically determined based on the type of database.&lt;/li&gt;
&lt;li&gt;All database calls efficiently pass through a layer that detects stale connections that will attempt to re-connect to a database.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;a href="http://images.google.com/images?gbv=2&amp;q=kung+fu+panda+opening&amp;btnG=Search&amp;start=0"&gt;&lt;i&gt;“There is no charge for awesomeness, or attractiveness.”&lt;/i&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The DBIx::Class::Storage::DBI pod illustrates all this in a round-about way: &lt;i&gt;“If you set AutoCommit =&gt; 0 in your connect info, then you are always in an assumed transaction between commits, and you’re telling us you’d like to manage that manually. A lot of the magic protections offered by this module will go away. We can’t protect you from exceptions due to database disconnects because we don’t know anything about how to restart your transactions. You’re on your own for handling all sorts of exceptional cases if you choose the AutoCommit =&gt; 0 path, just as you would be with raw DBI.”&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;This stuff is really powerful, and we should never have to work with databases in Perl without it.  But, currently, it is only meant to work under DBIC, which is a shame.  I’m betting that DBIx::Class::Storage::DBI could be used directly, bypassing DBIC completely.  There is some DBIC stuff layered in there, but that should be ignorable.&lt;/p&gt;

&lt;p&gt;What do the rest of you think?  Has anyone considered moving this logic out in to a generic distribution that isn’t DBIC specific?  Is there merit in what I’m talking about?  Does anyone use DBIx::Class::Storage::DBI directly, bypassing DBIC?&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16524520737</link><guid>http://blog.bluefeet.net/post/16524520737</guid><pubDate>Sat, 23 Jan 2010 22:27:00 -0800</pubDate><category>Perl</category><category>CPAN</category><category>DBI</category><category>DBIx::Class</category><category>DBIx::Connector</category></item><item><title>use HTML::FormHandler;</title><description>&lt;p&gt;I’ve been meaning to give &lt;a href="http://search.cpan.org/perldoc?HTML::FormHandler"&gt;HTML::FormHandler&lt;/a&gt; a try for quite some time now.  Over the weekend I converted a form from some home-grown form validation and html generation to use HTML::FormHandler instead.  HTML::FormHandler was inspired by, and quasi-forked from, &lt;a href="http://search.cpan.org/perldoc?Form::Processor"&gt;Form::Processor&lt;/a&gt;.  There are many options for processing forms, such as &lt;a href="http://search.cpan.org/perldoc?FormValidator::Simple"&gt;FormValidator::Simple&lt;/a&gt; (Catalyst’s default) and &lt;a href="http://search.cpan.org/perldoc?Data::FormValidator"&gt;Data::FormValidator&lt;/a&gt;, to name a few.&lt;/p&gt;

&lt;p&gt;Up until now I’ve always thought that the existing form handling/validating modules on CPAN were incredibly lacking.  They all have these crazy and inconsistent APIs that in the end limit what you are able to do.  I don’t expect a form validation API to handle every possible situation, but I do expect it to provide a consistent API that is well documented and allows me to easily extend if I need additional functionality.  Plus none of them use Moose (AFAIK), which isn’t just me being a Moose evangelist, its also practical because Moose provides mechanisms to extend functionality via roles and to provide reusable validation with &lt;a href="http://search.cpan.org/perldoc?MooseX::Types"&gt;MooseX::Types&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;HTML::FormHandler solves these issues.  HTML::FormHandler can be a complete end-to-end solution for declaring form fields and types, applying server-side validation, generating the HTML for a form, and applying form submits to the database.  Almost everything and the kitchen sink is there, except client-side form validation, which can be added separately of course.  Normally a “do everything” package scares me, especially for something like form validation.  But, Gerda Shank (the author of HTML::FormHandler) did a great job splitting out the various pieces of HTML::FormHandler so that any piece of the form handling process can be subverted to your own needs, and there is &lt;a href="http://search.cpan.org/perldoc?HTML::FormHandler::Manual"&gt;copious amounts of documentation&lt;/a&gt; explaining how to do so.&lt;/p&gt;

&lt;p&gt;The &lt;a href="http://search.cpan.org/perldoc?HTML::FormHandler::Manual::Intro"&gt;HTML::FormHandler::Manual::Intro&lt;/a&gt; does a great job introducing HTML::FormHandler.&lt;/p&gt;

&lt;p&gt;There are a few downsides to this module’s current state.  It is relatively new and is still stabilizing.  For example, just recently the results of form validation were separated from the form object itself.  This is a huge fundamental change, but a necessary one.  Also, the concept of widgets was recently introduced.  Widgets are a great way to extend and customize the display of form fields, and the form as a whole.  But, this was just introduced and is still experimental, and has some rough edges.  Despite this, the widget design is very promising and I ended up using it myself (thanks to &lt;a href="http://search.cpan.org/perldoc?HTML::FormHandler::Manual::Rendering"&gt;HTML::FormHandler::Manual::Rendering&lt;/a&gt;) as my preferred rendering method.&lt;/p&gt;

&lt;p&gt;Enjoy.&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16525266212</link><guid>http://blog.bluefeet.net/post/16525266212</guid><pubDate>Mon, 12 Oct 2009 09:00:00 -0700</pubDate><category>CPAN</category><category>Perl</category><category>HTML::FormHandler</category></item><item><title>IE8, another screwed up version.</title><description>&lt;p&gt;I was really hoping that Internet Explorer version 8 (IE8) would finally be the version of IE where Microsoft stepped up to the plate and produced a fast browser, with few bugs, less Microsoft-only features, and a good and modern UI.&lt;/p&gt;

&lt;p&gt;I’m the kind of guy that holds judgment for a very long time, sometimes too long.  So it comes with great sadness that I announce that IE8 is not the browser I was hoping for.  It is riddled with bugs, the rendering engine crashes on many web sites, and it is SLOW.  Its the slowest browser of them all as far as I can tell.  It renders many web-2.0’ish sites with teeth-gritting sluggishness.  Once rendered, javascript animations tend to be jumpy as well.  I’ve found several cases where the event engine is even more screwed up than it was in IE7.&lt;/p&gt;

&lt;p&gt;If you’re a web developer and IE8 is causing the same pain for you as it has for me, consider adding this to your HTML*:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&lt;meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;small&gt;* This should be the very first tag after the opening &lt;head&gt; tag.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;This will force IE8 to run in IE7 compatibility mode.  When in IE7 compatibility mode IE8 will not crash nearly as often and will render your HTML/CSS/JS much more predictably and act more similar to how Chrome and FireFox behave.&lt;/p&gt;

&lt;p&gt;I don’t understand why Microsoft keeps doing this.  They have all the power in the world to &lt;b&gt;WIN&lt;/b&gt; the browser war, but they are just going to keep failing with crap software like this and loose one more market to Google.&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16525315811</link><guid>http://blog.bluefeet.net/post/16525315811</guid><pubDate>Tue, 01 Sep 2009 11:32:00 -0700</pubDate><category>Browsers</category><category>IE8</category></item><item><title>use Path::Class;</title><description>&lt;p&gt;The &lt;a href="http://search.cpan.org/"&gt;CPAN&lt;/a&gt; (Comprehensive Perl Archive Network) distribution, &lt;a href="http://search.cpan.org/perldoc?Path::Class"&gt;Path::Class&lt;/a&gt;, provides a simple OO API alternative to the built-in perl file IO functions such as &lt;a href="http://perldoc.perl.org/functions/open.html"&gt;open&lt;/a&gt;, &lt;a href="http://perldoc.perl.org/functions/opendir.html"&gt;opendir&lt;/a&gt;, &lt;a href="http://perldoc.perl.org/functions/stat.html"&gt;stat&lt;/a&gt;, etc.  Code written to use Path::Class tends to be smaller (concise, easier to maintain, etc) than similar code that uses the standard built-in functions.&lt;/p&gt;

&lt;p&gt;Here is an example of how a small utility might be written &lt;strong&gt;without&lt;/strong&gt; Path::Class:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;print "Find all files that are less than 10k in size...\n";

my $dir = '/some/dir';
opendir( DIR, $dir );
    my @files = readdir( DIR );
closedir( DIR );

foreach my $file (@files) {
    next if !-f "$dir/$file";
    if ( (stat "$dir/$file")[7] &lt; 1024 * 10) {
        print "$dir/$file\n";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And here it is re-written to use Path::Class:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;use Path::Class;
print "Find all files that are less than 10k in size...\n";

my $dir = dir('/some/dir');

while (my $file = $dir-&gt;next()) {
    next if $file-&gt;is_dir();
    if ($file-&gt;stat-&gt;size() &lt; 1024 * 10) {
        print "$file\n";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Using Path::Class is a no-brainer when you compare &lt;code&gt;&lt;code lang="perl" inline="1"&gt;(stat "$dir/$file")[7]&lt;/code&gt;&lt;/code&gt; with &lt;code&gt;&lt;code lang="perl" inline="1"&gt;$file-&gt;stat-&gt;size()&lt;/code&gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;One of Path::Class’s greatest stengths is that it is very simple and many of the features it provides are done so by glueing with other well-tested modules that have been on CPAN for a long time.  These modules include &lt;a href="http://search.cpan.org/perldoc?IO::Dir"&gt;IO::Dir&lt;/a&gt;, &lt;a href="http://search.cpan.org/perldoc?IO::File"&gt;IO::File&lt;/a&gt;, &lt;a href="http://search.cpan.org/perldoc?File::Path"&gt;File::Path&lt;/a&gt;, and &lt;a href="http://search.cpan.org/perldoc?File::stat"&gt;File::stat&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Some other highlights include:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Has a recurse() method that provides an enhanced File::Find-like interface.&lt;/li&gt;
&lt;li&gt;Works equally well with absolute and relative paths, and can correctly convert between the two.&lt;/li&gt;
&lt;li&gt;Symlinks are handled correctly and there are methods to interact with them.&lt;/li&gt;
&lt;li&gt;Works equally well under different operating systems, such as Linux and Windows.&lt;/li&gt;
&lt;li&gt;The interface, for me anyway, is about as intuitive as it gets.  Very well designed to DWIM.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;I’ve been using this module at $work for a while now and am very happy with it and have had coworkers tell me, after they gave it a try, how much cleaner their code ended up being because they used this module.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16525405275</link><guid>http://blog.bluefeet.net/post/16525405275</guid><pubDate>Wed, 05 Aug 2009 22:26:00 -0700</pubDate><category>Path::Class</category><category>CPAN</category><category>Perl</category></item><item><title>Upgrading to Catalyst 5.8</title><description>&lt;blockquote&gt;
&lt;b&gt;Update:&lt;/b&gt; Catalyst now comes with an upgrade document: &lt;a href="http://search.cpan.org/perldoc?Catalyst::Upgrading"&gt;http://search.cpan.org/perldoc?Catalyst::Upgrading&lt;/a&gt;
&lt;/blockquote&gt;

&lt;p&gt;Over the last few days at $work I’ve been upgrading Catalyst from 5.7 to 5.8.  This new version of catalyst, released in April, has been completely overhauled to use &lt;a href="http://search.cpan.org/perldoc?Moose"&gt;Moose&lt;/a&gt; for it’s OO system, among other enhancements and bug fixes.&lt;/p&gt;

&lt;p&gt;I found that the &lt;a href="http://search.cpan.org/perldoc?Catalyst::Manual::CatalystAndMoose"&gt;Catalyst::Manual::CatalystAndMoose&lt;/a&gt; manual was a great starting point to using Moose with Catalyst.  Also, &lt;a href="http://search.cpan.org/perldoc?Catalyst::Upgrading"&gt;Catalyst::Upgrading&lt;/a&gt; has specific points to consider when upgrading to 5.8.  During the initial install of Catalyst 5.8 I was told that I had a few related modules installed, that while not Catalyst prerequisites, I should upgrade them as they were known to fail on the new Catalyst.  I was lucky that I caught this message, as cpan did not pause to wait for me to read it and went on its marry way building, testing, and installing Catalyst.&lt;/p&gt;

&lt;p&gt;Once installed I went ahead and also upgraded some related modules we use such as &lt;a href="http://search.cpan.org/perldoc?Catalyst::Plugin::Authentication"&gt;Catalyst::Plugin::Authentication&lt;/a&gt;, &lt;a href="http://search.cpan.org/perldoc?DBIx::Class"&gt;DBIx::Class&lt;/a&gt;, &lt;a href="http://search.cpan.org/perldoc?Catalyst::Plugin::Session"&gt;Catalyst::Plugin::Session&lt;/a&gt;, &lt;a href="http://search.cpan.org/perldoc?Catalyst::Authentication::Store::DBIx::Class"&gt;Catalyst::Authentication::Store::DBIx::Class&lt;/a&gt;, etc.  This way I could test all these upgrades all at once instead of one at a time.&lt;/p&gt;

&lt;p&gt;Next I modified all my custom plugins to use &lt;a href="http://search.cpan.org/perldoc?MRO::Compat"&gt;MRO::Compat&lt;/a&gt; instead of &lt;a href="http://search.cpan.org/perldoc?Class::C3"&gt;Class::C3&lt;/a&gt; per the documentation in &lt;a href="http://search.cpan.org/perldoc?Class::C3::Adopt::NEXT"&gt;Class::C3::Adopt::NEXT&lt;/a&gt;.  But, then I realized I might as well just rewrite all my plugins as &lt;a href="http://search.cpan.org/perldoc?Moose::Role"&gt;Moose::Role&lt;/a&gt;s as its pretty easy to convert a plugin to a role and you end up with much cleaner code.&lt;/p&gt;

&lt;p&gt;I started Apache up and things mostly worked.  There were a few backwards incompatibilities that I wasn’t aware of, such as there were a few cases where developers had done this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sub index : Local { }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Instead of:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sub index : Private { }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In our previous version of catalyst (5.7) using :Local, while not documented, worked just like :Private if the subroutine was named index.  In 5.8 only :Private will cause a handler named index to be the default handler if the URL resolves to the controller only.  This was an easy fix.  There were a couple other small issues, but nothing major.  I found and fixed &lt;a href="https://rt.cpan.org//Ticket/Display.html?id=48084"&gt;a bug&lt;/a&gt; in &lt;a href="http://search.cpan.org/perldoc?Catalyst::Model::DBIC::Schema"&gt;Catalyst::Model::DBIC::Schema&lt;/a&gt; and added the support for the compute() method to &lt;a href="Catalyst::Plugin::Cache"&gt;Catalyst::Plugin::Cache&lt;/a&gt;.  Both of these changes reduced the amount of changes I needed to make to my own code.&lt;/p&gt;

&lt;p&gt;A couple hours in to it I was upgraded and everything was working.  Of course I spent the next few days upgrading/enhancing/rewriting Catalyst bits that could be done much more elegantly, and with less code, using Moose.&lt;/p&gt;

&lt;p&gt;On a side note, during the upgrade I found this great quote in &lt;a href="http://search.cpan.org/perldoc?Catalyst::Model::Adaptor"&gt;Catalyst::Model::Adaptor&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;Catalyst is glue, not a way of life!&lt;/blockquote&gt;

&lt;p&gt;Amen!  Most people, myself included, start out by writing all their business logic in their Controllers because that is what &lt;a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller"&gt;MVC&lt;/a&gt; told them to do.  Don’t do it!  Catalyst is meant to be a GLUE - most of your application should be written in a way that it doesn’t give a flying crap how, or by whom, it is used.  Put your business logic in modules that optionally expose themselves as Models (perhaps via &lt;a href="http://search.cpan.org/perldoc?Catalyst::Model::Adaptor"&gt;Catalyst::Model::Adaptor&lt;/a&gt;) or just by adding a use statement in your controller that then uses that module.  Your controllers should be little more than code to glue a data source with the view and provide some input validation.&lt;/p&gt;

&lt;p&gt;I’ve been waiting a long time for this Moosification and its been a joy working with this new Catalyst.  Next up to bat will be the Moosification of &lt;a href="http://search.cpan.org/perldoc?DBIx::Class"&gt;DBIx::Class&lt;/a&gt;!  Think we’ll get it by Christmas?  :)&lt;/p&gt;

&lt;p&gt;Don’t forget to buy the new &lt;a href="http://www.shadowcat.co.uk/blog/matt-s-trout/the-definitive-guide-to-catalyst/"&gt;Catalyst Book&lt;/a&gt;!  If purchasing from Amazon make sure you follow &lt;a href="http://www.amazon.com/Definitive-Guide-Catalyst-Maintainable-Applications/dp/1430223650?&amp;camp=2486&amp;linkCode=wey&amp;tag=enligperlorga-21&amp;creative=8882"&gt;this link&lt;/a&gt; to ensure that the &lt;a href="http://www.enlightenedperl.org/"&gt;Enlightened Perl Organisation&lt;/a&gt; gets a cut of the sale.&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16525494999</link><guid>http://blog.bluefeet.net/post/16525494999</guid><pubDate>Tue, 28 Jul 2009 17:15:00 -0700</pubDate><category>Perl</category><category>CPAN</category><category>Catalyst</category></item><item><title>XS Hits Newb; Bystanders Watch in Dismay</title><description>&lt;p&gt;Last year I wrote &lt;a href="http://search.cpan.org/perldoc?GIS::Distance::Fast"&gt;GIS::Distance::Fast&lt;/a&gt; to provide some much needed speedups to the pure-perl &lt;a href="http://search.cpan.org/perldoc?GIS::Distance"&gt;GIS::Distance&lt;/a&gt;.  This ::Fast version used Inline::C which isn’t all that optimal and was just a scapegoat for doing the right thing.&lt;/p&gt;

&lt;p&gt;So, this evening I rolled up my sleeves and went to work.  I first looked at a module I already knew to use XS, &lt;a href="http://search.cpan.org/perldoc?Cache::Memcached::Fast"&gt;Cache::Memcached::Fast&lt;/a&gt;.  That was overwelming.&lt;/p&gt;

&lt;p&gt;Then I went on over and read through the &lt;a href="http://perldoc.perl.org/perlxs.html"&gt;perlxs&lt;/a&gt; and &lt;a href="http://perldoc.perl.org/perlxstut.html"&gt;perlxstut&lt;/a&gt; docs.  I was STILL floundering about not sure what to do.  I then took a whack at using &lt;a href="http://www.swig.org/"&gt;SWIG&lt;/a&gt; (Simplified Wrapper and Interface Generator).  OhMyGodz I’m feeling overwhelmed now and still nothing works.  I’m not going to even document my attempts up until this point.&lt;/p&gt;

&lt;p&gt;I then found &lt;a href="http://www.swig.org/papers/Perl98/swigperl.htm"&gt;this document&lt;/a&gt; that goes in to more detail about using SWIG with Perl.  The thing about this document that helped me so much is that in section 2, Perl Extension Building, it had the simplest example I had yet run in to, and it made sense!  Its kinda funny that a SWIG document was what taught me how to write my own XS without using SWIG.  :)&lt;/p&gt;

&lt;p&gt;An XS distribution can contain as little as two files (well, beyond the usual Makefile.PL, etc).  A single .pm file and a .xs file is enough.  You can get more complex, if you want, of course.  Once you’ve written your Module.xs file you can run it through &lt;code inline="1" lang="bash"&gt;xssubpp Module.xs &gt; Module.c&lt;/code&gt; to see what the .c file looks like and to verify that your .xs file is correct.&lt;/p&gt;

&lt;p&gt;Note that xssubpp may complain about you using types that aren’t in your typemap.  This is because xssubpp doesn’t know how to find your system’s typemap file.  You can specify a typemap file using the -typemap switch.  The file is located somewhere in your perl lib path as ExtUtils/typemap.&lt;/p&gt;

&lt;p&gt;So, let’s go for an example.  Let’s make an XS module that convert hours to minutes.  I structure all my code and files as if they would be distributed as a CPAN module.  This has added benefits as you’ll see in a moment.&lt;/p&gt;

&lt;p&gt;convert-hoursminutes/lib/Convert/HoursMins.pm:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;package Convert::HoursMins;
use strict;
use warnings;

our $VERSION = 0.01;

use XSLoader;

XSLoader::load('Convert::HoursMins', $VERSION);

1;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;convert-hoursminutes/HoursMins.xs:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

double convert_hours_mins( double hours ) {
    return hours * 60;
}

MODULE = Convert::HoursMins  PACKAGE = Convert::HoursMins

PROTOTYPES: DISABLE

double
convert_hours_mins (hours)
    double hours
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;convert-hoursmins/Makefile.PL&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;use inc::Module::Install;

name     'Convert-HoursMins';
all_from 'lib/Convert/HoursMins.pm';
requires 'XSLoader';

WriteAll;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;convert-hoursmins/t/00_basic.t&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;use strict;
use warnings;
use Test::More tests =&gt; 2;

BEGIN{ use_ok('Convert::HoursMins'); }

is(
    Convert::HoursMins::convert_hours_minutes(1.5),
    90,
    '1.5 hours is 90 minutes',
);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now lets see if it worked:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;perl Makefile.PL
make
make test
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Bottom line for me is XS isn’t all that hard when your C code isn’t all that complex.  SWIG is overkill for small stuff.  But for large swaths of C code I bet SWIG saves lives.  Also, XS is a little arcane, but its not too bad.&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16525601042</link><guid>http://blog.bluefeet.net/post/16525601042</guid><pubDate>Mon, 20 Jul 2009 20:53:00 -0700</pubDate><category>Perl</category><category>XS</category><category>C</category></item><item><title>$(document).ready() Shortcut</title><description>&lt;p&gt;When writing jquery you almost always put your code within a ready block:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$(document).ready(function(){
    // Code...
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And I always forget the exact syntax.  I just found that jQuery has a shortcut:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$(function(){
    // Code...
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Much better!&lt;/p&gt;</description><link>http://blog.bluefeet.net/post/16525633354</link><guid>http://blog.bluefeet.net/post/16525633354</guid><pubDate>Fri, 17 Jul 2009 14:54:00 -0700</pubDate><category>jQuery</category></item></channel></rss>

