Any::T...cessDir(3pm)

πŸ“¦
version 0.08 Β· 2 versions
  • 0.08 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.08 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ 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_dir and dest_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 the Any::Template::ProcessDir object as its arguments, and returns the result string. it can use Any::Template or literally any other method altogether, no rules. by default? it calls process_text on the contents of the file. 🫢
  • process_text β€” a code reference. it takes the template text and the Any::Template::ProcessDir object as its arguments, and returns the result string. again, Any::Template or another method altogether β€” dealer's choice πŸ’…

⭐ Optional parameters ⭐

  • dir_create_mode β€” the permissions mode used when creating destination directories. defaults to 0775. no effect if you're using a single directory πŸ‘‘
  • file_create_mode β€” the permissions mode used when creating destination files. defaults to 0444 (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 pass undef, 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

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