App::ZofCMS::Plugin::Debug::Dumper - small debugging plugin that Data::Dumper::Dumper()s interesting portions into {t}


App-ZofCMS-Plugin-Debug-Dumper documentation Contained in the App-ZofCMS-Plugin-Debug-Dumper distribution.

Index


Code Index:

NAME

Top

App::ZofCMS::Plugin::Debug::Dumper - small debugging plugin that Data::Dumper::Dumper()s interesting portions into {t}

SYNOPSIS

Top

In your Main Config file or ZofCMS Template:

    plugins => [ qw/Debug::Dumper/ ],

In your HTML::Template template:

    Dump of {t} key: <tmpl_var name="dumper_tt">
    Dump of {d} key: <tmpl_var name="dumper_td">
    Dump of ZofCMS template: <tmpl_var name="dumper_t">
    Dump of query: <tmpl_var name="dumper_q">
    Dump of main config: <tmpl_var name="dumper_c">

DESCRIPTION

Top

The module is a small debugging plugin for App::ZofCMS. It uses Data::Dumper to make dumps of 5 things and sticks them into {t} ZofCMS template key so you could display the dumps in your HTML::Template template for debugging purposes.

This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template

MAIN CONFIG FILE OR ZofCMS TEMPLATE

Top

plugins

    plugins => [ qw/Debug::Dumper/ ],

    plugins => [ { UserLogin => 100 }, { 'Debug::Dumper' => 200 } ],

You need to add the plugin to the list of plugins to execute (duh!). By setting the priority of the plugin you can make dumps before or after some plugins executed.

plug_dumper

    plug_dumper => {
        t_prefix    => 'dumper_',
        use_qq      => 1,
        pre         => 1,
        escape_html => 1,
        line_length => 80,
    },

The plugin takes configuration via plug_dumper first-level key that can be either in ZofCMS template or Main Config file, same keys set in ZofCMS template will override those keys set in Main Config file. As opposed to many ZofCMS plugins, App::ZofCMS::Plugin::Debug::Dumper will still execute even if the plug_dumper key is not set to anything.

The plug_dumper key takes a hashref as a value. Possible keys/values of that hashref are as follows:

t_prefix

    { t_prefix => 'dumper_', }

Optional. The t_prefix specifies the string to use to prefix the names of the HTML::Template variables generated by the plugin in {t} ZofCMS Template key. See HTML::Template VARIABLES section below for more information. Defaults to: dumper_ ( note the underscore at the end)

use_qq

    { use_qq => 1, }

Optional. Can be set to either true or false values. When set to a true value, the plugin will set $Data::Dumper::Useqq to 1 before making the dumps, this will basically make, e.g. "\n"s instead of generating real new lines in output. See Data::Dumper for more information. Defaults to: 1

pre

    { pre => 1, }

Optional. Can be set to either true or false values. When set to a true value the plugin will wrap all the generated dumps into HTML <pre></pre> tags. Defaults to: 1

escape_html

    { escape_html => 1, }

Optional. Can be set to either true or false values. When set to a true value the plugin will escape HTML code in the dumps. Defaults to: 1

line_length

    { line_length => 150, }

Optional. The line_length key takes a positive integer as a value. This value will specify the maximum length of each line in generated dumps. Strictly speaking it will stick a \n after every line_length characters that are not \n. Special value or 0 will disable line length feature. Defaults to: 150

HTML::Template VARIABLES

Top

The plugin will stick the generated dumps in the {t} ZofCMS template special key; that means that you can dump them out in your HTML::Template templates with <tmpl_var name"">s. The following five variables are available so far:

    Dump of {t} key: <tmpl_var name="dumper_tt">
    Dump of {d} key: <tmpl_var name="dumper_td">
    Dump of ZofCMS template: <tmpl_var name="dumper_t">
    Dump of query: <tmpl_var name="dumper_q">
    Dump of main config: <tmpl_var name="dumper_c">

