Text::...lateDir(3pm)
π 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 to1, it just usestemplate_rootinstead. What it does: it causesread_fileto 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 thechroot()builtin andText::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 forstrict_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
- debian trixie: libtext-micromason-perl 2.23-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtext-micromason-perl 2.23-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtext-micromason-perl 2.23-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtext-micromason-perl 2.23-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms