| 1 | package HTML::FormHandler::Render::WithTT; | ||||||||||
| 2 | # ABSTRACT: tt rendering | ||||||||||
| 3 | 4 | $HTML::FormHandler::Render::WithTT::VERSION = '0.410000'; | |||||||||
| 4 | 4 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use File::ShareDir; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use Template; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 4 | ▶ | use HTML::FormHandler::Render::Util ('process_attrs'); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | |||||||||||
| 11 | 4 | has 'tt_include_path' => ( | |||||||||
| 12 | traits => ['Array'], | ||||||||||
| 13 | is => 'rw', | ||||||||||
| 14 | isa => 'ArrayRef', | ||||||||||
| 15 | lazy => 1, | ||||||||||
| 16 | builder => 'build_tt_include_path', | ||||||||||
| 17 | handles => { | ||||||||||
| 18 | add_tt_include_path => 'push', | ||||||||||
| 19 | } | ||||||||||
| 20 | ); | ||||||||||
| 21 | 0 | ▶ | sub build_tt_include_path {[]} | ||||||||
|
Subroutine
build_tt_include_path: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 22 | |||||||||||
| 23 | 4 | has 'tt_config' => ( | |||||||||
| 24 | traits => ['Hash'], | ||||||||||
| 25 | is => 'rw', | ||||||||||
| 26 | lazy => 1, | ||||||||||
| 27 | builder => 'build_tt_config', | ||||||||||
| 28 | ); | ||||||||||
| 29 | sub build_tt_config { | ||||||||||
| 30 | 5 | ▶ | my $self = shift; | ||||||||
|
Subroutine
build_tt_config: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 31 | return { | ||||||||||
| 32 | INCLUDE_PATH => [ | ||||||||||
| 33 | 5 | @{ $self->tt_include_path }, | |||||||||
| 34 | File::ShareDir::dist_dir('HTML-FormHandler') . '/templates/' | ||||||||||
| 35 | ] | ||||||||||
| 36 | }; | ||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | # either file name string or string ref? | ||||||||||
| 40 | 4 | has 'tt_template' => ( is => 'rw', isa => 'Str', lazy => 1, | |||||||||
| 41 | builder => 'build_tt_template' ); | ||||||||||
| 42 | 0 | ▶ | sub build_tt_template { 'form/form.tt' } | ||||||||
|
Subroutine
build_tt_template: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 43 | |||||||||||
| 44 | 4 | has 'tt_engine' => ( is => 'rw', isa => 'Template', lazy => 1, | |||||||||
| 45 | builder => 'build_tt_engine' | ||||||||||
| 46 | ); | ||||||||||
| 47 | sub build_tt_engine { | ||||||||||
| 48 | 5 | ▶ | my $self = shift; | ||||||||
|
Subroutine
build_tt_engine: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 49 | |||||||||||
| 50 | 5 | my $tt_engine = Template->new( $self->tt_config ); | |||||||||
| 51 | 5 | return $tt_engine; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 4 | has 'tt_vars' => ( is => 'rw', traits => ['Hash'], | |||||||||
| 55 | builder => 'build_tt_vars'); | ||||||||||
| 56 | 5 | ▶ | sub build_tt_vars {{}} | ||||||||
|
Subroutine
build_tt_vars: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 57 | |||||||||||
| 58 | 4 | has 'default_tt_vars' => ( is => 'ro', isa => 'HashRef', | |||||||||
| 59 | lazy => 1, builder => 'build_default_tt_vars' ); | ||||||||||
| 60 | sub build_default_tt_vars { | ||||||||||
| 61 | 5 | ▶ | my $self = shift; | ||||||||
|
Subroutine
build_default_tt_vars: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 62 | 5 | return { form => $self->form, process_attrs => \&process_attrs }; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 4 | has 'tt_default_options' => ( | |||||||||
| 66 | traits => ['Hash'], | ||||||||||
| 67 | is => 'rw', | ||||||||||
| 68 | isa => 'HashRef', | ||||||||||
| 69 | lazy => 1, | ||||||||||
| 70 | builder => 'build_tt_default_options', | ||||||||||
| 71 | ); | ||||||||||
| 72 | 0 | ▶ | sub build_tt_default_options {{}} | ||||||||
|
Subroutine
build_tt_default_options: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 73 | |||||||||||
| 74 | |||||||||||
| 75 | sub tt_render { | ||||||||||
| 76 | 5 | ▶ | my $self = shift; | ||||||||
|
Subroutine
tt_render: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||
| 77 | |||||||||||
| 78 | 5 | my $output; | |||||||||
| 79 | 5 | my $vars = { %{$self->default_tt_vars}, %{$self->tt_vars} }; | |||||||||
| 80 | 5 | $self->tt_engine->process( $self->tt_template, $vars, \$output ); | |||||||||
| 81 | |||||||||||
| 82 | 5 | ▶ | if( my $exception = $self->tt_engine->{SERVICE}->{_ERROR} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | |||||||||||
| 84 | 0 | die $exception->[0] . " " . $exception->[1] . ". So far => " . ${$exception->[2]} . "\n"; | |||||||||
| 85 | } | ||||||||||
| 86 | 5 | return $output; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 4 | 1; | |||||||||
| 90 | |||||||||||
| 91 | __END__ | ||||||||||
| 92 | |||||||||||
| 93 | =pod | ||||||||||
| 94 | |||||||||||
| 95 | =encoding UTF-8 | ||||||||||
| 96 | |||||||||||
| 97 | =head1 NAME | ||||||||||
| 98 | |||||||||||
| 99 | HTML::FormHandler::Render::WithTT - tt rendering | ||||||||||
| 100 | |||||||||||
| 101 | =head1 VERSION | ||||||||||
| 102 | |||||||||||
| 103 | version 0.410000 | ||||||||||
| 104 | |||||||||||
| 105 | =head1 SYNOPSIS | ||||||||||
| 106 | |||||||||||
| 107 | A rendering role for HTML::FormHandler that allows rendering using | ||||||||||
| 108 | Template::Toolkit | ||||||||||
| 109 | |||||||||||
| 110 | package MyApp::Form; | ||||||||||
| 111 | use HTML::FormHandler::Moose; | ||||||||||
| 112 | extends 'HTML::FormHandler'; | ||||||||||
| 113 | with 'HTML::FormHandler::Render::WithTT'; | ||||||||||
| 114 | |||||||||||
| 115 | sub build_tt_template { 'user_form.tt' } | ||||||||||
| 116 | sub build_tt_include_path { ['root/templates'] } | ||||||||||
| 117 | ....< define form >.... | ||||||||||
| 118 | |||||||||||
| 119 | my $form = MyApp::Form->new( | ||||||||||
| 120 | $form->tt_render; | ||||||||||
| 121 | |||||||||||
| 122 | If you want to render with TT, you don't need this role. Just use | ||||||||||
| 123 | one of the TT form templates provided, form.tt or form_in_one.tt. | ||||||||||
| 124 | If you use this role to render, you are using two different TT | ||||||||||
| 125 | engines, with different sets of variables, etc, which doesn't | ||||||||||
| 126 | make much sense. | ||||||||||
| 127 | |||||||||||
| 128 | This is mainly useful as a testing aid and an example of using the | ||||||||||
| 129 | sample templates. | ||||||||||
| 130 | |||||||||||
| 131 | =head1 DESCRIPTION | ||||||||||
| 132 | |||||||||||
| 133 | Uses 'tt_render' instead of 'render' to allow using both TT templates and the | ||||||||||
| 134 | built-in rendering. | ||||||||||
| 135 | |||||||||||
| 136 | =head1 AUTHOR | ||||||||||
| 137 | |||||||||||
| 138 | FormHandler Contributors - see HTML::FormHandler | ||||||||||
| 139 | |||||||||||
| 140 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 141 | |||||||||||
| 142 | This software is copyright (c) 2017 by Gerda Shank. | ||||||||||
| 143 | |||||||||||
| 144 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 145 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 146 | |||||||||||
| 147 | =cut | ||||||||||