Random Geekery

Perl Hacks In My Workspace

Added by to Coolnamehere on

Tags · perl ·

Parrot Babysteps 04 - Adding Command Line Arguments Parrot Babysteps 05 - More About Arrays

This page shines a fresh light on specific hacks from the O’Reilly Perl Hacks book. It should be obvious from the tone and content that this is not intended to replace any of the original material or take credit for anything in the book.

Perl Hacks is a great book. I catch something new every time I open it. That’s at least partly because I still haven’t read it from cover to cover. The “Hacks” series of books is written in such a way that cover-to-cover reading is not needed, thankfully.

The browser hacks from the beginning are an especially convenient way to add some Perl-friendly functionality to Firefox. One minor issue is that I spend a lot of my time in ELinks, a text-based Web browser. Why? Well, most of my work is done over an ssh connection, so I’m already using GNU Screen and vim. Keeping my Web browser within my screen session reduces context switching. screen also keeps my sessions alive, so everything including my ELinks browser session is intact when I come back to my workspace the next morning.

Naturally, I had to examine Hack #1 in the context of ELinks.

There are a couple of preliminary steps to get out of the way before adding CPAN shortcuts to ELinks. First, install ELinks. Second, make sure smart prefixes are enabled.

The first requirement for this hack is ELinks. The ELinks download page shows all sorts of nifty ways to install it. I went the easy way and just used my system package managers.

That’s apt-get on Ubuntu Linux:

$ sudo apt-get install elinks

Or MacPorts on OS X:

$ sudo port install elinks

Windows folks are left to their own devices, since most of my Windows elinks usage is on other systems via Putty. I do know that ELinks is available in Cygwin.

Enable Smart Prefixes

The easiest way to test if smart prefixes are enabled is by trying to use one that’s already been defined. Try opening the following URL in ELinks:

g Modern::Perl

The resulting page should look something like this. Follow these steps if that is not the case:

  • Enter o to open the Options Manager
  • Open Protocols / URI Rewriting / Enable Smart Prefixes ** Use the space bar to expand the tree as you go.
  • Select [Edit]
  • Make sure the text field is set to 1.
  • Select [OK]
  • Select [Save]

Now go back and try to open g Modern::Perl again. That did the trick for me.

On to the CPAN shortcuts.

Adding a Smart Prefix

  • Enter o to open the Options Manager
  • Open Protocols / URI Rewriting / Smart Prefixes
    • Use the space bar to expand the tree as you go.
  • Select [Add]
  • Enter the name of the smart prefix, then select [OK]
  • Select [Edit]
  • Enter the URL for the smart prefix, then select [OK]
  • Select [Save]

The Smart Prefixes

Description Prefix URL
Search CPAN cpan http://search.cpan.org/search?mode=module;query=%s
Show Module Documentation cpod http://search.cpan.org/perldoc/%s
AnnoCPAN Module Documentation apod http://www.annocpan.org/?mode=search;field=Module;latest=1;name=%s

Try Them Out!

Try the following URLs to get you started.

  • cpan Modern::Perl
  • cpod Acme::Python
  • apod Moose

References

  • Perl Hacks by chromatic with Damian Conway and Curtis ‘Ovid’ Poe. Copyright 2006 O’Reilly Media, Inc., 0-596-52674-1