Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewing the variable content in a clean way

So the way I'm using to view a variable content is to use Data::Dumper in my template toolkit:

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

But the result I get is kind of a big mess - all the info about table relations, column types and attrbitues etc.

What I wonder is if there is a way to get a 'clean' variable content - as in only current result from the query being made + related resultsets (i.e. when I used php with cakephp framework there was a 'debug(varname)' command which provided such a result, which looked like this http://pastebin.com/Hut0LnAb).

like image 908
kK-Storm Avatar asked Nov 13 '12 10:11

kK-Storm


1 Answers

Data::Printer to the rescue! It's object dump is more human-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 it "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;
like image 85
creaktive Avatar answered Nov 03 '22 02:11

creaktive