From 75b13e155a270ac3c93bd6df2a6ead6e2325ede3 Mon Sep 17 00:00:00 2001 From: Nishibayashi Takuji Date: Mon, 9 Jan 2012 14:37:36 +0900 Subject: [PATCH] =?UTF-8?q?FormValidator::Lite=E3=81=AE=E6=8B=A1=E5=BC=B5?= =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/validator.pl | 9 +++++++++ lib/Xpost/Validator.pm | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 config/validator.pl create mode 100644 lib/Xpost/Validator.pm diff --git a/config/validator.pl b/config/validator.pl new file mode 100644 index 0000000..6531608 --- /dev/null +++ b/config/validator.pl @@ -0,0 +1,9 @@ +use 5.014001; +use warnings; +use utf8; + +return +{ + param_message => { + email => 'メールアドレス', + }, +}; diff --git a/lib/Xpost/Validator.pm b/lib/Xpost/Validator.pm new file mode 100644 index 0000000..37dd04d --- /dev/null +++ b/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;