=pod

=head1 is_url()

  if (&is_url($string)) { ...

=head1 DESCRIPTION

B<is_url()> returns true/false according to whether the string passed
to it "looks like" a well formed URL.  

Basically we do this by passing it to URI::URL and seeing if it barfs
or not.  The preceeding regexp is just so we don't bother
instantiating URI::URL if it's not needed.

=head1 SCRIPT CATEGORIES
Web/Misc
=cut

use strict;

sub is_url {
  my $string = shift;

  my $uri;

  # Basically, look for something vaguely resembling a URL,
  # then hand it off to URI::URL for examination
  local $SIG{__DIE__} = 'DEFAULT';  # URI::URL croaks on failure
  if ($string =~ /(\w+:.+)/) {
     # looks more or less right
     require URI::URL;  # load URI::URL on demand only. only loads once
     # Don't assume http.
     URI::URL::strict(1);

	  eval { $uri = URI::URL->new($1); };
     return !$@;   # $@ is true if the eval failed
  } else {
     return 0;
  }
}