X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=samples%2Fcgi_ex_2.cgi;fp=samples%2Fcgi_ex_2.cgi;h=114b4da070b7bdb74aed0dae99078f0ea4aba820;hb=4eee158dce82376f2f37de29d91c53f60a24aebe;hp=0000000000000000000000000000000000000000;hpb=85070b46d0a93ddbeef07341421adb8389a55418;p=chaz%2Fp5-CGI-Ex diff --git a/samples/cgi_ex_2.cgi b/samples/cgi_ex_2.cgi new file mode 100755 index 0000000..114b4da --- /dev/null +++ b/samples/cgi_ex_2.cgi @@ -0,0 +1,150 @@ +#!/usr/bin/perl -w + +=head1 NAME + +cgi_ex_2.cgi - Rewrite of cgi_ex_1.cgi using CGI::Ex::App + +=cut + +if (__FILE__ eq $0) { + handler(); +} + +sub handler { + MyCGI->navigate; +} + +###----------------------------------------------------------------### + +package MyCGI; + +use strict; +use base CGI::Ex::App; +use CGI::Ex::Dump qw(debug); + +sub pre_loop { + my $self = shift; + my $path = shift; + if ($#$path == -1) { + push @$path, 'userinfo'; + } +} + +### this will work for both userinfo_hash_common and success_hash_common +sub hash_common { + my $self = shift; + return { + title => 'My Application', + script => $ENV{SCRIPT_NAME}, + color => ['#ccf', '#aaf'], + history => $self->history, + } +} + +sub ready_validate { + my $self = shift; + return $self->form->{processing} ? 1 : 0; +} + +###----------------------------------------------------------------### + +sub userinfo_hash_validation { + return { + 'group order' => ['username', 'password'], + username => { + required => 1, + min_len => 3, + max_len => 30, + match => 'm/^\w+$/', + # could probably all be done with match => 'm/^\w{3,30}$/' + }, + password => { + required => 1, + max_len => 20, + }, + password_verify => { + validate_if => 'password', + equals => 'password', + }, + }; +} + +sub userinfo_hash_swap { + my $self = shift; + my $hash = $self->form; + $hash->{form_name} = 'formfoo'; + $hash->{js_val} = $self->vob->generate_js($self->userinfo_hash_validation(), + $hash->{form_name}, + "$ENV{SCRIPT_NAME}/js"); + return $hash; +} + +###----------------------------------------------------------------### + +sub userinfo_file_print { + return \ qq { + + + [% title %] + + + +

Please Enter information

+ [% error_header %] +
+ +
+ + + + + + + + + + + + + + + + + + + +
Username: + + [% username_error %]
Password: + [% password_error %]
Password Verify: + [% password_verify_error %]
+ +
+ + [% js_validation %] + + + }; +} + +sub success_file_print { + return \ qq{ + + [% title %] + +

Success

+
+ print "I can now continue on with the rest of my script!"; + + + }; +} + + +1;