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
Fork this module on GitHub: https://github.com/zoffixznet/App-ZofCMS
To report bugs or request features, please use https://github.com/zoffixznet/App-ZofCMS/issues
If you can't access GitHub, you can email your request to bug-App-ZofCMS at rt.cpan.org
bug-App-ZofCMS at rt.cpan.org
Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)
You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.
LICENSE
To install App::ZofCMS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::ZofCMS
CPAN shell
perl -MCPAN -e shell install App::ZofCMS
For more information on module installation, please visit the detailed CPAN module installation guide.