bump version to 0.001_004
[WWW-Mechanize-Script.git] / lib / WWW / Mechanize / Script / Plugin / ContentSizeTest.pm
blob980b815264538fa2be44aa45a83074c29b00a9a9
1 package WWW::Mechanize::Script::Plugin::ContentSizeTest;
3 use strict;
4 use warnings;
6 use parent qw(WWW::Mechanize::Script::Plugin);
8 # ABSTRACT: check for size of received content
10 our $VERSION = '0.001_004';
12 use 5.014;
14 =method check_value_names()
16 Returns qw(min_bytes max_bytes)
18 =cut
20 sub check_value_names
22 return qw(min_bytes max_bytes);
25 =method check_response(\%check,$mech)
27 Proves whether I<min_bytes> is greater than length of received content
28 (and accumulate I<min_bytes_code> into I<$code> when true) or
29 I<max_bytes> is lower than length of received content (and accumulate
30 I<max_bytes_code> into I<$code> when true).
32 Return the accumulated I<$code> and appropriate constructed message, if
33 any coparisation failed.
35 =cut
37 sub check_response
39 my ( $self, $check, $mech ) = @_;
41 my $code = 0;
42 my $msg;
44 my $min_bytes = 0 + $self->get_check_value( $check, "min_bytes" );
45 my $max_bytes = 0 + $self->get_check_value( $check, "max_bytes" );
46 my $content_len = length $mech->response()->content();
48 if ( defined($min_bytes) and $min_bytes > $content_len )
50 my $err_code = $self->get_check_value( $check, "min_bytes_code" ) // 1;
51 $code = &{ $check->{compute_code} }( $code, $err_code );
52 $msg = "received $content_len bytes exceeds lower threshold ($min_bytes)";
55 if ( defined($max_bytes) and $max_bytes < $content_len )
57 my $err_code = $self->get_check_value( $check, "max_bytes_code" ) // 1;
58 $code = &{ $check->{compute_code} }( $code, $err_code );
59 if ($msg)
61 $msg .= " and upper threshold ($max_bytes )";
63 else
65 $msg = "received $content_len bytes exceeds upper limit ($max_bytes)";
69 return ( $code, ( $msg ? ($msg) : () ) );