Jens Rehsack > WWW-Mechanize-Script > WWW::Mechanize::Script

Download:
WWW-Mechanize-Script-0.101.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.100   Source  

NAME ^

WWW::Mechanize::Script - fetch websites and executes tests on the results

VERSION ^

version 0.101

SYNOPSIS ^

  use WWW::Mechanize::Script;

  my $wms = WWW::Mechanize::Script->new();
  $wms->run_script(@script);

  foreach my $test (@script) {
    $wms->run_test(%{$test});
  }

METHODS ^

new(\%cfg)

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
    }

_gen_code_compute

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.

test_plugins( )

The plugins() classmethod returns the names of configuration loading plugins as found by Module::Pluggable::Object.

get_request_value($request,$value_name)

Returns the value for creating the request - either from current script or from defaults (defaults->request->$value_name).

summarize($code,@msgs)

Generates the summary passing the template in the configuration of config->summary into Template::Toolkit.

Following variables are provided for the template processing:

CODE

The accumulated return code of all executed checks computed via "_gen_code_compute".

MESSAGES

Collected messages returned of all executed checks.

Plus all constants named in the config->templating->vars hash and those in config->summary->vars hash.

The output target is guessed from config->summary->target whereby the special target - is interpreted as stdout.

gen_report($full_test, $mech, $code, @msgs)

Generates a report for a test within a script by passing the template in the configuration of config->report into Template::Toolkit.

Following variables are provided for the template processing:

CODE

The accumulated return code of all executed checks computed via "_gen_code_compute".

MESSAGES

Collected messages returned of all executed checks.

RESPONSE

Hash containing the following HTTP::Response items:

CODE

HTTP response code

CONTENT

Content of the response

BASE

The base URI for this response

HEADER

Header keys/values as perl hash

Plus all constants named in the config->templating->vars hash and those in config->report->vars hash.

The output target is guessed from config->summary->target whereby the special target - is interpreted as stdout.

When the config->summary->append flag is set and contains a true value, the output is appended to an existing target.

run_script(@script)

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

Returns the accumulated return codes from all tests in the given script.

run_test(\%test)

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.

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

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

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.

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.

BUGS ^

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.

AUTHOR ^

Jens Rehsack <rehsack@cpan.org>

COPYRIGHT AND LICENSE ^

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.

syntax highlighting: