File: Result.pm

package info (click to toggle)
libformvalidator-simple-perl 0.29-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 412 kB
  • sloc: perl: 3,043; makefile: 4
file content (64 lines) | stat: -rw-r--r-- 1,462 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package FormValidator::Simple::Result;
use strict;
use base qw/Class::Accessor::Fast/;
use FormValidator::Simple::Constants;
use FormValidator::Simple::Exception;
use Tie::IxHash;

__PACKAGE__->mk_accessors(qw/name constraints data is_blank/);

sub new {
    my $class = shift;
    my $self  = bless { }, $class;
    $self->_init(@_);
    return $self;
}

sub _init {
    my ($self, $name) = @_; 
    my %constraints = ();
    tie (%constraints, 'Tie::IxHash');
    $self->name($name);
    $self->constraints(\%constraints);
    $self->data(q{});
    $self->is_blank( FALSE );
}

sub set {
    my ($self, $constraint, $result) = @_;
    $self->constraints->{$constraint} = $result;
}

sub is_valid {
    my $self   = shift;
    return FALSE if $self->is_blank;
    foreach my $result ( values %{ $self->constraints } ) {
        return FALSE unless $result;
    }
    return TRUE;
}

sub is_invalid {
    my $self = shift;
    return FALSE if $self->is_blank;
    foreach my $result ( values %{ $self->constraints } ) {
        return TRUE unless $result;
    }
    return FALSE;
}

sub is_valid_for {
    my ($self, $constraint) = @_;
    return TRUE unless exists $self->constraints->{$constraint};
    return $self->constraints->{$constraint} ? TRUE : FALSE;
}

sub is_invalid_for {
    my ($self, $constraint) = @_;
    return FALSE unless exists $self->constraints->{$constraint};
    return $self->constraints->{$constraint} ? FALSE : TRUE;
}

1;
__END__