App-Templer

 view release on metacpan or  search on metacpan

PLUGINS.md  view on Meta::CPAN

return values are chained.

Each site page is loaded and the variable names & values are stored in a hash.
Each plugin is free to modify that hash of known variables and their values.

Generally we expect that plugins will look for variable values having a
particular pattern and ignoring those that don't match.  But there is
certainly no reason why you couldn't write a plugin to convert each
variable-value to uppercase, or perform other global operations.

In pseudo-code the processing looks like this:

    $data = ( "foo" => "bar",
              title => "This is my page title .." );

    foreach my $plugin ( $plugins )
    {
         $data = $plugin->expand_variables( $page, $data );
    }

Each plugin will be called once, and once only, for each page.  The

t/test-templer-plugin-filecontents.t  view on Meta::CPAN

my $ref      = $factory->expand_variables( $site, $page, \%original );
my %updated  = %$ref;

ok( %updated,               "Fetching the fields of the page succeeded" );
ok( $updated{ 'password' }, "The fields contain a file reference" );
ok( $updated{ 'foo' },      "The fields contain the self-file reference" );

#
# Do the file contents look sane?
#
ok( $updated{ 'password' } =~ /root:/,  "The password file looks sane" );
ok( $updated{ 'foo' }      =~ /passwd/, "The self-file looks sane" );

t/test-templer-plugin-shellcommand.t  view on Meta::CPAN


    is( $ref->{ 'bar' },
        "baz", "After calling the plugin the sane value is unchanged." );

    #
    #  Now see if our "foo" value was replaced by the output of the shell
    # command.
    #
    my $shell = $ref->{ 'foo' };
    ok( length($shell), "The shell command execution returned something." );
    ok( $shell =~ /passwd/, "Which looks a little sane." );
    ok( $shell =~ /fstab/,  "And a little more sane." );
}



( run in 0.429 second using v1.01-cache-2.11-cpan-64827b87656 )