NAME
App::ZofCMS::Plugin::DBIPPT - simple post-processor for results of DBI plugin queries
SYNOPSIS
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
}
DESCRIPTION
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 br
s while escaping HTML Entities.
This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template
DO I HAVE TO USE DBI PLUGIN?
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.
WTF IS PPT?
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".
FIRST-LEVEL ZofCMS TEMPLATE AND MAIN CONFIG FILE KEYS
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:
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
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
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.
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
t
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
.
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
REPOSITORY
Fork this module on GitHub: https://github.com/zoffixznet/App-ZofCMS
BUGS
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
AUTHOR
Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)
LICENSE
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.