The {t} and {d} keys refer to special keys in ZofCMS Templates. The query is the hashref of query parameters passed to the script and main config is your Main Config file hashref. The dumper_ prefix in the <tmpl_var name="">s above is the t_prefix that you can set in plug_dumper configuration key (explained way above). In other words, in your main config file or ZofCMS template you can set: plug_dumper => { t_prefix => '_' } and in HTML::Template templates you'd then use <tmpl_var name="_tt">, <tmpl_var name="_q">, etc.

The names are generated by using $t_prefix . $name, where $t_prefix is t_prefix set in plug_dumper and $name is one of the "variable names" that are as follows:

tt

    <tmpl_var name="dumper_tt">

The dump of {t} ZofCMS template special key. Mnemonic: template {t} key.

td

    <tmpl_var name="dumper_td">

The dump of {d} ZofCMS template special key. Mnemonic: template {d} key.

t

    <tmpl_var name="dumper_t">

The dump of entire ZofCMS template hashref. Mnemonic: template.

q

    <tmpl_var name="dumper_q">

The dump of query parameters as a hashref, in parameter/value way. Mnemonic: query.

c

    <tmpl_var name="dumper_c">

The dump of your Main Config file hashref. Mnemonic: config.

SPECIAL NOTES

Top

Note that all properly behaving plugins will remove their config data from ZofCMS templates and Main Config files, that list includes this plugin as well, therefore when dumping the ZofCMS template (<tmpl_var name="dumper_t">) after the plugins were executed, you will not see the configuration for those plugins that you wrote.

SEE ALSO

Top

Data::Dumper

AUTHOR

Top

'Zoffix, <'zoffix at cpan.org'> (http://zoffix.com/, http://haslayout.net/, http://zofdesign.com/)

BUGS

Top

Please report any bugs or feature requests to bug-app-zofcms-plugin-debug-dumper at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-ZofCMS-Plugin-Debug-Dumper. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc App::ZofCMS::Plugin::Debug::Dumper

You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-ZofCMS-Plugin-Debug-Dumper

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/App-ZofCMS-Plugin-Debug-Dumper

* CPAN Ratings

http://cpanratings.perl.org/d/App-ZofCMS-Plugin-Debug-Dumper

* Search CPAN

http://search.cpan.org/dist/App-ZofCMS-Plugin-Debug-Dumper

COPYRIGHT & LICENSE

Top


App-ZofCMS-Plugin-Debug-Dumper documentation Contained in the App-ZofCMS-Plugin-Debug-Dumper distribution.

package App::ZofCMS::Plugin::Debug::Dumper;

use warnings;
use strict;

our $VERSION = '0.0102';
use Data::Dumper;
use HTML::Entities qw/encode_entities/;

sub new { bless {}, shift }

sub process {
    my ( $self, $template, $query, $config ) = @_;

    my %conf = (
        t_prefix => 'dumper_',
        use_qq   => 1,
        pre      => 1,
        escape_html => 1,
        line_length => 150,
        %{ delete $config->conf->{plug_dumper} || {} },
        %{ delete $template->{plug_dumper}     || {} },
    );

    if ( $conf{use_qq} ) {
        $Data::Dumper::Useqq = 1;
    }

    my $t_dump = Dumper $template;

    $template->{t}{ $conf{t_prefix} . 't' . $_ } = Dumper $template->{$_}
        for qw/t d/;

    $template->{t}{ $conf{t_prefix} . 't' } = $t_dump;
    $template->{t}{ $conf{t_prefix} . 'q' } = Dumper $query;
    $template->{t}{ $conf{t_prefix} . 'c' } = Dumper $config->conf;

    if ( $conf{line_length } ) {
        for ( qw/tt td t q c/ ) {
            $template->{t}{ $conf{t_prefix} . $_ } =~ s/(.{$conf{line_length}})(?!\n)/$1\n/g;
        }
    }

    if ( $conf{escape_html} ) {
        encode_entities $template->{t}{ $conf{t_prefix} . $_ }
            for qw/tt td t q c/;
    }

    if ( $conf{pre} ) {
        $template->{t}{ $conf{t_prefix} . $_ }
        = qq|<pre style="font-family: 'DejaVu Sans Mono', monotype;">|
            . $template->{t}{ $conf{t_prefix} . $_ } . q|</pre>|
            for qw/tt td t q c/;
    }

    return 1;
}

1;
__END__