X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-CGI-Ex;a=blobdiff_plain;f=lib%2FCGI%2FEx%2FApp.pod;fp=lib%2FCGI%2FEx%2FApp.pod;h=8280b95882c65d716cce73da1d0a9a133394bbfc;hp=e0a539f5a3faf45ca9df9a55cfa210f3daef0406;hb=6c57b3331d84010b9e2031f8e3c8937c3117e8fc;hpb=f30b8252fcf71659a2fd3b5895e009ff8e39299d diff --git a/lib/CGI/Ex/App.pod b/lib/CGI/Ex/App.pod index e0a539f..8280b95 100644 --- a/lib/CGI/Ex/App.pod +++ b/lib/CGI/Ex/App.pod @@ -4,6 +4,10 @@ CGI::Ex::App - Anti-framework application framework. =head1 SYNOPSIS +A basic example: + + -------- File: /cgi-bin/my_cgi -------- + #!/usr/bin/perl -w use strict; @@ -13,10 +17,123 @@ CGI::Ex::App - Anti-framework application framework. exit; sub main_file_print { - return \ "Hello World"; + return \ "Hello World!"; + } + +Well, you should put your content in an external file... + + -------- File: /cgi-bin/my_cgi -------- + + #!/usr/bin/perl -w + + use strict; + use base qw(CGI::Ex::App); + + __PACKAGE__->navigate; + + sub base_dir_abs { '/var/www/templates' } + + + -------- File: /var/www/templates/my_cgi/main.html -------- + + Hello World! + +How about if we want to add substitutions... + + -------- File: /cgi-bin/my_cgi -------- + + #!/usr/bin/perl -w + + use strict; + use base qw(CGI::Ex::App); + + __PACKAGE__->navigate; + + sub base_dir_abs { '/var/www/templates' } + + sub main_hash_swap { + my $self = shift; + return { + greeting => 'Hello', + date => sub { scalar localtime }, + }; } -There is a longer "SYNOPSIS" after the process flow discussion. + + -------- File: /var/www/templates/my_cgi/main.html -------- + + [% greeting %] World! ([% date %]) + + +How about a form with validation (inluding javascript validation)... + + -------- File: /cgi-bin/my_cgi -------- + + #!/usr/bin/perl -w + + use strict; + use base qw(CGI::Ex::App); + + __PACKAGE__->navigate; + + sub base_dir_abs { '/var/www/templates' } + + sub main_hash_swap { {date => sub { scalar localtime }} } + + sub main_hash_fill { + return { + guess => 50, + }; + } + + sub main_hash_validation { + return { + guess => { + required => 1, + compare1 => '<= 100', + compare1_error => 'Please enter a value less than 101', + compare2 => '> 0', + compare2_error => 'Please enter a value greater than 0', + }, + }; + } + + sub main_finalize { + my $self = shift; + my $form = $self->form; + + $self->add_to_form({was_correct => ($form->{'guess'} == 23)}); + + return 0; # indicate to show the page without trying to move along + } + + + -------- File: /var/www/templates/my_cgi/main.html -------- + +

Hello World! ([% date %])

+ + [% IF was_correct %] + Correct! - The number was [% guess %].
+ [% ELSIF guess %] + Incorrect - The number was not [% guess %].
+ [% END %] + +
+ + Enter a number between 1 and 100:
+ [% guess_error %]
+ + +
+ + [% js_validation %] + + +There are infinite possibilities. There is a longer "SYNOPSIS" after +the process flow discussion and more examples near the end of this +document. It is interesting to note that there have been no databases +so far. CGI::Ex::App is Controller/Viewer that is somewhat Model +agnostic. =head1 DESCRIPTION