CGI::Application::Plugin::Phrasebook - A CGI::Application plugin for Data::Phrasebook
package MyCGIApp; use base 'CGI::Application'; use CGI::Application::Plugin::Phrasebook; sub cgiapp_prerun { my $self = shift; $self->config_phrasebook( class => 'Plain', loader => 'YAML', file => 'conf/my_phrasebook.yml', ); # ... do other stuff here ... } sub some_run_mode { my $self = shift; # grab the phrasebook instance # and fetch a keyword from it return $self->phrasebook->fetch('a_phrasebook_keyword'); }
This is a very simple plugin which provides access to an instance (or instances) of Data::Phrasebook inside your CGI::Application. I could have just stuffed this in with param, but this way is much nicer (and easier to type).
param
Given an array of arguments, this configures your Data::Phrasebook instance by simply passing any arguments onto Data::Phrasebook::new. It then stashes it into the CGI::Application instance.
Data::Phrasebook::new
If given a HASH reference, this will configure multiple Data::Phrasebook instances, one for each hash key. Here is an example, of how that would be used.
package MyCGIApp; use base 'CGI::Application'; use CGI::Application::Plugin::Phrasebook; sub cgiapp_prerun { my $self = shift; $self->config_phrasebook({ my_yaml_phrasebook => { class => 'Plain', loader => 'YAML', file => 'conf/my_phrasebook.yml', }, my_txt_phrasebook => { class => 'Plain', loader => 'Text', file => 'conf/my_phrasebook.txt', } }); # ... do other stuff here ... } sub some_run_mode { my $self = shift; return $self->phrasebook('my_yaml_phrasebook')->fetch('a_phrasebook_keyword'); } sub some_other_run_mode { my $self = shift; return $self->phrasebook('my_txt_phrasebook')->fetch('a_phrasebook_keyword'); }
You can also assign one of the hash keys to the string __DEFAULT__, and it will be used as the default phrasebook. But this behavior is optional.
__DEFAULT__
This will return the Data::Phrasebook instance, or undef if one has not yet been configured.
undef
If the plugin has been configured with multiple phrasebooks, you can specify the particular $phrasebook_name, if one is not specified, it will attempt to use the phrasebook called __DEFAULT__. If the phrasebook is not found, undef is returned.
$phrasebook_name
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.
Stevan Little <stevan@iinteractive.com>
Copyright 2006 by Infinity Interactive, Inc.
http://www.iinteractive.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install CGI::Application::Plugin::Phrasebook, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::Application::Plugin::Phrasebook
CPAN shell
perl -MCPAN -e shell install CGI::Application::Plugin::Phrasebook
For more information on module installation, please visit the detailed CPAN module installation guide.