CGI::Application::Plugin::Phrasebook - A CGI::Application plugin for Data::Phrasebook



NAME

CGI::Application::Plugin::Phrasebook - A CGI::Application plugin for Data::Phrasebook


SYNOPSIS


  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');
  }


DESCRIPTION

This is a very simple plugin which provides access to an instance (or instances) of the Data::Phrasebook manpage inside your the CGI::Application manpage. I could have just stuffed this in with param, but this way is much nicer (and easier to type).


METHODS

config_phrasebook (@phrasebook_args|\%multiple_phrasebooks)

Given an array of arguments, this configures your the Data::Phrasebook manpage instance by simply passing any arguments onto Data::Phrasebook::new. It then stashes it into the the CGI::Application manpage instance.

If given a HASH reference, this will configure multiple the Data::Phrasebook manpage 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 C<__DEFAULT__>, 
  and it will be used as the default phrasebook. But this behavior is 
  optional.
phrasebook (?$phrasebook_name)

This will return the the Data::Phrasebook manpage instance, or undef if one has not yet been configured.

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.


SEE ALSO

the Data::Phrasebook manpage
http://www.perl.com/pub/a/2002/10/22/phrasebook.html


BUGS

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.


AUTHOR

Stevan Little <stevan@iinteractive.com>


COPYRIGHT AND LICENSE

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.