Paper
o,o Google translator is great. it helps a lot. :)
http://translate.google.com/translate_t
I'm back HangZhou yesterday, I'll be stay here for 2-3 weeks I think. It's my last school time. :)
God bless me.
Perl is not the whole part of life. I know!
sub register : Global {
my ( $self, $c ) = @_;
$c->stash->{template} = 'user/register.html';
return unless ($c->req->param('process'));
# execute validation.
$c->form(
username => [[ 'DBIC_UNIQUE', $c->model('DBIC')->resultset('User'), 'username' ], qw/NOT_BLANK ASCII/, [qw/LENGTH 6 20/] ],
password => [qw/NOT_BLANK/, [qw/LENGTH 6 12/] ],
email => [qw/NOT_BLANK EMAIL_LOOSE/, [qw/LENGTH 5 20/], [ 'DBIC_UNIQUE', $c->model('DBIC')->resultset('User'), 'email' ] ],
{ passwords => ['password', 'confirm_password'] } => ['DUPLICATION'],
);
my $result = $c->form;
return if ( $result->has_error );$c->form 就是 Catalyst::Plugin::FormValidator::Simple 所提供的函数。DBIC_UNIQUE 检验机制是由 FormValidator::Simple::Plugin::DBIC::Unique 所提供的。主要用于检测表中的某一字段是否是 unique 独一的。我们所看到的如 NOT_BLANK LENGTH EMAIL_LOOSE DUPLICATION 都是 FormValidator::Simple 所自带的检测机制。还有 DATE 用于检测输入的日期是否合法,Regex 等。可以查阅 perldoc FormValidator::Simple<input type='text' name='username' length='12' />这种是比较愚笨的方法。我对这个也没用过几次,所以可能有好办法还没发现。perldoc 中提到了用 yml 来定义错误信息,或者这个比较可行,但是我不太喜欢,因为我在做多语言版本的 Forum
[% FOREACH type IN c.form.error('username') %]
[% IF type == 'DBIC_UNIQUE' %]
This username is used by another one.
[% END %]
....
[% END %]
[% IF c.form.error('username') %]
[% IF IF c.form.error('username', 'DBIC_UNIQUE') %]
This username is used by another one.
[% ELSE %]
username should be 6-20 chars.
[% END %]
[% END %]
use Date::Holidays::CN;
my ($year, $month, $day) = (localtime)[ 5, 4, 3 ];
$year += 1900;
$month += 1;
if (my $holidayname = is_cn_holiday( $year, $month, $day )) {
print $holidayname;
}