1 package WWW
::Mechanize
::Script
::Plugin
::ContentSizeTest
;
6 use parent
qw(WWW::Mechanize::Script::Plugin);
8 # ABSTRACT: check for size of received content
10 our $VERSION = '0.001_003';
14 =method check_value_names
()
16 Returns
qw(min_bytes max_bytes)
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
.
39 my ( $self, $check, $mech ) = @_;
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 );
61 $msg .= " and upper threshold ($max_bytes )";
65 $msg = "received $content_len bytes exceeds upper limit ($max_bytes)";
69 return ( $code, ( $msg ?
($msg) : () ) );