I'm considering some enhancements to Win32::IE::Mechanize and have encountered a potential issue with Win32::OLE.

One of the things I'm attempting to do is to improve IE Mech's page complete logic. Doing so requires monitoring IE's event stream looking for a condition that indicates that IE has 'completed' the page.

In testing various schemes, I've encountered a problem relating to IE's popup treatment. When I configure IE to block popups the test program I'm using runs well. When I disable IE's popup blocker and run the test program I get a perl crash shortly after IE's NewWindow3 event. I can provide the test jig if anyone is interested.

As an experiment I added some logic to the IE perl event handler to catch the NewWindow3 event and create a new IE for it with the following code
sub win32_ie_events { my( $agent, $event, @args ) = @_; $events_ok++ or init_win32_ie_events(); $t_last_event = gettimeofday(); CASE: { # NON RELEVANT CODE DELETED $event eq 'NewWindow3' and do { my $pu = Win32::OLE->new('InternetExplorer.Application')-> +{Application}; #Win32::OLE->WithEvents( $pu, \&win32_ie_events, 'DWebBrow +serEvents2' ); $args[0]->Put($pu); } } my $te = sprintf '%6.2f', $t_last_event - $t_start; print "$te $agent $dl_cnt $dl_tot [$event]\n"; }
With this code in place, the test program runs OK. However, it raises the question of how to handle the child's events re child completion and other potential IE Mech issues. It appears that I can examine the event's agent parameter to tell which IE the event came from (I'm not really sure about this, I'd appreciate any cluse). So I tried to use the same event handler per the code that is commented out. When I do this, the print statements generate output that looks like two events overwriting each other. It appears that the event routine may have been reentered! I've considered a separate event handler for the child window but ultimately, that is not attractive since a parent may have many children who may have many children and so on. I suppose I might be able to do something with anonymous handlers. However, I attack this issue, it seems to me that there are issues of multiple OLE event streams to perl that need to be dealt with.

Now my questions -

Is my guess about what is going on correct? Is the current Win32::OLE event support safe in the sense that it passes only one event at a time to perl when there are multiple concurrently operating automation objects?

Is there a programming technique that can make it safe in this sense? What is it?

Would anonymous event handlers work? Would this create threading issues with perl? BTW, I'm reluctant to use this rechnique as it causes other difficulties.

I'd also appreciate any advice concerning how to address this issue. If anyone has questions or would like the testing routines I’ll gladly provide them.


In reply to Win32::OLE and Win32::IE::Mechanize by puff

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.