From 53471501a94ee9c168b218c64d0eeecebe3684a7 Mon Sep 17 00:00:00 2001 From: Jens Rehsack Date: Fri, 10 Aug 2012 14:27:44 +0200 Subject: [PATCH] improving doc part3 including some fixes found during code review while documenting --- lib/Config/Any/WTScript.pm | 12 +++++------ lib/WWW/Mechanize/Script/Plugin/ContentSizeTest.pm | 22 ++++++++++++++++++-- lib/WWW/Mechanize/Script/Plugin/RegexMatchTest.pm | 21 +++++++++++++++++++ .../Mechanize/Script/Plugin/ResponseTimeTest.pm | 24 +++++++++++++++++++--- lib/WWW/Mechanize/Script/Plugin/StatusTest.pm | 19 ++++++++++++++++- lib/WWW/Mechanize/Script/Plugin/TextMatchTest.pm | 21 +++++++++++++++++++ 6 files changed, 107 insertions(+), 12 deletions(-) diff --git a/lib/Config/Any/WTScript.pm b/lib/Config/Any/WTScript.pm index c7bfc47..5c2ed4f 100644 --- a/lib/Config/Any/WTScript.pm +++ b/lib/Config/Any/WTScript.pm @@ -139,7 +139,7 @@ MSG return \@configs; } -sub eval_in_playground +sub _eval_in_playground { my $code = shift; @@ -153,11 +153,11 @@ $code CODE } -sub make_sub_in_playground +sub _make_sub_in_playground { my $code = shift; - return eval_in_playground("sub { local \$^W; $code }"); + return _eval_in_playground("sub { local \$^W; $code }"); } sub _parse @@ -360,7 +360,7 @@ sub _parse_scalar { # variable interpolation impossible - just evalute string # to get rid of escape chars - my $ret = eval_in_playground($extracted); + my $ret = _eval_in_playground($extracted); chomp $@; die "Eval error\n$@\n" if $@; @@ -371,7 +371,7 @@ sub _parse_scalar { # variable interpolation possible - evaluate as subroutine # which will be used as callback - my $ret = make_sub_in_playground($extracted); + my $ret = _make_sub_in_playground($extracted); chomp $@; die "Eval error\n$@\n" if $@; @@ -386,7 +386,7 @@ sub _parse_scalar die "Missing right curly bracket\n" if $extracted eq ''; - my $ret = make_sub_in_playground($extracted); + my $ret = _make_sub_in_playground($extracted); chomp $@; die "Eval error\n$@\n" if $@; diff --git a/lib/WWW/Mechanize/Script/Plugin/ContentSizeTest.pm b/lib/WWW/Mechanize/Script/Plugin/ContentSizeTest.pm index 5e72a98..8d84585 100644 --- a/lib/WWW/Mechanize/Script/Plugin/ContentSizeTest.pm +++ b/lib/WWW/Mechanize/Script/Plugin/ContentSizeTest.pm @@ -11,11 +11,29 @@ our $VERSION = '0.001_003'; use 5.014; +=method check_value_names() + +Returns qw(min_bytes max_bytes) + +=cut + sub check_value_names { return qw(min_bytes max_bytes); } +=method check_response(\%check,$mech) + +Proves whether I is greater than length of received content +(and accumulate I into I<$code> when true) or +I is lower than length of received content (and accumulate +I into I<$code> when true). + +Return the accumulated I<$code> and appropriate constructed message, if +any coparisation failed. + +=cut + sub check_response { my ( $self, $check, $mech ) = @_; @@ -23,8 +41,8 @@ sub check_response my $code = 0; my $msg; - my $min_bytes = $self->get_check_value( $check, "min_bytes" ); - my $max_bytes = $self->get_check_value( $check, "max_bytes" ); + my $min_bytes = 0 + $self->get_check_value( $check, "min_bytes" ); + my $max_bytes = 0 + $self->get_check_value( $check, "max_bytes" ); my $content_len = length $mech->response()->content(); if ( defined($min_bytes) and $min_bytes > $content_len ) diff --git a/lib/WWW/Mechanize/Script/Plugin/RegexMatchTest.pm b/lib/WWW/Mechanize/Script/Plugin/RegexMatchTest.pm index 54dcd3a..029eb88 100644 --- a/lib/WWW/Mechanize/Script/Plugin/RegexMatchTest.pm +++ b/lib/WWW/Mechanize/Script/Plugin/RegexMatchTest.pm @@ -13,11 +13,32 @@ our $VERSION = '0.001_003'; use 5.014; +=method check_value_names() + +Returns qw(regex_forbid regex_require). + +=cut + sub check_value_names { return qw(regex_forbid regex_require); } +=method check_response(\%check,$mech) + +This method checks whether any line of I matches against +received content (and accumulates I into I<$code> when +match) or any line of I doesn't match against content +(and accumulates I into I<$code> unless match). + +In case of an HTML response, the received content is rendered into plain +text before searching for matches. + +Return the accumulated I<$code> and appropriate constructed message, if +any match approval failed. + +=cut + sub check_response { my ( $self, $check, $mech ) = @_; diff --git a/lib/WWW/Mechanize/Script/Plugin/ResponseTimeTest.pm b/lib/WWW/Mechanize/Script/Plugin/ResponseTimeTest.pm index 2714a6b..67b94c4 100644 --- a/lib/WWW/Mechanize/Script/Plugin/ResponseTimeTest.pm +++ b/lib/WWW/Mechanize/Script/Plugin/ResponseTimeTest.pm @@ -11,11 +11,29 @@ our $VERSION = '0.001_003'; use 5.014; +=method check_value_names() + +Returns qw(min_elapsed_time max_elapsed_time) + +=cut + sub check_value_names { return qw(min_elapsed_time max_elapsed_time); } +=method check_response(\%check,$mech) + +Proves whether I is greater than C +(and accumulate I into I<$code> when true) or +I is lower than C (and accumulate +I into I<$code> when true). + +Return the accumulated I<$code> and appropriate constructed message, if +any coparisation failed. + +=cut + sub check_response { my ( $self, $check, $mech ) = @_; @@ -23,9 +41,9 @@ sub check_response my $code = 0; my $msg; - my $min_time = $self->get_check_value( $check, "min_elapsed_time" ); - my $max_time = $self->get_check_value( $check, "max_elapsed_time" ); - my $total_time = $mech->client_elapsed_time(); + my $min_time = 0 + $self->get_check_value( $check, "min_elapsed_time" ); + my $max_time = 0 + $self->get_check_value( $check, "max_elapsed_time" ); + my $total_time = 0 + $mech->client_elapsed_time(); if ( defined($min_time) and $min_time > $total_time ) { diff --git a/lib/WWW/Mechanize/Script/Plugin/StatusTest.pm b/lib/WWW/Mechanize/Script/Plugin/StatusTest.pm index 9536edf..294bc19 100644 --- a/lib/WWW/Mechanize/Script/Plugin/StatusTest.pm +++ b/lib/WWW/Mechanize/Script/Plugin/StatusTest.pm @@ -11,16 +11,33 @@ our $VERSION = '0.001_003'; use 5.014; +=method check_value_names() + +Returns qw(response). + +=cut + sub check_value_names { return qw(response); } +=method check_response(\%check,$mech) + +This methods proves whether the HTTP status code of the response matches the +value configured in I and accumulates I into I<$code> +when not. + +Return the accumulated I<$code> and appropriate constructed message, if +coparisation failed. + +=cut + sub check_response { my ( $self, $check, $mech ) = @_; - my $response_code = $self->get_check_value( $check, "response" ); + my $response_code = 0 + $self->get_check_value( $check, "response" ); if ( $response_code != $mech->status() ) { diff --git a/lib/WWW/Mechanize/Script/Plugin/TextMatchTest.pm b/lib/WWW/Mechanize/Script/Plugin/TextMatchTest.pm index 6025abe..5b05ad4 100644 --- a/lib/WWW/Mechanize/Script/Plugin/TextMatchTest.pm +++ b/lib/WWW/Mechanize/Script/Plugin/TextMatchTest.pm @@ -13,11 +13,32 @@ our $VERSION = '0.001_003'; use 5.014; +=method check_value_names() + +Returns qw(text_forbid text_require). + +=cut + sub check_value_names { return qw(text_forbid text_require); } +=method check_response(\%check,$mech) + +This method checks whether any line of I is found in received +content (and accumulates I into I<$code> when found) or +any line of I missing in content (and accumulates +I into I<$code> when missing). + +In case of an HTML response, the received content is rendered into plain +text before searching for matches. + +Return the accumulated I<$code> and appropriate constructed message, if +any match approval failed. + +=cut + sub check_response { my ( $self, $check, $mech ) = @_; -- 2.11.4.GIT