Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

davorg (18)

davorg
  dave@dave.org.uk
http://dave.org.uk/
Yahoo! ID: daveorguk (Add User, Send Message)

Hacker, author, trainer

Technorati Profile [technorati.com]

Journal of davorg (18)

Wednesday August 28, 2002
02:57 AM

Scratching Other People's Itches

[ #7356 ]
pdcawley posed a problem on the #london.pm IRC channel yesterday. He wanted a program that would parse a POD file, search for links and replace the long ones with a link from makeashorterlink.com. Apparently this will make life a lot easier for him when he's writing the Perl6 summaries.

I had far better things to do with my time, but it sounded like an interesting problem.

Here's my solution:

#!/usr/bin/perl -w

use 5.006;
use strict;

use Pod::Parser;

package Pod::Parser::MASL;

use MakeAShorterLink;
our @ISA = qw(Pod::Parser);

sub interior_sequence {
  my $parser = shift;
  my ($seq_command, $seq_argument, $pod_seq) = @_;

  return $parser->SUPER::interior_sequence(@_) unless $seq_command eq 'L';
  return $parser->SUPER::interior_sequence(@_) unless $seq_argument =~ /^http/i;

  $_[1] = makeashorterlink($seq_argument) || $seq_argument;

  $pod_seq->parse_tree($parser->parse_text($_[1]));

  return $parser->SUPER::interior_sequence(@_);
}

package main;

my $p= Pod::Parser::MASL->new;
$p->parse_from_filehandle(\*STDIN)  unless @ARGV;
$p->parse_from_file($_) for @ARGV;

It uses my MakeAShorterLink.pm which has just appeared on CPAN.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.