1 package WebPAC::Validate;
8 use base 'WebPAC::Common';
14 WebPAC::Validate - provide simple validation for records
22 our $VERSION = '0.01';
26 This module provide a simple way to validate your file against a simple
27 configuration file in following format:
29 # field 10 doesn't have any subfields
33 # field 200 have valid subfields a-g
35 # field 205 can have only subfield a
37 # while 210 can have a c or d
44 Create new validation object
46 my $validate = new WebPAC::Validate(
47 path => '/path/to/input/validate_file',
57 my $log = $self->_get_logger();
59 foreach my $p (qw/path/) {
60 $log->logconfess("need $p") unless ($self->{$p});
63 my $v_file = read_file( $self->{path} ) ||
64 $log->logdie("can't open validate path $self->{path}: $!");
69 foreach my $l (split(/[\n\r]+/, $v_file)) {
72 next if ($l =~ m/^#/);
77 my @d = split(/\s+/, $l);
79 my $fld = shift @d || $log->logdie("need field name in line $curr_line: $l");
82 $v->{$fld}->{ref} = 'ARRAY';
83 $v->{$fld}->{sf} = \@d;
85 $v->{$fld}->{ref} = '';
90 $log->debug("current validation rules: ", Dumper($v));
94 $self ? return $self : return undef;
99 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
101 =head1 COPYRIGHT & LICENSE
103 Copyright 2006 Dobrica Pavlinusic, All Rights Reserved.
105 This program is free software; you can redistribute it and/or modify it
106 under the same terms as Perl itself.
110 1; # End of WebPAC::Validate