view Lib/Form/Filter.pm @ 49:16ada169ca75

migrating to the Eclipse IDE
author wizard@linux-odin.local
date Fri, 26 Feb 2010 10:49:21 +0300
parents 03e58a454b20
children
line wrap: on
line source

package Form::Filter;
use strict;
use Common;
our @ISA = qw(Object);

use constant {
    CTX_SINGLE      => 1,   # значение поля
    CTX_SET         => 2,   # множество значений
    CTX_EXISTENT    => 4    # только существующие значения
};

BEGIN {
    DeclareProperty Name => ACCESS_READ;
    DeclareProperty Message => ACCESS_READ;
}

sub CTOR {
    my ($this,$name,$message) = @_;
    $this->{$Name} = $name or die new Exception('A filter name is required');
    $this->{$Message} = $message;
}

sub FormatMessage {
    my ($this,$object) = @_;
    
    (my $message = $object->Attributes->{$this->{$Name}} || $this->{$Message} || ($Common::Debug ? "$this->{$Name}: %name%" : '')) =~ s{%(\w+(?:\.\w+)*)%}{
        my $value = $object->Attributes->{$1} || ($Common::Debug ? $object->Name.'.'.$1 : '');
    }ge;
    
    return $message;
}

package Form::FilterResult;
use Common;
our @ISA = qw(Object);

use constant {
    STATE_ERROR => 0,           # ошибочное значение
    STATE_SUCCESS => 1,         # значение корректное, можно продолжать выполнение
    STATE_SUCCESS_STOP => 2,    # значение корректное, выполнение остальных фильтров не требуется
    STATE_SUCCESS_STAY => 3     # значение корректное, выполнение данного фильтра более не требуется
};

BEGIN {
    DeclareProperty State => ACCESS_READ;
    DeclareProperty Message => ACCESS_READ;
    DeclareProperty Target => ACCESS_READ;
    DeclareProperty Container => ACCESS_READ;
}

sub CTOR {
    my $this = shift;
    $this->SUPER::CTOR(@_);
    
    UNIVERSAL::isa($this->{$Target},'Form::Item') or UNIVERSAL::isa($this->{$Container},'Form::Container') or die new Exception("Invalid Target or Container property") if $this->{$State} == STATE_ERROR;
}

sub Item {
    my $this = shift;
    
    return ref $this->{$Target} ?
        ($this->{$Target}->isa('Form::Item') ? $this->{$Target} : $this->{$Container}->Item( $this->{$Target}->isMulti ? $this->{$Target}->Name . '0' : $this->{$Target}->Name ) )
        :
        ($this->{$Target});
}

1;