[code-review] URI::Find::Iterator
Simon Wistow <simon-n4s/[email protected]> Wed, 3 Dec 2003 14:29:56 +0000
| Newsgroups | gmane.comp.lang.perl.code-review-ladder |
|---|---|
| Message-ID | <[email protected]> |
Reposted from london.pm
Inspired by this http://perl.plover.com/yak/iterators/ talk by Mjd at
YAPC::Europe this year I knocked up an iterator version of URI::Find.
use URI::Find::Iterator;
my $string = "foo http://thegestalt.org/simon/ bar\n";
my $it = URI::Find::Iterator->new($string);
while (my $match = $it->match()) {
print "Matched $match\n";
$it->replace("<a href='$match'>$match</a>");
}
# prints
# foo <a href='http://thegestalt.org/simon/'> \
# http://thegestalt.org/simon</a> bar
print $it->result();
http://www.thegestalt.org/simon/perl/URI-Find-Iterator-0.1.tar.gz
there's still a bit of work to be done - match() should probably return
($uri, $orig_uri) = $it->match()
being a URI::URL object and the original string just like the original
but comments would be appreciated.
It occured to me that the underlying code could be spun out into
Regex::Iterator to provide a generic way to iterate over regexes with
U:F:I being a thin shim on top.
I finished the code last night when I found it lying around about 6
months after doing the initial stab . I'm using a slightly odd mechnism
for iterating and I should probably try and remember why I did that.
Again comments welcome.
Simon