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

NAME

DemoGuestBook - Demo of CGI::Portable that implements a complete guest book with unlimited questions that also e-mails submissions to the website owner.

DEPENDENCIES

Perl Version

        5.004

Standard Modules

        Fcntl
        Symbol
        Net::SMTP 2.15 (earlier versions may work)

Nonstandard Modules

        CGI::Portable 0.50
        CGI::Portable::AppStatic 0.50
        CGI::MultiValuedHash 1.09
        HTML::FormTemplate 2.021

SYNOPSIS

Use Default Question

        #!/usr/bin/perl
        use strict;
        use warnings;

        require CGI::Portable;
        my $globals = CGI::Portable->new();

        use Cwd;
        $globals->file_path_root( cwd() );  # let us default to current working dir
        $globals->file_path_delimiter( $^O=~/Mac/i ? ":" : $^O=~/Win/i ? "\\" : "/" );

        require CGI::Portable::AdapterCGI;
        my $io = CGI::Portable::AdapterCGI->new();
        $io->fetch_user_input( $globals );

        $globals->default_application_title( 'Demo Guest Book' );
        $globals->default_maintainer_name( 'Tony Simons' );
        $globals->default_maintainer_email_address( 'tony@aardvark.net' );

        my %CONFIG = (
                fn_messages => 'guestbook_messages.txt',  # file in simple Boulder format
        );

        $globals->current_user_path_level( 1 );
        $globals->set_prefs( \%CONFIG );
        $globals->call_component( 'DemoGuestBook' );

        $io->send_user_output( $globals );

        1;

Use Custom Questions Defined Here

        my %CONFIG = (
                fn_messages => 'guestbook_messages.txt',  # file in simple Boulder format
                custom_fd => 1,
                field_defn => [
                        {
                                visible_title => "What's your age?",
                                type => 'textfield',
                                name => 'age',
                                is_required => 1,
                                validation_rule => '\d',
                                error_message => 'You must enter a number.',
                        }, {
                                visible_title => "What's the combination?",
                                type => 'checkbox_group',
                                name => 'words',
                                'values' => ['eenie', 'meenie', 'minie', 'moe'],
                                default => ['eenie', 'minie'],
                                labels => [qw( This That And Another )],
                        }, {
                                visible_title => "Who do you love?",
                                type => 'textfield',
                                name => 'name',
                        }, {
                                visible_title => "What's your favorite colour?",
                                type => 'popup_menu',
                                name => 'color',
                                'values' => ['red', 'green', 'blue', 'chartreuse'],
                        },
                ],
        );

Use Custom Questions Defined In Perl File

        my %CONFIG = (
                fn_messages => 'guestbook_messages.txt',  # file in simple Boulder format
                custom_fd => 1,
                field_defn => 'guestbook_questions.txt',  # do Perl code to make array ref
        );

Use Custom Questions Defined In simple Boulder File

        my %CONFIG = (
                fn_messages => 'guestbook_messages.txt',  # file in simple Boulder format
                custom_fd => 1,
                field_defn => 'guestbook_questions.txt',  # file in simple Boulder format
                fd_in_seqf => 1,
        );

Default To Signing Mode When Mode Not Specified In User Path

        my %CONFIG = (
                fn_messages => 'guestbook_messages.txt',
                sign_by_default => 1,
        );

Show Email Addresses In Message Listings (Default Is No Show)

        my %CONFIG = (
                fn_messages => 'guestbook_messages.txt',
                msg_list_show_email => 1,
        );

Customize Subject Of Your Emails

        my %CONFIG = (
                fn_messages => 'guestbook_messages.txt',
                email_subj => 'Your Visitor Has Left A Message',
        );

Customize Webpage Intro Text

        my %CONFIG = (
                fn_messages => 'guestbook_messages.txt',
                msg_new_title => 'Leave A Message',  # custom title for new messages
                msg_new_head => <<__endquote,   # custom heading for new messages
        <h1>Leave A Message</h1>
        <p>Please leave a message after the beep.  Answer the questions as faithfully
        and truthfully as you can, as we have a lie detector set up and any false 
        answers will be met with spam.</p>
        __endquote
                msg_list_title => 'Previous Reflections',  # custom title when reading
                msg_list_head => <<__endquote,   # custom heading for reading
        <h1>Wise Words That You Never Wrote</h1>
        <p>Here are the messages that previous visitors wrote.  Please stay awhile 
        and soak in the goodness.  You never know what you don't read.</p>
        __endquote
        );

DESCRIPTION

This Perl 5 object class is part of a demonstration of CGI::Portable in use. It is one of a set of "application components" that takes its settings and user input through CGI::Portable and uses that class to send its user output. This demo module set can be used together to implement a web site complete with static html pages, e-mail forms, guest books, segmented text document display, usage tracking, and url-forwarding. Of course, true to the intent of CGI::Portable, each of the modules in this demo set can be used independantly of the others.

SYNTAX

This class does not export any functions or methods, so you need to call them using object notation. This means using Class->function() for functions and $object->method() for methods. If you are inheriting this class for your own modules, then that often means something like $self->method().

PUBLIC FUNCTIONS AND METHODS

main( GLOBALS )

You invoke this method to run the application component that is encapsulated by this class. The required argument GLOBALS is an CGI::Portable object that you have previously configured to hold the instance settings and user input for this class. When this method returns then the encapsulated application will have finished and you can get its user output from the CGI::Portable object.

MODES THAT THIS MODULE OPERATES IN

DemoGuestBook has separate modes for signing the guest book and viewing the existing messages. The signing mode is accessed through the relative user path /sign. The reading mode is accessed through /read. Each of the modes is designed to present links going to the other mode. When the GuestBook is started up it defaults to the reading mode when no valid mode is specified. If the preference 'sign_by_default' is true then GuestBook defaults to the signing mode instead.

PREFERENCES HANDLED BY THIS MODULE

This POD is coming when I get the time to write it.

        custom_fd   # if true, we use a custom list of 
                # questions in the form; otherwise, we simply have a "message" field.
        field_defn  # instruc for how to make form fields
                # If array ref, this is taken literally as list of definitions.
                # Otherwise, this is name of a file containing the definitions.  
                # Field definitions are processed by HTML::FormTemplate, so please see 
                # its POD to know what options you have in your forms.
        fd_in_seqf  # if true, above file is of the 
                # format that is a simplified form of Boulder; else it is Perl code

        fn_messages  # file messages go in, if filed

        sign_by_default  # if true, we default to the signing screen; false is read
        
        msg_list_show_email  # if true, guest emails are shown, else they are not

        email_subj  # if set, use when sending e-mails

        msg_new_title  # custom title for new messages
        msg_new_head   # custom heading for new messages

        msg_list_title  # custom title when reading
        msg_list_head   # custom heading for reading

AUTHOR

Copyright (c) 1999-2004, Darren R. Duncan. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. However, I do request that this copyright information and credits remain attached to the file. If you modify this module and redistribute a changed version then please attach a note listing the modifications. This module is available "as-is" and the author can not be held accountable for any problems resulting from its use.

I am always interested in knowing how my work helps others, so if you put this module to use in any of your own products or services then I would appreciate (but not require) it if you send me the website url for said product or service, so I know who you are. Also, if you make non-proprietary changes to the module because it doesn't work the way you need, and you are willing to make these freely available, then please send me a copy so that I can roll desirable changes into the main release.

Address comments, suggestions, and bug reports to perl@DarrenDuncan.net.

SEE ALSO

perl(1), CGI::Portable, CGI::Portable::AppStatic, HTML::FormTemplate, CGI::MultiValuedHash, Net::SMTP, Fcntl, Symbol, Boulder, CGI::Portable::AdapterCGI.