App-ZofCMS
view release on metacpan or search on metacpan
lib/App/ZofCMS/Plugin/DBIPPT.pm view on Meta::CPAN
=head1 NAME
App::ZofCMS::Plugin::DBIPPT - simple post-processor for results of DBI plugin queries
=head1 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
}
=head1 DESCRIPTION
The module is a plugin for L<App::ZofCMS> that provides
means to automatically post-process some most common (at least for me)
post-processing needs when using L<App::ZofCMS::Plugin::DBI>; namely,
converting numerical output of C<time()> with C<localtime()> as well
as changing new lines in regular text data into C<br>s while escaping
HTML Entities.
This documentation assumes you've read L<App::ZofCMS>,
L<App::ZofCMS::Config> and L<App::ZofCMS::Template>
=head1 DO I HAVE TO USE DBI PLUGIN?
No, you don't have to use L<App::ZofCMS::Plugin::DBI>,
C<App::ZofCMS::Plugin::DBIPPT> can be run on any piece of data
that fits the description of C<< <tmpl_loop> >>. The reason for the
name and use of L<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.
=head1 WTF IS PPT?
Ok, the name C<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 C<DBIPostProcessLargeText> to C<DBIPPT> (the C<L>
was lost in "translation" as well). If you're suffering from memory
problems, I guess one way to remember the name is "B<P>lease B<Process>
B<This>".
=head1 FIRST-LEVEL ZofCMS TEMPLATE AND MAIN CONFIG FILE KEYS
=head2 C<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 C<DBIPPT> would be run after
any other plugins generate data for processing.
=head2 C<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',
};
}
B<Mandatory>. Takes a hashref or a subref as a value. If subref is specified,
its return value will be assigned to C<plug_dbippt> as if it was already there. If sub returns
an C<undef>, then plugin will stop further processing. The C<@_> of the subref will
contain (in that order): ZofCMS Tempalate hashref, query parameters hashref and
L<App::ZofCMS::Config> object. To run with all the defaults,
use an empty hashref. The keys/values are as follows:
=head3 C<cell>
plug_dbippt => {
cell => 't',
}
B<Optional>. Specifies the first-level ZofCMS Template hashref key
under which to look for data to convert. B<Defaults to:> C<t>
=head3 C<key>
plug_dbippt => {
key => 'dbi',
}
( run in 0.619 second using v1.01-cache-2.11-cpan-39bf76dae61 )