CGI-Ex

 view release on metacpan or  search on metacpan

lib/CGI/Ex/App.pod  view on Meta::CPAN

    -------- File: /cgi-bin/my_cgi --------

    #!/usr/bin/perl -w

    use strict;
    use base qw(CGI::Ex::App);

    __PACKAGE__->navigate;

    sub template_path { '/var/www/templates' }


    -------- File: /var/www/templates/my_cgi/main.html --------

    Hello World!

Adding substitutions...

    -------- File: /cgi-bin/my_cgi --------

    #!/usr/bin/perl -w

    use strict;
    use base qw(CGI::Ex::App);

    __PACKAGE__->navigate;

    sub template_path { '/var/www/templates' }

    sub main_hash_swap {
        my $self = shift;
        return {
            greeting => 'Hello',
            date     => sub { scalar localtime },
        };
    }


    -------- File: /var/www/templates/my_cgi/main.html --------

    [% greeting %] World! ([% date %])


Add forms and  validation (inluding javascript validation)...

    -------- File: /cgi-bin/my_cgi --------

    #!/usr/bin/perl -w

    use strict;
    use base qw(CGI::Ex::App);

    __PACKAGE__->navigate;

    sub template_path { '/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 --------

    <h2>Hello World! ([% date %])</h2>

    [% IF was_correct %]
       <b>Correct!</b> - The number was [% guess %].<br>
    [% ELSIF guess %]
       <b>Incorrect</b> - The number was not [% guess %].<br>
    [% END %]

    <form name="[% form_name %]" method="post">

    Enter a number between 1 and 100: <input type="text" name="guess"><br>
    <span id="guess_error" style="color:red">[% guess_error %]</span><br>

    <input type="submit">
    </form>

    [% 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.  It is very, very difficult to find a single database
abstraction that fits every model.  CGI::Ex::App is Controller/Viewer
that is somewhat Model agnostic and doesn't come with any default
database abstraction.

=head1 DESCRIPTION

Fill in the blanks and get a ready made web application.

This module is somewhat similar in spirit to CGI::Application,
CGI::Path, and CGI::Builder and any other "CGI framework."  As with
the others, CGI::Ex::App tries to do as much of the mundane things, in
a simple manner, without getting in the developer's way.  However,
there are various design patterns for CGI applications that
CGI::Ex::App handles for you that the other frameworks require you to
bring in extra support.  The entire CGI::Ex suite has been taylored to
work seamlessly together.  Your mileage in building applications may
vary.

If you build applications that submit user information, validate it,
re-display it, fill in forms, or separate logic into separate modules,
then this module may be for you.  If all you need is a dispatch
engine, then this still may be for you.  If all you want is to look at
user passed information, then this may still be for you.  If you like
writing bare metal code, this could still be for you.  If you don't want
to write any code, this module will help - but you still need to
provide your key actions and html.

One of the great benefits of CGI::Ex::App vs. Catalyst or Rails style
frameworks is that the model of CGI::Ex::App can be much more abstract.
And models often are abstract.

=head1 DEFAULT PROCESS FLOW

The following pseudo-code describes the process flow
of the CGI::Ex::App framework.  Several portions of the flow
are encapsulated in hooks which may be completely overridden to give
different flow.  All of the default actions are shown.  It may look
like a lot to follow, but if the process is broken down into the
discrete operations of step iteration, data validation, and template
printing the flow feels more natural.

=head2 navigate

The process starts off by calling ->navigate.

    navigate {
        eval {
            ->pre_navigate
            ->nav_loop



( run in 1.908 second using v1.01-cache-2.11-cpan-39bf76dae61 )