File Coverage

blib/lib/Apache/Voodoo/Validate/Plugin.pm
Criterion Covered Total %
statement 23 34 67.6
branch 6 8 75.0
condition 3 3 100.0
subroutine 6 11 54.5
pod 0 9 0.0
total 38 65 58.4


line stmt bran cond sub pod time code
1             #####################################################################################
2             #
3             # Apache::Voodoo::Validate::Plugin
4             #
5             # Base class which all the data type plugins must inherit from in order to work
6             # correctly with A::V::Validate.
7             #
8             ####################################################################################
9             package Apache::Voodoo::Validate::Plugin;
10              
11             $VERSION = "3.0200";
12              
13 3     3   21 use strict;
  3         6  
  3         107  
14 3     3   17 use warnings;
  3         5  
  3         1423  
15              
16             sub new {
17 28     28 0 40 my $class = shift;
18 28         34 my $config = shift;
19              
20 28         41 my $self = {};
21 28         67 bless $self,$class;
22              
23              
24 28         106 $self->{'name'} = $config->{'id'};
25 28         48 $self->{'type'} = $config->{'type'};
26              
27             # grab the switches
28 28         46 foreach ("required","unique",'multiple') {
29 84 100       196 if ($config->{$_}) {
30 10 50       102 $self->{$_} = ($config->{$_})?1:0;
31             }
32             }
33              
34 28         89 my @e = $self->config($config);
35 28 100 100     139 if (!defined($self->{valid}) && defined($config->{valid})) {
36 3 50       9 if (ref($config->{valid}) ne "CODE") {
37 0         0 push(@e,"'valid' is not a subroutine reference");
38             }
39             else {
40 3         7 $self->{valid_sub} = $config->{valid};
41             }
42             }
43              
44 28         98 return $self,@e;
45             }
46              
47 71     71 0 322 sub valid_sub { return $_[0]->{valid_sub} }
48 0     0 0 0 sub type { return $_[0]->{type}; }
49 30     30 0 124 sub name { return $_[0]->{name}; }
50 78     78 0 695 sub required { return $_[0]->{required}; }
51 0     0 0   sub unique { return $_[0]->{unique}; }
52 0     0 0   sub multiple { return $_[0]->{multiple}; }
53              
54             sub config {
55 0     0 0   my $self = shift;
56 0           my $e = ref($self)." didn't override the config function as it should have";
57 0           warn $e;
58 0           return {},$e;
59             }
60              
61             sub valid {
62 0     0 0   my $self = shift;
63 0           warn ref($self)." didn't override the valid function as it should have";
64 0           return undef;
65             }
66              
67             1;
68              
69             ################################################################################
70             # Copyright (c) 2005-2010 Steven Edwards (maverick@smurfbane.org).
71             # All rights reserved.
72             #
73             # You may use and distribute Apache::Voodoo under the terms described in the
74             # LICENSE file include in this package. The summary is it's a legalese version
75             # of the Artistic License :)
76             #
77             ################################################################################