Skip to content

Commit

Permalink
FormValidator::Liteの拡張クラス
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishibayashi Takuji committed Jan 9, 2012
1 parent 3c5a2f1 commit 75b13e1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
9 changes: 9 additions & 0 deletions config/validator.pl
@@ -0,0 +1,9 @@
use 5.014001;
use warnings;
use utf8;

return +{
param_message => {
email => 'メールアドレス',
},
};
46 changes: 46 additions & 0 deletions lib/Xpost/Validator.pm
@@ -0,0 +1,46 @@
use 5.014001;
use warnings;
package Xpost::Validator {
use Amon2;
use Amon2::Config::Simple;
use FormValidator::Lite qw/
Date
Email
/;
use parent qw/-norequire FormValidator::Lite/;


sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->load_function_message('ja');
$self->set_param_message(%{Amon2::Config::Simple->load(Amon2->context(), {env => 'validator'})->{param_message}});
return $self;
}

sub check {
my $self = shift;

my %args = @_;

$self->SUPER::check(@_);
return if $self->has_error;
$self->{valid_params} = {};
$self->{valid_params}->{$_} = 1 for (keys %args);
}



sub valid_data {
my $self = shift;

die "invalid request" if $self->has_error;

return {
map { $_ => $self->query->param($_) }
grep { defined $self->query->param($_) }
keys %{ $self->{valid_params} }
};
}
}
1;

0 comments on commit 75b13e1

Please sign in to comment.