| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Ark::View::MT; | 
| 2 | 2 |  |  | 2 |  | 914 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 53 |  | 
| 3 | 2 |  |  | 2 |  | 10 | use warnings; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 45 |  | 
| 4 | 2 |  |  | 2 |  | 8 | use Ark 'View'; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 13 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | has include_path => ( | 
| 7 |  |  |  |  |  |  | is      => 'rw', | 
| 8 |  |  |  |  |  |  | isa     => 'ArrayRef', | 
| 9 |  |  |  |  |  |  | lazy    => 1, | 
| 10 |  |  |  |  |  |  | default => sub { | 
| 11 |  |  |  |  |  |  | my $self = shift; | 
| 12 |  |  |  |  |  |  | [$self->path_to('root')]; | 
| 13 |  |  |  |  |  |  | }, | 
| 14 |  |  |  |  |  |  | ); | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | has extension => ( | 
| 17 |  |  |  |  |  |  | is      => 'rw', | 
| 18 |  |  |  |  |  |  | isa     => 'Str', | 
| 19 |  |  |  |  |  |  | default => '.mt', | 
| 20 |  |  |  |  |  |  | ); | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | has use_cache => ( | 
| 23 |  |  |  |  |  |  | is      => 'rw', | 
| 24 |  |  |  |  |  |  | isa     => 'Bool', | 
| 25 |  |  |  |  |  |  | default => 1, | 
| 26 |  |  |  |  |  |  | ); | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | has cache => ( | 
| 29 |  |  |  |  |  |  | is      => 'rw', | 
| 30 |  |  |  |  |  |  | isa     => 'HashRef', | 
| 31 |  |  |  |  |  |  | lazy    => 1, | 
| 32 |  |  |  |  |  |  | default => sub { {} }, | 
| 33 |  |  |  |  |  |  | ); | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | has open_layer => ( | 
| 36 |  |  |  |  |  |  | is      => 'rw', | 
| 37 |  |  |  |  |  |  | isa     => 'Str', | 
| 38 |  |  |  |  |  |  | default => ':utf8', | 
| 39 |  |  |  |  |  |  | ); | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | has macro => ( | 
| 42 |  |  |  |  |  |  | is      => 'rw', | 
| 43 |  |  |  |  |  |  | isa     => 'HashRef', | 
| 44 |  |  |  |  |  |  | lazy    => 1, | 
| 45 |  |  |  |  |  |  | default => sub { {} }, | 
| 46 |  |  |  |  |  |  | ); | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | has options => ( | 
| 49 |  |  |  |  |  |  | is      => 'rw', | 
| 50 |  |  |  |  |  |  | isa     => 'HashRef', | 
| 51 |  |  |  |  |  |  | lazy    => 1, | 
| 52 |  |  |  |  |  |  | default => sub { {} }, | 
| 53 |  |  |  |  |  |  | ); | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | has mt => ( | 
| 56 |  |  |  |  |  |  | is      => 'rw', | 
| 57 |  |  |  |  |  |  | isa     => 'Text::MicroTemplate::Extended', | 
| 58 |  |  |  |  |  |  | lazy    => 1, | 
| 59 |  |  |  |  |  |  | default => sub { | 
| 60 |  |  |  |  |  |  | my $self = shift; | 
| 61 |  |  |  |  |  |  | my $c     = sub { $self->context }; | 
| 62 |  |  |  |  |  |  | my $stash = sub { $self->context->stash }; | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | $self->ensure_class_loaded('Text::MicroTemplate::Extended'); | 
| 65 |  |  |  |  |  |  | Text::MicroTemplate::Extended->new( | 
| 66 |  |  |  |  |  |  | package_name  => ref($self) . '::_MT', | 
| 67 |  |  |  |  |  |  | include_path  => $self->include_path, | 
| 68 |  |  |  |  |  |  | extension     => $self->extension, | 
| 69 |  |  |  |  |  |  | use_cache     => $self->use_cache, | 
| 70 |  |  |  |  |  |  | open_layer    => $self->open_layer, | 
| 71 |  |  |  |  |  |  | macro         => { | 
| 72 | 0 |  |  | 0 |  |  | raw_string => sub($) { Text::MicroTemplate::EncodedString->new($_[0]) }, | 
| 73 |  |  |  |  |  |  | %{ $self->macro }, | 
| 74 |  |  |  |  |  |  | }, | 
| 75 |  |  |  |  |  |  | template_args => { | 
| 76 |  |  |  |  |  |  | c     => $c, | 
| 77 |  |  |  |  |  |  | s     => $stash, | 
| 78 |  |  |  |  |  |  | stash => $stash, | 
| 79 |  |  |  |  |  |  | }, | 
| 80 |  |  |  |  |  |  | %{ $self->options } | 
| 81 |  |  |  |  |  |  | ); | 
| 82 |  |  |  |  |  |  | }, | 
| 83 |  |  |  |  |  |  | ); | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | sub template { | 
| 86 | 1 |  |  | 1 | 0 | 3 | my ($self, $template) = @_; | 
| 87 | 1 |  |  |  |  | 2 | $self->context->stash->{__view_mt_template} = $template; | 
| 88 | 1 |  |  |  |  | 3 | $self; | 
| 89 |  |  |  |  |  |  | } | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | sub render { | 
| 92 | 4 |  |  | 4 | 0 | 75 | my $self     = shift; | 
| 93 | 4 |  |  |  |  | 5 | my $template = shift; | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | $template ||= $self->context->stash->{__view_mt_template} | 
| 96 | 4 | 50 | 66 |  |  | 19 | || $self->context->request->action->reverse | 
|  |  |  | 66 |  |  |  |  | 
| 97 |  |  |  |  |  |  | or return; | 
| 98 |  |  |  |  |  |  |  | 
| 99 | 4 |  |  |  |  | 87 | my $form_renderer = \&Ark::Form::render; | 
| 100 | 2 |  |  | 2 |  | 14 | no warnings 'redefine'; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 336 |  | 
| 101 |  |  |  |  |  |  | local *Ark::Form::render = sub { | 
| 102 | 0 |  |  | 0 |  | 0 | Text::MicroTemplate::EncodedString->new( $form_renderer->(@_) ); | 
| 103 | 4 | 50 |  |  |  | 29 | } if $form_renderer; | 
| 104 |  |  |  |  |  |  |  | 
| 105 | 4 |  |  |  |  | 21 | $self->mt->render($template, @_); | 
| 106 |  |  |  |  |  |  | } | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | sub process { | 
| 109 | 3 |  |  | 3 | 0 | 5 | my ($self, $c) = @_; | 
| 110 | 3 |  |  |  |  | 16 | $c->response->body( $self->render ); | 
| 111 |  |  |  |  |  |  | } | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | __PACKAGE__->meta->make_immutable; |