View the contents of a variable in pure form

So, the way I use to view the contents of a variable is to use Data :: Dumper in my template set:

  [% USE Dumper%]
 [% Dumper.dump (varname)%]

But the result that I get is a big mess - all the information about table relationships, column types and attrbitues, etc.

I wonder if there is a way to get the "pure" content of the variable - as in the current result from the request made + related results (i.e. when I used php with the cakephp framework, there was "debug" (varname) ', which gave such a result, which looked like this http://pastebin.com/Hut0LnAb ).

+6
source share
2 answers

Data :: Printer to the rescue! This dump of the object is more readable:

my $obj = SomeClass->new; p($obj); # produces: \ SomeClass { Parents Moose::Object Linear @ISA SomeClass, Moose::Object public methods (3) : bar, foo, meta private methods (0) internals: { _something => 42, } } 

It is compatible with Template Toolkit:

 [% USE DataPrinter %] html-formatted, colored dump of the same data structure: [% DataPrinter.dump_html( myvar ) %] 

And he "knows" how to handle DBIx :: Class too:

 use Data::Printer filters => { -external => [qw[DB]], # use DB filter }, class => { expand => 2, # traverse object 2-levels deep linear_isa => 0, # hide not-so-relevant information }; ... my $obj = $schema ->resultset('AddressState') ->search({}, { prefetch => [qw[country]] }) ->single; p $obj; 
+8
source

you could use

  [% Dumper.dump_html(variable) %] 

See: http://template-toolkit.org/docs/modules/Template/Plugin/Dumper.html

0
source

All Articles