87dfa3bc12d7fc8cdf88b849116da597d711b161
[WWW-Mechanize-Script.git] / lib / WWW / Mechanize / Script / Plugin.pm
blob87dfa3bc12d7fc8cdf88b849116da597d711b161
1 package WWW::Mechanize::Script::Plugin;
3 use strict;
4 use warnings;
6 # ABSTRACT: plugin base class for check plugins
8 our $VERSION = '0.001_003';
10 use 5.014;
12 =method new()
14 Instantiates new WWW::Mechanize::Script::Plugin. This is an abstract class.
16 =cut
18 sub new
20 my ($class) = @_;
22 my $self = bless( {}, $class );
24 return $self;
27 =method get_check_value(\%check,$value_name)
29 Retrieves the value for I<$value_name> from the hash I<%check>.
31 =cut
33 sub get_check_value
35 my ( $self, $check, $value_name ) = @_;
37 $value_name or return;
39 return $check->{check}->{$value_name};
42 =method get_check_value_as_bool(\%check,$value_name)
44 Retrieves the value for I<$value_name> from the hash I<%check> and returns
45 true when it can be interpreted as a boolean value with true content
46 (any object is always returned as it is, (?:(?i)true|on|yes) evaluates to
47 I<true>, anything else to I<false>).
49 =cut
51 sub get_check_value_as_bool
53 my ( $self, $check, $value_name ) = @_;
55 $value_name or return;
57 my $val = $check->{check}->{$value_name};
59 defined($val) or return;
60 ref($val) and return $val;
61 if ( _STRING($val) )
63 $val =~ m/(?:true|on|yes)/i and return 1;
66 return 0;
69 =method can_check(\%check)
71 Proves whether this instance can check anything on the current run test.
72 Looks if any of the required L</check_value_names> are specified in the
73 check parameters of the current test.
75 =cut
77 sub can_check
79 my ( $self, $check ) = @_;
80 my $ok = 0;
82 my @value_names = $self->check_value_names();
83 foreach my $value_name (@value_names)
85 my $cv = $self->get_check_value( $check, $value_name );
86 $cv and $ok = 1 and last;
89 return $ok;
93 =method check_value_names()
95 Returns list of check values which are used to check the response.
97 Each I<value> has a I<value>C<_code> counterpart which is used to modify
98 the return value of L</check_response> when the check upon that value
99 fails.
101 =cut
103 sub check_value_names { ... }
105 =method check_response(\%check,$mech)
107 Checks the response based on test specifications. See individual plugins
108 for specific test information.
110 Returns the accumulated code for each failing check along with optional
111 messages containing details about each failure.
113 # no error
114 return (0);
115 # some error
116 return ($code,@messages);
117 # some error but no details
118 return ($code);
120 =cut
122 sub check_response { ... }