NAME

Test::WWW::Mechanize::Object - run mech tests by making requests on an object

VERSION

Version 0.020

SYNOPSIS

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

DESCRIPTION

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.

METHODS

request

$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.

url_base

default_url_base

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.

prepare_request

$obj->prepare_request($request, $mech);

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.

before_request

$obj->before_request($request, $mech);

Called after LWP and Mech do their request object preparation, but before $obj->request is called.

Note: this method will be called once per request in a redirect chain.

after_request

$obj->after_request($request, $response, $mech);

Called after the object has returned its response, but before LWP and Mech have done any post-processing.

Note: this method will be called once per request in a redirect chain.

This method is optional.

on_redirect

$obj->on_redirect($request, $response, $mech);

Called after after_request each time the object returns a response that is a redirect (3XX status code).

This method is optional.

INTERNALS

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.

new

Overridden to note the 'handler' parameter.

_make_request

Overridden (from WWW::Mechanize) to call the prepare_request hook.

get

post

Overridden (from LWP::UserAgent) to allow path-only URLs to be passed in, e.g.

$mech->get('/foo', ...);

send_request

Overridden (from LWP::UserAgent) to send requests to the handler object and to call the before_request hook.

Note: This ignores the $arg and $size arguments that LWP::UserAgent uses.

TODO

Consider using URI::WithBase instead of rebasing URIs internally.

SEE ALSO

Test::WWW::Mechanize HTTP::Request HTTP::Response

AUTHOR

Hans Dieter Pearcey, <hdp at cpan.org>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Test::WWW::Mechanize::Object

You can also look for information at:

ACKNOWLEDGEMENTS

Thanks to Pobox.com, who sponsored the original development of this module.

COPYRIGHT & LICENSE

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.