NAME
URI::Find::Iterator - provides an iterator interface to URI::Find
SYNOPSIS
use URI::Find::Iterator;
my $string = "foo http://thegestalt.org/simon/ bar\n";
my $it = URI::Find::Iterator->new($string);
while (my ($uri, $orig_match) = $it->match()) {
print "Matched $uri\n";
$it->replace("<a href='$uri'>$uri</a>");
}
# prints
# foo <a href='http://thegestalt.org/simon/'>http://thegestalt.org/simon</a> bar
print $it->result();
DESCRIPTION
Inspired by Mark Jason Dominus' talk Programming with Iterators and Generators (available from http://perl.plover.com/yak/iterators/) this is an iterative version of URI::Find that hopefully makes code a little easier to understand and works slightly better with people's brains than callbacks do.
METHODS
new <string> [%opts]
Takes a string checking as an argument. Optionally can also take a class name to extract regexes from (the class must have uri_re and schemeless_uri_re methods).
URI::Find::Iterator->new($string, class => "URI::Find::Schemeless");
would be the canonical example.
Alterantively it could take a straight regexp of your own devising
URI::Find::Iterator->new($string, re => "http://[^ ]+");
match
Returns the current match as a tuple - the first element of which is a URI::URL object and the second is the original text of the URI found.
Just like URI::Find.
It then advances to the next one.
replace <replacement>
Replaces the current match with replacement
result
Returns the string with all replacements.
BUGS
None that I know of but there are probably loads.
It could possibly be split out into a generic Regex::Iterator module.
COPYING
Distributed under the same terms as Perl itself.
AUTHOR
Copyright (c) 2003, Simon Wistow <simon@thegestalt.org>
SEE ALSO
URI::Find, http://perl.plover.com/yak/iterators/