WWW::Mechanize::Script - fetch websites and executes tests on the results
version 0.101
use WWW::Mechanize::Script; my $wms = WWW::Mechanize::Script->new(); $wms->run_script(@script); foreach my $test (@script) { $wms->run_test(%{$test}); }
Instantiates new WWW::Mechanize::Script object.
Configuration hash looks like:
defaults => { check => { # check defaults "code_cmp" : ">", "XXX_code" : 2, "ignore_case" : true, }, request => { # request defaults agent => { # LWP::UserAgent defaults agent => "Agent Adderly", accept_cookies => 'yes', # check LWP::UA param show_cookie => 'yes', # check LWP::UA param show_headers => 'yes', # check LWP::UA param send_cookie => 'yes', # check LWP::UA param }, }, }, script_dirs => [qw(/old/wtscripts /new/json_scripts)], summary => { template => "[% CODE_NAME; IF MESSAGES.size > 0 %] - [% MESSAGES.join(', '); END %]\n", target => "-" }, report => { template => "[% USE Dumper; Dumper.dump(RESPONSE) %]", target => "/tmp/@OPTS_FILE@.log", append => true }
Interpretes one of following config hash parameters
defaults => { check => { # check defaults code_cmp => ">", code_func => 'my ($cur,$new) = @_; return $cur > $new ? $cur : $new;' } }
When none of them are there, the sample in defaults->check->code_func is used.
The plugins() classmethod returns the names of configuration loading plugins as found by Module::Pluggable::Object.
plugins()
Returns the value for creating the request - either from current script or from defaults (defaults->request->$value_name).
defaults->request->$value_name
Generates the summary passing the template in the configuration of config->summary into Template::Toolkit.
config->summary
Following variables are provided for the template processing:
The accumulated return code of all executed checks computed via "_gen_code_compute".
Collected messages returned of all executed checks.
Plus all constants named in the config->templating->vars hash and those in config->summary->vars hash.
config->templating->vars
config->summary->vars
The output target is guessed from config->summary->target whereby the special target - is interpreted as stdout.
config->summary->target
stdout
Generates a report for a test within a script by passing the template in the configuration of config->report into Template::Toolkit.
config->report
Hash containing the following HTTP::Response items:
HTTP response code
Content of the response
The base URI for this response
Header keys/values as perl hash
Plus all constants named in the config->templating->vars hash and those in config->report->vars hash.
config->report->vars
When the config->summary->append flag is set and contains a true value, the output is appended to an existing target.
config->summary->append
Runs a script consisting of at least one test and generates a summary if configured. The code to accumulate the return codes from each test is taken from config->defaults->check as described in "_gen_code_compute".
config->defaults->check
Returns the accumulated return codes from all tests in the given script.
Runs one test and generates a report if configured (config->report).
The request is constructed from test->request whereby the part below test->request->agent is used to parametrize a new instance of WWW::Mechanize::Timed.
test->request
test->request->agent
All keys defined below test->request->agent are taken as setter of WWW::Mechanize::Timed or a inherited class.
If there is a hash defined at test->request->http_headers, those headers are passed along with the URI specified at test->request->uri to GET/POST or whatever you want to do (test->request->method).
test->request->http_headers
test->request->uri
test->request->method
Which checks are executed is defined below test->check. Each valid plugin below the WWW::Mechanize::Script::Plugin namespace is approved for relevance for the test (see "can_check" in WWW::Mechanize::Script::Plugin).
test->check
The test specification is enriched by the configuration in config->defaults using Hash::Merge with the LEFT_PRECEDENT ruleset. Please care about the ruleset especially when merging arrays is to expect.
config->defaults
The code to accumulate the return codes from each test is taken from test->check as described in "_gen_code_compute".
Returns the accumulated return codes from all checks in the given tests.
Please report any bugs or feature requests on the bugtracker website http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Mechanize-Script or by email to bug-www-mechanize-script@rt.cpan.org.
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Jens Rehsack <rehsack@cpan.org>
This software is copyright (c) 2014 by Jens Rehsack.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install WWW::Mechanize::Script, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Mechanize::Script
CPAN shell
perl -MCPAN -e shell install WWW::Mechanize::Script
For more information on module installation, please visit the detailed CPAN module installation guide.