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.