On Jul 17, 2007, at 9:55 PM, Andy Lester wrote:


On Jul 17, 2007, at 11:53 PM, Father Chrysostomos wrote:

What do you think? (And is the name intuitive enough?) Or do you think that a plugin mechanism for Mech would be good anyway?

Send it to the LWP list and see what people think. I'm only one pair of eyes.


A while back, I suggested to Andy a plugin mechanism for WWW::Mechanize that would allow me to write a JavaScript plugin for it. Here is what I sent him yesterday, for everyone’s perusal.

I must add that the Mech patch does not take into account what should happen to plugin objects when _push_pagestack is called. I suggest that use_plugin record its arguments, so that the plugin objects can be created afresh each time a new page is loaded.

Also, please CC to me (sprout [at sign] cpan . org) any important replies, so I don't have to subscribe to the mailing list. Thank you.


Hello,

Please have a look at the attached patch for Mech and tell me what you think. I have not tested it thoroughly yet. If you like, I can write tests and documentation as well.

Attached also are pre-alpha versions of the plugins, in case you would like to look at them. So far, only scripts embedded in the page that use document.write() to generate HTML code really work. I still have to get <script src=...> to work and I have to trigger event handlers when appropriate. But, just to demonstrate, look at this four-liner, which fetches a page that has generated content:

use WWW::Mechanize;
($m = new WWW::Mechanize quiet => 1)->use_plugin(JavaScript);
$m->get('http://ctosonline.org/order/'); # contains a JS-scrambled e-mail address
print $m->content(format => text), "\n";

(I do still have to resolve the "Attempt to free unreferenced scalar" issue that show up in perl 5.8.8.)


On second thought, seeing that wmpdom is going to override most of Mech's content-handling functionality anyway, maybe I could simply make a subclass of Mech, called WWW::Mechanize::Scriptable, that will provide the DOM tree and allow various scripting engines to plug in to it. And this would make it easier for you, too. What do you think? (And is the name intuitive enough?) Or do you think that a plugin mechanism for Mech would be good anyway?


Father Chrysostomos

Attachment: Mech-plugins.diff
Description: Binary data

Attachment: WWW-Mechanize-Plugin-JavaScript-0.0.1.tar.gz
Description: GNU Zip compressed data



Reply via email to