You don't have to load Data::Dumper for that. One of the built-in helpers is Data::Dumper.
% if ($debug_mode) { dumper $session; }
or specific values:
% if ($debug_mode) { dumper $session->some_value; }
Question
I expect this to be marked as a dup, but I've searched and searched and can't find any questions that are similar, much less the answer. When a Mojolicious template has an error, you get a page that shows all of the session data.
For debugging, I created a "dump" page that contains a deliberate error, but that seems to be a mite inefficient. Is there a simple way (like an already defined helper) to append the same well-formatted information to a page that I'm debugging?
Solution
You don't have to load Data::Dumper for that. One of the built-in helpers is Data::Dumper.
% if ($debug_mode) { dumper $session; }
or specific values:
% if ($debug_mode) { dumper $session->some_value; }
OTHER TIPS
Rather than throwing an error, you could call render_exception
(which is what throwing an error does), but even that isn't the best idea. You should try using tempire's excellent Mojolicious::Plugin::ConsoleLogger which will send all the information you could ever want to your browser's javascript console.
Do you mean a page like an HTML template? You can just insert it into an HTML comment anywhere on any template:
% if ($debug_mode) {
% my $session_dump = Data::Dumper::Dumper($self->session);
<!-- session data is: <%= $session_dump %> -->
% }
Then view the page source when you want to inspect the session data.