Having some free time during the Christmas break, I decided to give a shot at a small project that I had in mind for a while, and that was to develop a PSGI-compliant(-ish) web server with support for the SPDY protocol.
In case you haven’t heard of it, SPDY is a networking protocol developed at Google with a goal of reducing web page load latency. It is currently used by some of Google services (including search and Gmail) and by Twitter, and is supported natively in Firefox, Chrome, and Opera — so if you visited any of those sites with any of those browsers, it’s highly likely that your web content was transmitted by means of SPDY. An official standard for the protocol is in the works.
Happy 25th Birthday, Perl! I made you a card:
perl -C -e'print map+(v9635 x8^unpack B8).(v10)[++$n%9],(unpack u,"MK__^=^WW_S_WK)FNO\$3F5U\$7BJJ.=>U51S-WK)GNM>UF=W%[K[N>?___SW__")=~/./g'
In this article, we'll develop a basic search application using Dancer and
Sphinx. Sphinx is an open source search engine
that's fairly easy to use, but powerful enough to be deployed in high-traffic
sites, such as Craigslist and Dailymotion.
In keeping with this year's Dancer Advent Calendar trend, the example app will
be built on Dancer 2, but it should work just as well with Dancer 1.
Alright, let's get to work.
The de facto standard way of constructing portable filesystem paths in Perl is through the use of File::Spec's catfile and catdir functions. Example:
my $path = File::Spec->catfile('dir', 'subdir', 'file.txt');
This method, or a similar one involving Path::Class, is the most recommended approach and has been adopted by application development frameworks like Dancer (which has a wrapper method for it, named
path) and Catalyst (with its
The slight problem that I see with this method is that it makes code a bit more complicated, and thus a bit less readable. Paths become lists of parameters and no longer look like paths.
I wrote a simple module that tries to address this by allowing you to write paths the traditional way -- as strings, using a directory separator of your choice (
/ being the default), while the
catfile stuff happens behind the scenes. You can just say:
my $path = path 'dir/subdir/file.txt';
What it does is it splits the path string on each occurrence of the forward slash and feeds the resulting list of path components to
File::Spec->catfile, which reassembles them using the appropriate OS-specific directory separator, and constructs the OS-specific path that you want.
The module is up on Github, and should also be available on CPAN shortly.
perldoc perlsyn | perl -ne 's/^.*?"|\\.*$//g,print if/1\.\.15/'