Sometimes Data::Dumper is not enough. Got a Moose object you want to inspect? Huge numbers of the same structure? Want stuff sorted? Colored? Data::Printer is your friend.
use Data::Printer;
p $data_structure;
Data::Printer writes to STDERR, like warn
. That makes it easier to find the output. By default, it sorts hash keys and looks at objects.
use Data::Printer;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
p $ua;
It will look at all the methods of the object, and also list the internals.
LWP::UserAgent {
Parents LWP::MemberMixin
public methods (45) : add_handler, agent, clone, conn_cache, cookie_jar, credentials, default_header, default_headers, delete, env_proxy, from, get, get_basic_credentials, get_my_handler, handlers, head, is_online, is_protocol_supported, local_address, max_redirect, max_size, mirror, new, no_proxy, parse_head, post, prepare_request, progress, protocols_allowed, protocols_forbidden, proxy, put, redirect_ok, remove_handler, request, requests_redirectable, run_handlers, send_request, set_my_handler, show_progress, simple_request, ssl_opts, timeout, use_alarm, use_eval
private methods (4) : _agent, _need_proxy, _new_response, _process_colonic_headers
internals: {
def_headers HTTP::Headers,
handlers {
response_header HTTP::Config
},
local_address undef,
max_redirect 7,
max_size undef,
no_proxy [],
protocols_allowed undef,
protocols_forbidden undef,
proxy {},
requests_redirectable [
[0] "GET",
[1] "HEAD"
],
show_progress undef,
ssl_opts {
verify_hostname 1
},
timeout 180,
use_eval 1
}
}
You can configure it further, so it serializes certain objects in a certain way, or to include objects up to an arbitrary depth. The full configuration is available in the documentation.
Unfortunately Data::Printer does not ship with Perl, so you need to install it from CPAN or through your package management system.