NAME

Text::FindLinks - Find and markup URLs in plain text

SYNOPSIS

use Text::FindLinks 'markup_links';
my $text = "Have you seen www.foo.com yet?";
# Have you seen <a href="http://www.foo.com">http://www.foo.com</a> yet?
print markup_links(text => $text);

FUNCTIONS

markup_links(text => ..., [handler => sub { ... }])

Finds all URLs in the given text and replaces them using the given handler. The handler gets passed three arguments: the URL itself, all the text to the left from it and all the text to the right. (The context is passed in case you would like to keep some URLs untouched.) If no handler is given, the default handler will be used that simply creates a link to the URL and skips URLs already turned into links.

find_links(text => ...)

Returns an array with all the URLs found in given text. Just a simple wrapper around markup_links, see the sources.

decorate_link($url, $left, $right)

Default URL handler that will be used if you don’t pass your own to the markup_links sub using the handler attribute. It turns an URL into a HTML link and skips URLs that are apparently already links. Not exported.

BUGS

The algorithm is extremely naive, a simple regex. It is almost certain that some URLs will not be recognized and some things that are not URLs will (to keep the balance). I’d be glad to hear if there is some URL that misbehaves.

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-FindLinks

AUTHOR

Tomáš Znamenáček, zoul@fleuron.cz

http://github.com/zoul/Text-FindLinks

COPYRIGHT & LICENSE

Copyright 2009 Tomáš Znamenáček

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.