Subject: | follow("number, but really a string"); |
I've got links where the only link text is a numeric id. This
completely stymies follow(). It sees the number, and goes to that
index in @{$agent->{links}}. There's no way in place to force the
number to be treated as a string.
I've enclosed a simple patch that fixed this for me. It adds an optional
flag, 'string', that can be passed to follow(). It forces the number
to be treated as a string, and is otherwise ignored.
-- Mike F.
--- Mechanize.pm~ Mon Mar 24 23:47:37 2003
+++ Mechanize.pm Thu Mar 27 11:02:54 2003
@@ -204,19 +204,22 @@
=head2 $agent->follow($string|$num)
-Follow a link. If you provide a string, the first link whose text
-matches that string will be followed. If you provide a number, it will
-be the nth link on the page.
+=head2 $agent->follow($num => 'string')
+
+Follow a link. If you provide a string, the first link whose text
+matches that string will be followed. If you provide a number, it
+will be the nth link on the page. To force a number to be treated as
+a string, also pass in the string 'string'.
Returns true if the link was found on the page or undef otherwise.
=cut
sub follow {
- my ($self, $link) = @_;
+ my ($self, $link, $flag) = @_;
my @links = @{$self->{links}};
my $thislink;
- if ( $link =~ /^\d+$/ ) { # is a number?
+ if ( $link =~ /^\d+$/ and (not $flag or $flag ne 'string')) { # is a number?
if ($link <= $#links) {
$thislink = $links[$link];
} else {