Subject: | find_link_dom(text => 'foo') runs slowly |
I think find_link_dom() tries to parse as many arguments as possible and
search with xpath(). It then tries to remove those arguments from
%opts. If there are some it can't remove, it falls back and does a
slower search by instantiating a bunch of WWW::Mechanize objects. That
instantiation can take many seconds on a large page.
I think the code is currently mishandling find_link_dom(text => 'foo')
calls:
# Decode text and text_contains into XPath
for my $lvalue (qw( text id name class )) {
...
my $lhs = $lefthand{ $lvalue } || '@'.$lvalue;
for my $op (keys %match_op) {
my $key = "${lvalue}_$op";
if (exists $opts{ $key }) {
my $p = delete $opts{ $key };
push @spec, sprintf $match_op{ $op }, $lhs, $p;
};
};
Note that the key is "${lvalue}_$op". This works for "text_contains",
but if you hand in 'text' as the lvalue, it ends up looking for "text_",
which doesn't exist in %opts. I fixed it by adding a line, and pulling
the "_" out of the $key-building statement:
$op = '_'.$op if length($op);
my $key = "${lvalue}$op";