]> Dogcows Code - chaz/p5-CGI-Ex/blobdiff - samples/app/app1/lib/App1/CustInfo.pm
CGI::Ex 2.24
[chaz/p5-CGI-Ex] / samples / app / app1 / lib / App1 / CustInfo.pm
diff --git a/samples/app/app1/lib/App1/CustInfo.pm b/samples/app/app1/lib/App1/CustInfo.pm
new file mode 100644 (file)
index 0000000..c164b07
--- /dev/null
@@ -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;
This page took 0.019842 seconds and 4 git commands to generate.