Template-Resolver

 view release on metacpan or  search on metacpan

lib/Template/Resolver.pm  view on Meta::CPAN


=item handle

A handle to a file containing templated content.

=item key

The template key, defaults to C<TEMPLATE>.

=back

=head1 AUTHOR

Lucas Theisen <lucastheisen@pastdev.com>

=head1 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.

=head1 SEE ALSO

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

=over 4

=item *

L<Template::Transformer|Template::Transformer>

=item *

L<Template::Overlay|Template::Overlay>

=item *

L<https://github.com/lucastheisen/template-resolver|https://github.com/lucastheisen/template-resolver>

=back

=head1 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 );

=cut



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