The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

CGI::Application::Plugin::PageLookup::Value - Manage values scattered across a website

VERSION

Version 1.0

DESCRIPTION

This module allows the management of template variable instantiation across a website. You can specialize a default value for a parameter (without requiring it to be used on every page) and override that value for specific pages. Or you can merely set the value for individual pages. This depends on CGI::Application::Plugin::PageLookup. For loops see CGI::Application::Plugin::PageLookup::Loop.

SYNOPSIS

In the template you can do things like <TMPL_VAR NAME="values.hope">, <TMPL_VAR NAME="values.faith"> and <TMPL_VAR NAME="values.charity">. You must register the "values" parameter as a CGI::Application::Plugin::PageLookup::Value object as follows:

    use CGI::Application;
    use CGI::Application::Plugin::PageLookup qw(:all);
    use CGI::Application::Plugin::PageLookup::Value;
    use HTML::Template::Pluggable;
    use HTML::Template::Plugin::Dot;

    sub cgiapp_init {
        my $self = shift;

        # pagelookup depends CGI::Application::DBH;
        $self->dbh_config(......); # whatever arguments are appropriate

        $self->html_tmpl_class('HTML::Template::Pluggable');

        $self->pagelookup_config(

                # load smart dot-notation objects
                objects =>
                (
                        # Register the 'values' parameter
                        values => 'CGI::Application::Plugin::PageLookup::Value,
                }
        );
    }


    ...

After that all that remains is to populate the cgiapp_values table with the appropriate values. Notice that the code does not need to know what comes after the dot in the templates. So if you want to set "values.hope" to "disappointment" in all English pages you would run

        INSERT INTO cgiapp_values (lang, param, value) VALUES ('en', 'hope', 'disappointment')

On the other hand if you wanted set "values.hope" to "a glimmer of light" on page 7 but "disappointment" everywhere else, then you would run

        INSERT INTO cgiapp_values (lang, param, value) VALUES ('en', 'hope', 'disappointment')
        INSERT INTO cgiapp_values (lang, internalId, param, value) VALUES ('en', 7, 'hope', 'a glimmer of light')
        

DATABASE

This module depends on only one extra table: cgiapp_values. The lang and internalId columns join against the cgiapp_table. However the internalId column can null, making the parameter available to all pages in the same language. The lang, internalId and param columns form the key of the table.

Table: cgiapp_values Field |Type |Null|Key |Default|Extra| -------------------------------------------------------------------------------------------------------- lang |varchar(2) |NO | |NULL | | internalId |unsigned numeric(10,0) |YES | |NULL | | param |varchar(20) |NO | |NULL | | value |text |NO | |NULL | |

FUNCTIONS

new

A constructor folowing the requirements set out in CGI::Application::Plugin::PageLookup.

can

We need to autoload methods so that the template writer can use variables without needing to know where the variables will be used. Thus 'can' must return a true value in all cases to avoid breaking HTML::Template::Plugin::Dot. Also 'can' is supposed to either return undef or a CODE ref. This seems the cleanest way of meeting all requirements.

AUTOLOAD

We need to autoload methods so that the template writer can use variables without needing to know where the variables will be used.

DESTRROY

We have to define DESTROY, because an autoloaded version would be bad.

AUTHOR

Nicholas Bamber, <nicholas at periapt.co.uk>

BUGS

Please report any bugs or feature requests to bug-cgi-application-plugin-pagelookup at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CGI-Application-Plugin-PageLookup. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

AUTOLOAD

AUTOLOAD is quite a fraught subject. There is probably no perfect solution. See http://www.perlmonks.org/?node_id=342804 for a sample of the issues.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc CGI::Application::Plugin::PageLookup::Value

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2009 Nicholas Bamber.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.