NAME
YAML::Active - Combine data and logic in YAML
VERSION
version 1.100810
SYNOPSIS
use YAML::Active;
my $data = Load(<
The content of the included file goes here.
"YAML::Active::PID"
Returns the current process id.
Example:
the_pid: /YAML::Active::PID
whatever:
Result (for example):
the_pid: 12345
Note that, although this plugin doesn't require any arguments, we
have to give it either an array reference or a hash reference,
because "YAML" can't bless something that's not a reference. The
contents of the reference don't matter.
"YAML::Active::Shuffle"
Expects an array reference and returns another array reference with
the activated original elements in random order.
Example:
data: /YAML::Active::Shuffle
- 1
- 2
- 3
- 4
- 5
Result (for example):
data:
- 3
- 5
- 1
- 2
- 4
"YAML::Active::Print"
Expects an array reference and joins the activated array elements,
printing the result and returning a null (i.e., a
"YAML::Active::NULL") node. That is, the node won't appear in the
resulting activated data structure.
Example:
data:
- foo
- /YAML::Active::Print
- '# Hello, world!'
- 'Goodbye, world!'
- baz
Result:
data:
- foo
- baz
and the string "# Hello, world!Goodbye, world!" is printed.
"YAML::Active::uc"
Replaces node values (scalars, array elements and hash values) with
their lowercased value. Does not descend into deeper array
references or hash references, but passes them through unaltered.
Example:
data: /YAML::Active::uc
- Hello
- world and
- one: GOoD
two: byE
- wOrLd!
Result:
data:
- HELLO
- WORLD AND
- one: GOoD
two: byE
- WORLD!
"YAML::Active::lc"
Like "YAML::Active::uc", but lowercases the values.
WRITING YOUR OWN PLUGIN
Suppose you want to write an activation plugin that takes a reference to
an array of numbers and adds them.
By including the string "YAML::Active" in the package name we can let
"YAML::Active" load the package when necessary. All we need to do is to
provide a "yaml_activate()" method that does the work.
package My::YAML::Active::Add;
use YAML::Active qw/array_activate assert_arrayref/;
sub yaml_activate {
my $self = shift;
assert_arrayref($self);
my $result;
$result += $_ for @{ array_activate($self) };
return $result;
}
Now you can do:
result: /My::YAML::Active::Add
- 1
- 2
- 3
- 7
- 15
And the result would be:
result: 28
This could be the beginning of a YAML-based stack machine or at least an
RPN calculator...
INSTALLATION
See perlmodinstall for information and options on installing Perl
modules.
BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests through the web interface at
.
AVAILABILITY
The latest version of this module is available from the Comprehensive
Perl Archive Network (CPAN). Visit to find a
CPAN site near you, or see .
The development version lives at
. Instead of sending patches,
please fork this project using the standard git and github
infrastructure.
AUTHOR
Marcel Gruenauer
COPYRIGHT AND LICENSE
This software is copyright (c) 2003 by Marcel Gruenauer.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.