#!/usr/bin/perl

use strict;
use warnings;

use URI::Find;
use WWW::Shorten 'Metamark';

my ( $conversion, $needs_conversion );

if ( $ARGV[0] eq "-u" ) {
	shift @ARGV;
	$conversion = \&makealongerlink;
	$needs_conversion = qr/xrl\.us/;
} else {
	$conversion = \&makeashorterlink;
	$needs_conversion = qr/groups\.google\.com|gmane/;
}

sub maybe_shorten {
	my $uri = shift;

	$uri = $conversion->($uri) || $uri if $uri =~ $needs_conversion;

	return "<$uri>";
}

my $f = URI::Find->new(\&maybe_shorten);

while (<>) {
	$f->find(\$_);
	print;
}


