App::ZofCMS::Plugin::DBIPPT - simple post-processor for results of DBI plugin queries
In your ZofCMS Template or Main Config file:
plugins => [ { DBI => 2000 }, # use of DBI plugin in this example is optional { DBIPPT => 3000 }, ], dbi => { # ..connection options are skipped for brevity dbi_get => { name => 'comments', sql => [ 'SELECT `comment`, `time` FROM `forum_comments`', { Slice => {} }, ], }, }, plug_dbippt => { key => 'comments', n => 'comment', # t => 'time' <---- by default, so we don't need to specify it }
The module is a plugin for App::ZofCMS that provides means to automatically post-process some most common (at least for me) post-processing needs when using App::ZofCMS::Plugin::DBI; namely, converting numerical output of time() with localtime() as well as changing new lines in regular text data into brs while escaping HTML Entities.
time()
localtime()
br
This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template
No, you don't have to use App::ZofCMS::Plugin::DBI, App::ZofCMS::Plugin::DBIPPT can be run on any piece of data that fits the description of <tmpl_loop>. The reason for the name and use of App::ZofCMS::Plugin::DBI in my examples here is because I only required doing such post-processing as this plugin when I used the DBI plugin.
App::ZofCMS::Plugin::DBIPPT
<tmpl_loop>
Ok, the name DBIPPT isn't the most clear choice for the name of the plugin, but when I first wrote out the full name I realized that the name alone defeats the purpose of the plugin - saving keystrokes - so I shortened it from DBIPostProcessLargeText to DBIPPT (the L was lost in "translation" as well). If you're suffering from memory problems, I guess one way to remember the name is "Please Process This".
DBIPPT
DBIPostProcessLargeText
L
plugins
plugins => [ { DBI => 2000 }, # example plugin that generates original data { DBIPPT => 3000 }, # higher run level (priority) ],
You need to include the plugin in the list of plugins to run. Make sure to set the priority right so DBIPPT would be run after any other plugins generate data for processing.
plug_dbippt
# run with all the defaults plug_dbippt => {}, # all arguments specified (shown are default values) plug_dbippt => { cell => 't', key => 'dbi', n => undef, t => 'time', } # derive config via a sub plug_dbippt => sub { my ( $t, $q, $config ) = @_; return { cell => 't', key => 'dbi', n => undef, t => 'time', }; }
Mandatory. Takes a hashref or a subref as a value. If subref is specified, its return value will be assigned to plug_dbippt as if it was already there. If sub returns an undef, then plugin will stop further processing. The @_ of the subref will contain (in that order): ZofCMS Tempalate hashref, query parameters hashref and App::ZofCMS::Config object. To run with all the defaults, use an empty hashref. The keys/values are as follows:
undef
@_
cell
plug_dbippt => { cell => 't', }
Optional. Specifies the first-level ZofCMS Template hashref key under which to look for data to convert. Defaults to: t
t
key
plug_dbippt => { key => 'dbi', } # or plug_dbippt => { key => [ qw/dbi dbi2 dbi3 etc/ ], } # or plug_dbippt => { key => sub { my ( $t, $q, $config ) = @_; return unless $q->{single}; return $q->{single} == 1 ? 'dbi' : [ qw/dbi dbi2 dbi3 etc/ ]; } }
Optional. Takes either a string, subref or an arrayref as a value. If the value is a subref, that subref will be executed and its return value will be assigned to key as if it was already there. The @_ will contain (in that order) ZofCMS Template hashref, query parameters hashref and App::ZofCMS::Config object. Passing (or returning from the sub) a string is the same as passing an arrayref with just that string in it.
Each element of the arrayref specifies the second-level key(s) inside cell first-level key value of which is an arrayref of either hashrefs or arrayrefs (i.e. typical output of App::ZofCMS::Plugin::DBI). Defaults to: dbi
dbi
n
plug_dbippt => { n => 'comments', } # or plug_dbippt => { n => [ 'comments', 'posts', 'messages' ], } # or plug_dbippt => { n => sub { my ( $t, $q, $config ) = @_; return unless $q->{single}; return $q->{single} == 1 ? 'comments' : [ qw/comments posts etc/ ]; } }
Optional. Pneumonic: new lines. Keys/indexes specified in n argument will have HTML entities escaped and new lines converted to <br> HTML elements.
<br>
Takes either a string, subref or an arrayref as a value. If the value is a subref, that subref will be executed and its return value will be assigned to n as if it was already there. The @_ will contain (in that order) ZofCMS Template hashref, query parameters hashref and App::ZofCMS::Config object. Passing (or returning from the sub) a string is the same as passing an arrayref with just that string in it. If set to undef no processing will be done for new lines.
Each element of the arrayref specifies either the keys of the hashrefs (for DBI plugin that would be when second element of sql arrayref is set to { Slice => {} }) or indexes of the arrayrefs (if they are arrayrefs). Defaults to: undef
sql
{ Slice => {} }
plug_dbippt => { t => undef, # no processing, as the default value is "time" } # or plug_dbippt => { t => [ qw/time post_time other_time/ ], } # or plug_dbippt => { t => sub { my ( $t, $q, $config ) = @_; return unless $q->{single}; return $q->{single} == 1 ? 'time' : [ qw/time post_time other_time/ ]; } }
Optional. Pneumonic: time. Keys/indexes specified in t argument are expected to point to either undef or empty string, in which case, no conversion will be done, or values of time() output and what will be done is scalar localtime($v) (where $v) is the original value) run on them and the return is assigned back to the original. In other words, they will be converted from time to localtime.
scalar localtime($v)
$v
time
localtime
Takes either a string, subref or an arrayref as a value. If the value is a subref, that subref will be executed and its return value will be assigned to t as if it was already there. The @_ will contain (in that order) ZofCMS Template hashref, query parameters hashref and App::ZofCMS::Config object. Passing (or returning from the sub) a string is the same as passing an arrayref with just that string in it. If set to undef no processing will be done.
Each element of the arrayref specifies either the keys of the hashrefs (for DBI plugin that would be when second element of sql arrayref is set to { Slice => {} }) or indexes of the arrayrefs (if they are arrayrefs). Defaults to: time
'Zoffix, <'zoffix at cpan.org'> (http://haslayout.net/, http://zoffix.com/, http://zofdesign.com/)
<'zoffix at cpan.org'>
Please report any bugs or feature requests to bug-app-zofcms-plugin-dbippt at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-ZofCMS-Plugin-DBIPPT. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-app-zofcms-plugin-dbippt at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc App::ZofCMS::Plugin::DBIPPT
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-ZofCMS-Plugin-DBIPPT
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/App-ZofCMS-Plugin-DBIPPT
CPAN Ratings
http://cpanratings.perl.org/d/App-ZofCMS-Plugin-DBIPPT
Search CPAN
http://search.cpan.org/dist/App-ZofCMS-Plugin-DBIPPT/
Copyright 2009 'Zoffix, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install App::ZofCMS::Plugin::DBIPPT, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::ZofCMS::Plugin::DBIPPT
CPAN shell
perl -MCPAN -e shell install App::ZofCMS::Plugin::DBIPPT
For more information on module installation, please visit the detailed CPAN module installation guide.