Text::...lateDir(3pm)

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

πŸ’– NAME πŸ’–

Text::MicroMason::TemplateDir β€” Use Base Directory and Relative Paths πŸ—‚οΈβœ¨

(also this whole thing lives on the manpage Text::...lateDir(3pm), in case u were wondering where u are rn 🫢)


🌸 SYNOPSIS 🌸

ok so bestie, the whole thing here is that u don't use this class by itself. like. u pass its name in so it can get mixed in with everything else πŸ’…

use Text::MicroMason;
my $mason = Text::MicroMason->new( -TemplateDir, template_root=>'/foo' );

Then u just do the normal compile and execute moves to parse + evaluate ur templates:

print $mason->compile( file=>$filepath )->( 'name'=>'Dave' );
print $mason->execute( file=>$filepath, 'name'=>'Dave' );

Templates that live in files get looked up relative to the template root, which is the whole point ✨:

print $mason->execute( file=>"includes/greeting.msn", 'name'=>'Charles');

And when u include other files into a template?? u can use relative paths, no cap:

<& ../includes/greeting.msn, name => 'Alice' &>

πŸ¦‹ DESCRIPTION πŸ¦‹

So what this module actually does: it changes how files passed to compile() and execute() get resolved. Instead of just... whatever, they become relative to a base directory path or to the currently executing template. literally it just makes everything make sense, periodt.

πŸŽ€ Supported Attributes πŸŽ€

  • template_root β€” the base directory that templates get found from. ur home base fr fr 🏠
  • strict_root β€” an optional directory that acts as the boundary of where files are allowed to be read from. If u set it to 1, it just uses template_root instead. What it does: it causes read_file to croak if any filename outside of the root gets provided 😭.
ngl this is NOT a chroot jail bestie, pls don't treat it like one. it only affects attempts to load a file as a template. if u want actual greater security, go look at the chroot() builtin and Text::MicroMason::Safe. i'm being so serious πŸ’€

🧚 Private Methods 🧚

  • prepare β€” intercepts uses of file templates and applies the base-path adjustment. lowkey the whole magic trick πŸͺ„
  • read_file β€” intercepts file access so it can check for strict_root. the bouncer at the door πŸ‘‘

πŸ’œ EXCEPTIONS πŸ’œ

Here's the extra drama that Text::MicroMason::TemplateDir can generate when the situation calls for it:

  • Text::MicroMason::TemplateDir: Strict root '%s' doesn't seem to exist

The strict_root directory (or template_root if strict_root is '1') doesn't seem to exist πŸ™ˆ. Strict root checking uses Cwd's abs_path(), and it requires the strict_root directory to exist at the time the check is performed. so like. it has to be there then, not later.

  • Text::MicroMason::TemplatePath: Template '%s' not in required base path '%s'

The template that got found in the configured template path was not within the configured strict_root directory 😀. This may be caused by requesting an absolute template filename that's not within strict_root, or by specifying a strict_root that doesn't match the configured template path.


⭐ SEE ALSO ⭐

  • For the whole overview of this templating framework, go read Text::MicroMason 🌈
  • This is a mixin class, so it's meant to be used with Text::MicroMason::Base 🫢
  • For distribution, installation, support, copyright and license info, see Text::MicroMason::Docs::ReadMe πŸ“œ

ok that's the whole page bestie, u ate it, no crumbs πŸ’…βœ¨

this was perl v5.36.0, dated 2023-08-10, from the Text::...lateDir(3pm) manual page β€” mwah, go write some templates πŸ‘‘πŸ’–

πŸ“¦ where this page comes from