Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nishibayashi Takuji
committed
Jan 9, 2012
1 parent
3c5a2f1
commit 75b13e1
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use 5.014001; | ||
use warnings; | ||
use utf8; | ||
|
||
return +{ | ||
param_message => { | ||
email => 'メールアドレス', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use 5.014001; | ||
use warnings; | ||
package Xpost::Validator { | ||
use Amon2; | ||
use Amon2::Config::Simple; | ||
use FormValidator::Lite qw/ | ||
Date | ||
/; | ||
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; |