X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-CGI-Ex;a=blobdiff_plain;f=samples%2Fapp%2Fapp1%2Flib%2FApp1%2FCustInfo.pm;fp=samples%2Fapp%2Fapp1%2Flib%2FApp1%2FCustInfo.pm;h=c164b0709218961ba0a3055181c3d0b6ab02fcfd;hp=0000000000000000000000000000000000000000;hb=ed00221d27dfab1e82ec2ea040ab4c399a91c545;hpb=0b04f67c06c1db11969096f07dfc7dbb23bf99ba diff --git a/samples/app/app1/lib/App1/CustInfo.pm b/samples/app/app1/lib/App1/CustInfo.pm new file mode 100644 index 0000000..c164b07 --- /dev/null +++ b/samples/app/app1/lib/App1/CustInfo.pm @@ -0,0 +1,71 @@ +package App1::CustInfo; + +=head1 NAME + +App1::CustInfo - enter user info and verify it + +=cut + +use strict; +use warnings; +use base qw(App1); +use CGI::Ex::Dump qw(debug); + +sub hash_swap { + my $self = shift; + return { + countries => $self->_countries, + }; +} + +sub hash_fill { + return if shift->ready_validate; + return {country => 'US'}; +} + +sub hash_validation { + my $self = shift; + return { + 'group no_alert' => 1, + 'group no_confirm' => 1, + 'group onevent' => [qw(change blur submit)], + first_name => { + required => 1, + max_len => 50, + custom => sub { my ($key, $val) = @_; $val ne 'Matt' }, + custom_error => 'Too many people named Matt - please use a different first name', + }, + last_name => { + required => 1, + max_len => 50, + min_len => 2, + }, + password => { + required => 1, + max_len => 15, + match => 'm/[a-z]/i', + match_error => 'Password must contain a letter', + match2 => 'm/[0-9]/', + match2_error => 'Password must contain a number', + }, + password2 => { + equals => 'password', + }, + country => { + required => 1, + custom => sub { my ($key, $val) = @_; $self->_countries->{$val} }, + custom_error => "Please pick from the list of valid countries", + } + }; +} + +sub _countries { + # this is better off in a database + return { + US => "United States", + CA => "Canada", + MX => "Mexico", + }; +} + +1;