The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

CGI::Ex::Recipes - A usage example for CGI::Ex::App!

SYNOPSIS

You may find in index.cgi the following:

    use CGI::Ex::Recipes;
    CGI::Ex::Recipes->new({
        conf_file => './conf/Recipes.conf',
    })->navigate;
    ...

DESCRIPTION

This small but relatively complete application was inspired by the examples given by Paul in his documentation. I decided to go further and experiment with the recomendations and features which the framework provides. You are encouraged to play with it and use it as a starting point for far more complex and customized applications.

Currently an SQLite database is used, but it should be easy to switch to whatever database you like. With very little change this application should be able to use MySQL as a backend.

If you need another databse you should know how to adapt the application.

REQUIREMENTS

Below are listed only packages which are not available in the standart Perl 5.8 distribution.

    CGI::Ex
    DBI
    DBD::SQLite
    SQL::Abstract
    YAML

DBI and DBD::SQLite come with ActivePerl.

INSTALL

    1. CPAN
        
    2. svn checkout https://bcc.svn.sourceforge.net:443/svnroot/bcc/trunk/recipes
    into some viewable by the server dir with option AllowOverride All

MOD_PERL

As of VERSION 0.6 this application should run out of the box under mod_perl 2. You just need to have "AllowOverride All" configuration option set for the directory where the application is installed. In the conf directory of the installed application you will find an example httpd.conf.

See also index.pl and perl/bin/startup.pl. Modify these files to meet your needs.

METHODS

Below are mentioned only methods which are overridden or not provided by CGI::Ex::App. Some of them or their modified variants, or parts of them will probably find their way up to the base module. Some of them did it already. This way they will become obsolete, but that is the point.

Others will stay here since they provide some specific for the application functionality. Writing more specific methods will meen you make your own application, reflecting your own buziness logic. This is good, because CGI::Ex::Recipes has done his job, by providing a codebase and starting point for you.

You are wellcome to give feedback if you think some functionality is enough common to go up straight to CGI::Ex::App.

Bellow are described overriten methods and methods defined in this package.

load_conf

Returns the value of $self->{load_conf} or 1(TRUE) by default.

pre_step

Returns 0 after executing $self->step_args().

allow_morph

Blindly returns the current value of allow_morph key in Recipes.conf, which should be interpreted as TRUE or FALSE.

path_info_map

This is just our example implementation, following recomendations in CGI::Ex::App.

skip

Ran at the beginning of the loop before prepare, info_complete, and finalize are called. If it returns true, nav_loop moves on to the next step (the current step is skipped).

In our case we bind it to the presence of the id parameter from the HTTP request. So if there is an id parameter it returns 0, otherwise 1.

get_pass_by_user

Returns the password for the given user. See the get_pass_by_user method of CGI::Ex::Auth for more information. Installed as a hook to the authentication object during the get_valid_auth method.

We get the password from the configuration file, which is enough for this demo, but you can do and SQL query for that purpose if you store your users' info in the database.

require_auth

Returns 0 or 1 depending on configuration for individual steps. This way we make only some steps to require authentication.

auth_args

Get authentication arguments from configuration if there is such and returns a hashref. The template_args are merged in also.

hash_base

The extra work done here is that we use Scalar::Util to weaken the reference to the main application which we pass for use from within the templates and template plugins. Without doing this we may have problems under persistent environments, such as mod_perl. This is very handy when you need to dynamically generate HTML or use the attached DBI object. See CGI::Ex::Recipes::Template::Menu, CGI::Ex::App.

base_dir_abs

See also CGI::Ex::App.

conf

Currently we use the old CGI::Ex::App::conf(), so the configuration file is found as it was before CGI::Ex 2.18. See also CGI::Ex::App.

ext_conf

We prefer conf file extension as default over pl. See also CGI::Ex::App.

pre_navigate

We have naive code here for logging out a user. See also CGI::Ex::App.

post_navigate

Currently I placed here a set of debug statements for fun. See also CGI::Ex::App.

step_args

hook/method - returns parsed arguments from $self-form->{step_info}> for the curent step. Initially called in pre_step. Not in CGI::Ex::App.

cache

Returns the cache object. See CGI::Ex::Recipes::Cache. Not in CGI::Ex::App.

UTILITY METHODS

These may go in another module - created specifically for this purpose. And ofcource there are plenty of modules providing beter implementation.

strftmime

now

AUTHOR

Красимир Беров, <k.berov at gmail.com>

BUGS

Probably many.

Please report any bugs or feature requests to k.berov@gmail.com by putting "CGI::Ex::Recipes" in the Subject line

ACKNOWLEDGEMENTS

    Larry Wall - for Perl
    
    Paul Seamons - for all his modules and especially for CGI::Ex didtro
    
    Anyone wich published anything on CPAN

COPYRIGHT & LICENSE

Copyright 2007-2012 Красимир Беров, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.