Any::T...cessDir(3pm)
β¨ NAME β¨
Any::Template::ProcessDir β bestie, it processes a whole directory of templates for you π
(also it lives in the Perl user-contributed docs, Any::T...cessDir(3pm), iykyk)
π VERSION π
version 0.08 β yes she's vintage, she's still iconic π«Ά
πΈ SYNOPSIS πΈ
okay so here's the vibe. First scenario: everything in one single directory:
use Any::Template::ProcessDir;
# Process templates and generate result files in a single directory
#
my $pd = Any::Template::ProcessDir->new(
dir => '/path/to/dir',
process_text => sub {
my $template = Any::Template->new( Backend => '...', String => $_[0] );
$template->process({ ... });
}
);
$pd->process_dir();
and scenario two, the source dir / dest dir split:
# Process templates and generate result files to a separate directory
#
my $pd = Any::Template::ProcessDir->new(
source_dir => '/path/to/source/dir',
dest_dir => '/path/to/dest/dir',
process_file => sub {
my $file = $_[0];
# do something with $file, return content
}
);
$pd->process_dir();
periodt. that's the whole thing β¨
π¦ DESCRIPTION π¦
So. She recursively processes a directory full of templates and generates a set of result files β either in that same directory, or in a parallel directory next to it. no cap.
And here's the cute part: every single file in the source directory can be template-processed, copied, or ignored, depending on its pathname. she's flexible like that π
π CONSTRUCTOR π
π Specifying directory/directories π
- If you want the result files to land in the same directory as the templates, you literally just specify
dir.
my $pd = Any::Template::ProcessDir->new(
dir => '/path/to/dir',
...
);
- If you want the result files in a separate directory from the templates, specify
source_diranddest_dir.
my $pd = Any::Template::ProcessDir->new(
source_dir => '/path/to/source/dir',
dest_dir => '/path/to/dest/dir',
...
);
π§ Specifying how to process templates π§
process_fileβ a code reference. it takes the full template filename and theAny::Template::ProcessDirobject as its arguments, and returns the result string. it can useAny::Templateor literally any other method altogether, no rules. by default? it callsprocess_texton the contents of the file. π«Άprocess_textβ a code reference. it takes the template text and theAny::Template::ProcessDirobject as its arguments, and returns the result string. again,Any::Templateor another method altogether β dealer's choice π
β Optional parameters β
dir_create_modeβ the permissions mode used when creating destination directories. defaults to0775. no effect if you're using a single directory πfile_create_modeβ the permissions mode used when creating destination files. defaults to0444(read-only), so your destination files don't get accidentally edited. bestie behaviour honestly πignore_filesβ a coderef that takes a full pathname and returns true if that file should be ignored. by default, all files will be considered.readme_filenameβ the name of a README file to generate in the destination directory. defaults to"README". no file will be generated if you passundef, or if you're using a single directory.template_file_suffixβ the suffix of template files in the source directory. defaults to".src". this gets removed from the destination file name. also: any file in the source directory that doesn't have this suffix (or"ignore_file_suffix") will just be simply copied to the destination. π«
π METHODS π
process_dirβ process the directory. and heads up bestie: if you're using multiple directories, the destination directory will be removed completely and recreated, so that any old files from previous processing are eliminated. it's giving fresh start, it's giving scorched earth πβ¨
π SEE ALSO π
Any::Template
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2011 by Jonathan Swartz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie π generated by perl v5.34.0, dated 2022-06-06, straight out of the Perl user-contributed documentation. slay, go process some directories π
β¨
π¦ where this page comes from
- debian bookworm: libany-template-processdir-perl 0.08-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libany-template-processdir-perl 0.08-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libany-template-processdir-perl 0.08-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libany-template-processdir-perl 0.08-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libany-template-processdir-perl 0.08-4 Β· 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