YAML::P...:Include(3)
π NAME π
okay bestie, this is the manual for YAML::P...:Include(3) β a User Contributed Perl Documentation page for YAML::PP::Schema::Include, and its whole thing is Include YAML files. yes, it is literally a plugin for pulling other YAML files into your YAML. πβ¨
β¨ SYNOPSIS β¨
okay so picture this: /path/to/file.yaml has an !include in it, and the included file is also YAML. the setup goes like this:
# /path/to/file.yaml
# ---
# included: !include include/file2.yaml
# /path/to/include/file2.yaml
# ---
# a: b
my $include = YAML::PP::Schema::Include->new;
my $yp = YAML::PP->new( schema => ['+', $include] );
# we need the original YAML::PP object for getting the current filename
# and for loading another file
$include->yp($yp);
my ($data) = $yp->load_file("/path/to/file.yaml");
# The result will be:
$data = {
included => { a => 'b' }
};
want to allow absolute filenames and upwards ..? slay, here is the switch:
my $include = YAML::PP::Schema::Include->new(
allow_absolute => 1, # default: 0
);
and if you want to specify paths to search for includes, you do this:
my @include_paths = ("/path/to/include/yaml/1", "/path/to/include/yaml/2");
my $include = YAML::PP::Schema::Include->new(
paths => \@include_paths,
);
my $yp = YAML::PP->new( schema => ['+', $include] );
$include->yp($yp);
# /path/to/include/yaml/1/file1.yaml
# ---
# a: b
my $yaml = <<'EOM';
- included: !include file1.yaml
EOM
my ($data) = $yp->load_string($yaml);
πΈ DESCRIPTION πΈ
this plugin lets you split a large YAML file into smaller ones, then include them with the !include tag. iconic. it will search for the specified filename relative to the currently processed filename.
you can also specify the paths where to search for files to include. it iterates through the paths and returns the first filename that exists. yes bestie, first match wins. π¦
by default, only relative paths are allowed. any ../ in the path will be removed. you can change that behavior by setting the option allow_absolute to true.
if the included file contains more than one document, only the first one will be included. and the original author says: βI will probably add a possibility to return all documents as an arrayref.β that is their note, not me making promises. π
the included YAML file will be loaded by creating a new YAML::PP object with the schema from the existing object. this way you can recursively include files. you can even reuse the same include via an alias:
---
invoice:
shipping address: &address !include address.yaml
billing address: *address
circular includes will be detected, and will be fatal. no cap, that is a hard error. π
it is possible to specify what to do with the included file:
my $include = YAML::PP::Schema::Include->new(
loader => sub {
my ($yp, $filename);
if ($filename =~ m/\.txt$/) {
# open file and just return text
}
else {
# default behaviour
return $yp->load_file($filename);
}
},
);
for example, RAML defines an !include tag which depends on the file content. if it contains a special RAML directive, it will be loaded as YAML, otherwise the content of the file will be included as a string. so with this plugin you are able to read RAML specifications. π₯
and that is the whole page, bestie π
source situation: perl v5.42.0, date 2026-04-24, and the manual is still YAML::P...:Include(3) β go forth and include things responsibly ππ«Ά
π¦ where this page comes from
- opensuse-leap 16.0: perl-YAML-PP 0.40.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms