Test::WWW::Mechanize::Object - run mech tests by making requests on an object
Version 0.01
use Test::WWW::Mechanize::Object; my $mech = Test::WWW::Mechanize::Object->new(handler => $obj); $mech->get_ok('/foo'); # use $mech as usual, omitting scheme/host if you want to
Test::WWW::Mechanize::Object exists to make it easier to run tests with unusual request semantics.
Instead of having to guess at which parts of the LWP::UserAgent and WWW::Mechanize code needs to be overridden, any object that implements a (relatively) simple API can be passed in.
All methods from Test::WWW::Mechanize. The only change is the addition of the 'handler' parameter to the new method.
new
$obj->request($request);
This method receives a HTTP::Request as its only argument. It should return a HTTP::Response object. It should not follow redirects; LWP will take care of that.
This method must exist.
These method should return the current or default base for request URLs, e.g.
http://localhost.localdomain (the default default) http://myserver.com/myurl
These methods are optional. They are provided for handler objects that change their behavior based on some contextual information (e.g. %ENV). If this confuses you, you probably don't need them.
The results of these methods are cached after being called once, so if your object's return values might change during program execution, that will not be reflected properly in Test::WWW::Mechanize::Object. If this matters to anyone, send me a bug.
$obj->prepare_request($request);
Called before LWP and Mech do all their request object preparation.
Note: this method will be called once per request in a redirect chain.
This method is optional.
$obj->before_request($request);
Called after LWP and Mech do their request object preparation, but before $obj->request is called.
$obj->request
$obj->after_request($request, $response);
Called after the object has returned its response, but before LWP and Mech have done any post-processing.
$obj->on_redirect($request, $response);
Called after after_request each time the object returns a response that is a redirect (3XX status code).
after_request
You don't need to read this section unless you are interested in finding out how this module works, for subclassing or debugging. Most users will only need to read the method documentation above.
Overridden to note the 'handler' parameter.
Overridden (from WWW::Mechanize) to call the prepare_request hook.
prepare_request
Overridden (from LWP::UserAgent) to allow path-only URLs to be passed in, e.g.
$mech->get('/foo', ...);
Overridden (from LWP::UserAgent) to send requests to the handler object and to call the before_request hook.
before_request
Note: This ignores the $arg and $size arguments that LWP::UserAgent uses.
$arg
$size
Consider using URI::WithBase instead of rebasing URIs internally.
Test::WWW::Mechanize HTTP::Request HTTP::Response
Hans Dieter Pearcey, <hdp at cpan.org>
<hdp at cpan.org>
Please report any bugs or feature requests to bug-test-www-mechanize-object at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-WWW-Mechanize-Object. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-test-www-mechanize-object at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Test::WWW::Mechanize::Object
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Test-WWW-Mechanize-Object
CPAN Ratings
http://cpanratings.perl.org/d/Test-WWW-Mechanize-Object
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-WWW-Mechanize-Object
Search CPAN
http://search.cpan.org/dist/Test-WWW-Mechanize-Object
Thanks to Pobox.com, who sponsored the original development of this module.
Copyright 2006 Hans Dieter Pearcey, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Test::WWW::Mechanize::Object, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::WWW::Mechanize::Object
CPAN shell
perl -MCPAN -e shell install Test::WWW::Mechanize::Object
For more information on module installation, please visit the detailed CPAN module installation guide.