Text::...hErrors(3pm)

πŸ“¦
version 2.23 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Text::MicroMason::CatchErrors β€” no cap, bestie πŸ’–

okay so this is the Perl manpage for Text::MicroMason::CatchErrors, living in the User Contributed Perl Documentation corner of the world. it adds exception catching for templates. that's the whole vibe. 🫢


✨ NAME ✨

Text::MicroMason::CatchErrors β€” adds exception catching for templates, periodt.


πŸŽ€ SYNOPSIS πŸŽ€

okay first thing, do not use this class directly, bestie. it's a mixin. you pass its name in and let it do its thing:

use Text::MicroMason;
my $mason = Text::MicroMason->new( -CatchErrors );

then you use the standard compile and execute methods to parse and evaluate templates, like the icon that you are:

print scalar $mason->compile( text=>$template )->( @%args );
print scalar $mason->execute( text=>$template, @args );

and here's the slay part: the result is undef on exception, plus an error message if you're in list context:

($coderef, $error) = $mason->compile( text=>$template );
($result,  $error) = $mason->execute( text=>$template, 'name'=>'Dave' );

it's giving "check a variable instead of wrapping everything in eval." iconic.


πŸ’… DESCRIPTION πŸ’…

so this package adds exception catching to MicroMason, which means you get to check an error variable instead of wrapping every single call in an eval. no more chaos. no more eval everywhere like it's 2003.

both compilation and run-time errors in your template are handled as fatal exceptions. and like, here's the thing β€” the base MicroMason class will croak() if you attempt to compile or execute a template that contains an incorrect fragment of Perl syntax. 😭 and similarly, if the Perl code in your template causes die() or croak() to be called, that will interrupt your program unless it's caught by an eval block. that's just how it is, ngl.

this class provides that error catching behavior for the compile and execute methods. it's literally the whole job.

so in a scalar context they return the result of the call, or undef if it failed; in a list context they return the results of the call (undef if it failed) followed by the error message (undef if it succeeded). πŸ’–

🌸 Public Methods 🌸

  • compile() β€” uses an eval block to provide an exception catching wrapper for the compile method. πŸ¦‹
$code_ref = $mason->compile( text => $template, %options );
($coderef, $error) = $mason->compile( text=>$template, %options );
  • execute() β€” uses an eval block to provide an exception catching wrapper for the execute method. ✨
$result = $mason->execute( text => $template, @arguments );
($result,  $error) = $mason->execute( text=>$template, 'name'=>'Dave' );

πŸ‘‘ SEE ALSO πŸ‘‘

  • for an overview of this templating framework, see Text::MicroMason. πŸ“š
  • this is a mixin class intended for use with Text::MicroMason::Base. 🧚
  • for distribution, installation, support, copyright and license information, see Text::MicroMason::Docs::ReadMe. πŸ’œ

okay that's the whole page, bestie, you ate that. πŸ’… this was perl v5.36.0, dated 2023-08-10, and it's the Text::MicroMason::CatchErrors page from the User Contributed Perl Documentation. mwah πŸ’‹

πŸ“¦ where this page comes from