Subject: | Some corrections to Win32::IE::Mechanize |
Date: | Sat, 17 Mar 2007 20:07:51 +0100 |
To: | <bug-Win32-IE-Mechanize [...] rt.cpan.org> |
From: | "K. Wittrock" <KWittrock [...] web.de> |
Hello,
I found some corrections to Win32::IE::Mechanize (version 0.009) which I want to communicate.
BEGIN block: When Time::HiRes isn't installed, the wait loop in sub _wait_while_busy doesn't sleep. This freezes your screen during
page fetches. It would be preferable to use a 1 second sleep in this case, thus waisting 0.5 seconds per page fetch on average.
Suggested correction: replace
$@ or $SLEEP = 0.055
by
$SLEEP = $@ ? 1 : 0.055
in the BEGIN block and
$SLEEP and sleep( $SLEEP )
by
sleep( $SLEEP )
in sub _wait_while_busy.
sub _wait_while_busy: At present the sub returns when ReadyState is 3, which is by far too early. Suggested correction: replace
while ( $agent->{ReadyState} <= $READYSTATE )
by
while ( $agent->{ReadyState} != 4 )
By the way the wait loop cannot be controlled by while ( $agent->{Busy} == 1 ). My tests show that Busy sometimes switches back from
0 to 1 during a page fetch.
sub _wait_while_busy: Sometimes ReadyState is 4 from the beginning, thus the call $self->_wait_while_busy is essentially a no-op. It
takes about 80 loop cycles until ReadyState switches from 4 to 3, and then 100 cycles to switch back to 4. On the other hand, Busy
is 1 from the beginning. I observed this when I submitted a login page. Maybe this occurs while the server is verifying my password.
Suggested correction: add
while ( $agent->{ReadyState} == 4 and $agent->{Busy} ) {
sleep( $SLEEP );
}
near the beginning.
sub find_frame: When a subroutine "falls through", it returns the value of the last evaluated expression. In sub find_frame it's not
obvious what this might be (actually it's an empty string, I don't know why). Suggestion: for clarity, just add
return; # indicate no success
at the end.
sub get: When it is called with no url (e.g. because load_frame didn't find the requested frame), sub get shouldn't navigate to the
current page and report 'Ok'. Suggested correction: add
return unless $url; # indicate no success
near the beginning.
sub click_button: Clicking by number doesn't work. Suggested correction: replace
@buttons <= $args{number} and return
by
@buttons < $args{number} and return;
('<' instead of '<=', and ';' at the end).
Note: sub submit in Win32::IE::Form should call _wait_while_busy too.
Note: sub success is a mess. It always returns true, even when you are not connected to the Internet and IE displays its "Server not
found" page.
I will attach my sub sub dump_page, which might be of general interest. It helps me a lot finding the next navigation step without
investigating the HTML code of the current page.
Please feel free to contact me if I can be of any further help.
Kind regards
Klaus Wittrock
Message body not shown because it is not plain text.