Mercurial > pub > Impl
comparison Lib/Form/Filter/Regexp.pm @ 0:03e58a454b20
Создан репозитарий
author | Sergey |
---|---|
date | Tue, 14 Jul 2009 12:54:37 +0400 |
parents | |
children | 16ada169ca75 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:03e58a454b20 |
---|---|
1 package Form::Filter::Regexp; | |
2 use strict; | |
3 use Common; | |
4 use Form::Filter; | |
5 use base qw(Form::Filter); | |
6 | |
7 BEGIN { | |
8 DeclareProperty Regexp => ACCESS_READ; | |
9 } | |
10 | |
11 sub CTOR { | |
12 my ($this,@args) = @_; | |
13 | |
14 $this->SUPER::CTOR(@args[0,1]); | |
15 | |
16 my $re = $args[2] or die new Exception('A regular expression is required'); | |
17 | |
18 $this->{$Regexp} = qr/$re/; | |
19 } | |
20 | |
21 sub SUPPORTED_CONTEXT { Form::Filter::CTX_SINGLE | Form::Filter::CTX_EXISTENT } | |
22 | |
23 sub Invoke { | |
24 my ($this,$object) = @_; | |
25 | |
26 if ($object->isa('Form::ValueItem')) { | |
27 my $re = $this->{$Regexp}; | |
28 if ($object->isEmpty or $object->Value =~ m/$re/) { | |
29 return new Form::FilterResult(State => Form::FilterResult::STATE_SUCCESS); | |
30 } else { | |
31 return new Form::FilterResult(Sate => Form::FilterResult::STATE_ERROR, Message => $this->FormatMessage($object), Target => $object ); | |
32 } | |
33 } else { | |
34 die new Exception('Only a value items can be verified against a regular expression'); | |
35 } | |
36 } | |
37 | |
38 1; |