Mojo::Template *returns* Mojo::Exceptions? Why doesn't it *throw* them?

56 views
Skip to first unread message

Peter Valdemar Mørch

unread,
Aug 8, 2016, 9:00:45 PM8/8/16
to Mojol...@googlegroups.com
I'm just getting my feet wet with Mojolicious. One of the things I loved immediately was Mojo::Template, so I've started using it also outside of Mojolicious. I was very surprised to see error output on STDOUT without my $SIG{__DIE__} kicking in.

So now I am curious as to why it returns Mojo::Exception objects on error instead of die-ing them outright. This choice seems unusual to me, and I'd like to understand why it is. The perldoc suggests:

my $mt = Mojo::Template->new;
say $mt->render(<<'EOF');
....
EOF

But really one cannot do that. One really needs to:

my $mt = Mojo::Template->new;
my $output = $mt->render(<<'EOF');
....
EOF
die $output if ref $output
say $output;

"die $$output if ref $$output;" is found in Mojolicious/Plugin/EPLRenderer.pm and "return ref $output ? die $output : $output;" is found in Mojolicious/Plugin/JSONConfig.pm, so I guess Mojolicious itself also needs to do that.

The perldoc does say that ".... Mojo::Template will return Mojo::Exception objects that stringify to error messages with context." but doesn't show any such "die if exception" code in the actual examples.

Is there a good reason for this somewhat non-standard exception behavior?

Sincerely,

Peter

sri

unread,
Aug 12, 2016, 8:05:47 AM8/12/16
to Mojolicious, Mojol...@googlegroups.com
The perldoc does say that ".... Mojo::Template will return Mojo::Exception objects that stringify to error messages with context." but doesn't show any such "die if exception" code in the actual examples.

Is there a good reason for this somewhat non-standard exception behavior?

It used to be necessary for the Mojolicious renderer, and i guess nobody thought it was worth changing once it was not needed anymore.

--
sebastian

Peter Valdemar Mørch

unread,
Aug 15, 2016, 3:54:16 AM8/15/16
to mojol...@googlegroups.com
Ok, thanks! It helps to understand the reasons behind why things are as as they are.
Reply all
Reply to author
Forward
0 new messages