Archive for February, 2012

File::PlainPath – Let Paths Be Paths Again

Sunday, February 26th, 2012

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 path_to method).

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.

The Little Story of Opel

Saturday, February 18th, 2012

Yesterday was World Cat Day (as observed in Poland), so I thought this might be the perfect time to tell you a little cat story.

More than two years ago, I posted the story of Rocket, a kitten that I found in my neighborhood — now a big, happy cat living with my parents. This story has a very similar beginning.

It was a cold September evening, I was walking home along a busy street, when I heard a kitten squeak. It was obviously coming from under a car parked near the street, so I started looking, but couldn’t see any kitten under the car. The squeaking continued, so I knew it must have been there, and I kept looking and reaching behind the wheels, but to no avail.

Since many people were passing by, my unusual activities attracted the attention of some of them. One man with an “excuse me sir, what are you doing?” look approached me, but before he even asked me a question, the kitten meowed again, so the man began searching with me.

After we both searched for a while with no success, the guy said “you know what, I live in this block here and I know the owner of this car, let me call him”. In a few minutes, the owner came and joined the search operation.

He looked inside the car just to be sure the kitten didn’t get in there in some miraculous way, but that was not the case. It was obvious that the little guy was somewhere in the car undercarriage, but the meowing seemed to be coming from different places and neither one of us was able to tell exactly where the kitten could be.

In the end, we lifted the car up with a jack, the owner crawled under it and saw some fur sticking out from a hollow spot next to the exhaust pipe. He reached in there and got the kitten out — the poor thing looked all dirty and miserable, but didn’t appear to be hurt in any way. The first guy called his wife, who brought some cat food (it turned out they had two Persian cats) and water for the rescuee.

(more…)

  • Archives

  • Categories

  • Meta

  • Latest Tweets


    Warning: Illegal string offset 'last_access' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 334

    Warning: Illegal string offset 'time_limit' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 334

    Warning: Illegal string offset 'last_access' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 336

    Warning: Illegal string offset 'twitter_api' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 234

    Warning: Illegal string offset 'user_token' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 262

    Warning: Illegal string offset 'user_secret' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 263

    Warning: Illegal string offset 'consumer_key' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 264

    Warning: Illegal string offset 'consumer_secret' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 265

    Warning: Illegal string offset 'twitter_username' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 270

    Warning: Illegal string offset 'show_retweets' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 272

    Warning: Illegal string offset 'exclude_replies' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 275

    Warning: Illegal string offset 'twitter_data' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 282

    Warning: Illegal string offset 'twitter_data' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 350

    Warning: Illegal string offset 'twitter_data' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 351
    Twitter outputted an error:
    .
    Warning: Illegal string offset 'time_format' in /usr/local/www/odyniec.net/public/blog/wp-content/plugins/twitget/twitget.php on line 484
  • Follow odyniec on Twitter