Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the WWW-Mechanize CPAN distribution.

Report information
The Basics
Id: 2299
Status: resolved
Priority: 90/
Queue: WWW-Mechanize

People
Owner: Nobody in particular
Requestors: frag [...] ripco.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.38
Fixed in: (no value)



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 {
I'll fix it, but not with the patch. I'll change it like I changed form() into form() wrapping form_number() and form_name(). I really don't like boolean flags. You wind up with code like: $x = $agent->follow( "this", 1 ); What's the 1? Is it meaningful? It's magic! Better to create a specific function for it.