Template-Resolver

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

 resolve(%options)

    Will read the template and replace all placeholders prefixed by key.
    One of the options content, handle, or filename is required. The
    available options are:

    content

      A string containing templated content.

    filename

      The name of a file containing templated content.

    handle

      A handle to a file containing templated content.

    key

      The template key, defaults to TEMPLATE.

AUTHOR

    Lucas Theisen <lucastheisen@pastdev.com>

COPYRIGHT AND LICENSE

    This software is copyright (c) 2015 by Lucas Theisen.

    This is free software; you can redistribute it and/or modify it under
    the same terms as the Perl 5 programming language system itself.

SEE ALSO

    Please see those modules/websites for more information related to this
    module.

      * Template::Transformer

      * Template::Overlay

      * https://github.com/lucastheisen/template-resolver

SYNOPSIS # Basic example use Template::Resolver; my $resolver =
Template::Resolver->new($entity); $resolver->resolve(file =>
'/path/to/file', key => 'REPLACEME');

      # More complete example
      use Template::Resolver;
    
      $java_properties_file = <<'EOF';
    
        # Simple value that will error if not present
        server_port = ${TEMPLATE{app.port}}
    
        # Simple value with a default (no error if not present)
        context_path = ${TEMPLATE{app.context_path:/myapp}}
    
        # Get an env var
        http_proxy = ${TEMPLATE_env{HTTP_PROXY}}
    
        # Translate a cygwin path with error if not present
        module_jar = ${TEMPLATE_os{app.module_addon1}}
    
        # Translate a cygwin path with default
        module_jar = ${TEMPLATE_os{app.module_addon2:/var/local/lib/mymodule.jar}}
    
        # Escape some xml (with blank default)
        html_header = ${TEMPLATE_xml_escape{app.header:}}
    
        # Run some perl
        https_enabled = ${TEMPLATE_perl{ property(app.use_https) ? 'true' : 'false'}}
        https_proxy = ${TEMPLATE_perl{ sprintf( 'https://%s:%d/', $ENV{HTTPS_PROXY_HOST}, $ENV{HTTPS_PROXY_PORT} )}}
    
        # Custom stuff
        db_user = ${TEMPLATE_customfetch{ 'dbuser' }}
    
      EOF
    
      my $entity = {
          app => {
              port => 80,
              module_addon1 => '/var/local/lib/mymodule.jar',
              use_https => 0,
          }
      };
    
      my $resolver = Template::Resolver->new( $entity, additional_transforms => {
          customfetch => sub {
              #Do something here
              return 'mydbuser';
          }
      });
      my $transformed_result = $resolver->resolve( content => $java_properties_file );



( run in 0.665 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )