> > I propose adding a DUMP directive.  ...
>
> I would just use the Dumper plugin for that.  Is that not sufficient?

Well, reading the rest of the proposal and comparing the output of the
two, I think that it isn't quite sufficient.  I'm not meaning to sound
harsh - but the Dumper plugin is good at spitting out data structures
only.  It has little utility beyond that.

  1) The Dumper plugin doesn't know the name of my variable.
     I would have to pass it {a => a} for it to spit out a name.
     It is very useful to see which variable is which.  The proposed
     output shows the variable name in question.

  2) The Dumper plugin (and any other plugin) doesn't know what line or
     what template/component I am in.  It is very, very useful to see
     what file and line I am in and on.  The debug_dirs configuration
     is a little overkill as it tells everything going on in a particular
     section.  Often I just want a quick note to see what part of the template
     I am in.  Multiple Dumper outputs tell me nothing.  The proposed DUMP
     output shows me plenty.

  3) The Dumper plugin (and any other plugin) can't access the entire stash.
     There isn't even a way for the stash to be passed in.  That is good
     - plugins shouldn't have that much access.  The proposed DUMP directive
     has all the access it needs.

  4) The Dumper plugin is clunky.  This is a matter of opinion - but I do not
     like writing:

     [% USE Dumper; Dumper.dump(foo) %]

     but I do like writing

     [% DUMP foo %]

     Again - this is my opinion.  I don't mean to disparage the Dumper plugin.
     It is a fine plugin and did the best that it could with what access
     it had.

So, I maintain my proposal.  If I don't hear a contrary vote, I'll most likely
prepare a patch to add it.

Paul

PS - for those interested in a comparison of output - here you go (it
is even more interesting when the DUMP statements are in nested templates:

#!/usr/bin/perl
my $file = <<"HERE";
Some text:
[% DUMP a %]
[% DUMP [b, c, 1+2] %]
[% DUMP '' %]
[% DUMP %]
HERE

CGI::Ex::Template->new->process(\$file, {
    a  => "A string",
    b  => {key1 => 'val1'},
    c  => [qw(foo bar baz)],
    _d => "Something hidden",
    e  => sub { die },
});

$file = <<"HERE";
Some text:
[% USE Dumper %]
[% Dumper.dump(a) %]
[% Dumper.dump([b, c, 1+2]) %]
[% Dumper.dump('') %]
[% Dumper.dump() %]
HERE

CGI::Ex::Template->new->process(\$file, {
    a  => "A string",
    b  => {key1 => 'val1'},
    c  => [qw(foo bar baz)],
    _d => "Something hidden",
    e  => sub { die },
});

Prints out:
Some text:
DUMP: File "input text" line 2
    a = 'A string';

DUMP: File "input text" line 3
    [b, c, 1+2] = [
          {
            'key1' => 'val1'
          },
          [
            'foo',
            'bar',
            'baz'
          ],
          3
        ];

DUMP: File "input text" line 4
    '' = '';

DUMP: File "input text" line 5
    EntireStash = {
          'a' => 'A string',
          'b' => {
                   'key1' => 'val1'
                 },
          'c' => [
                   'foo',
                   'bar',
                   'baz'
                 ],
          'e' => sub { "DUMMY" },
          'global' => {}
        };

Some text:

$VAR1 = 'A string';

$VAR1 = [
          {
            'key1' => 'val1'
          },
          [
            'foo',
            'bar',
            'baz'
          ],
          3
        ];

$VAR1 = '';

So - if all I wanted was to see the data - the the Dumper plugin is almost 
sufficient (except I can't see the entire stash).

_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to