From e2b062e5be48ab758d3c2b98721138e637acbd17 Mon Sep 17 00:00:00 2001 From: hylom Date: Thu, 8 Sep 2016 18:57:48 +0900 Subject: [PATCH] Plugin::TT2Renderer: fix code indent --- .../lib/Newslash/Plugin/TT2Renderer.pm | 154 ++++++++++----------- 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/dev/newslash_web/lib/Newslash/Plugin/TT2Renderer.pm b/dev/newslash_web/lib/Newslash/Plugin/TT2Renderer.pm index 249ef21f..048a9519 100644 --- a/dev/newslash_web/lib/Newslash/Plugin/TT2Renderer.pm +++ b/dev/newslash_web/lib/Newslash/Plugin/TT2Renderer.pm @@ -19,89 +19,89 @@ use FileHandle; # subclass for customizing template-provider { - package Newslash::Plugin::TT2Renderer::Provider; - use base qw(Template::Provider); - - my $EXT = ["", ".html.tt2", ".tt2"]; - - sub _find_template { - my ($self, $fname) = @_; - foreach my $ext (@$EXT) { - my $path = $fname . $ext; - if (-f $path) { - return $path; - } - } - return undef; + package Newslash::Plugin::TT2Renderer::Provider; + use base qw(Template::Provider); + + my $EXT = ["", ".html.tt2", ".tt2"]; + + sub _find_template { + my ($self, $fname) = @_; + foreach my $ext (@$EXT) { + my $path = $fname . $ext; + if (-f $path) { + return $path; + } } - - sub _template_modified { - my ($self, $fname) = @_; - my $path = $self->_find_template($fname); - if (!$path) { - return undef; - } - - return (stat($path))[9]; + return undef; + } + + sub _template_modified { + my ($self, $fname) = @_; + my $path = $self->_find_template($fname); + if (!$path) { + return undef; } - - sub _template_content { - my ($self, $fname) = @_; - my $path = $self->_find_template($fname); - if (!$path) { - return undef; - } - my $fh = FileHandle->new; - if ($fh->open($path, "r")) { - my $tmpl = do { local $/; <$fh> }; - $fh->close; - return $tmpl; - } - return undef; + + return (stat($path))[9]; + } + + sub _template_content { + my ($self, $fname) = @_; + my $path = $self->_find_template($fname); + if (!$path) { + return undef; + } + my $fh = FileHandle->new; + if ($fh->open($path, "r")) { + my $tmpl = do { local $/; <$fh> }; + $fh->close; + return $tmpl; } + return undef; + } } sub register { - my ($self, $app, $conf) = @_; - - $app->renderer->add_handler( 'tt2' => sub { - my ($renderer, $c, $output, $options) = @_; - - my $inline_template = $options->{inline}; - my $template_path = $renderer->template_path($options); - my $data_template = $renderer->get_data_template($options); - my $template_name = $renderer->template_name($options); - my $paths = $renderer->paths; - - my $tt_options = $options || {}; - $tt_options->{INCLUDE_PATH} = $paths; - $tt_options->{ENCODING} = 'utf8'; - $tt_options->{LOAD_TEMPLATES} = [Newslash::Plugin::TT2Renderer::Provider->new($tt_options),]; - - #$log->debug(Dumper($tt_options)); - - my $tt = Template->new($tt_options); - - my $template = ''; - if ($inline_template) { - # use string as a template - $template = $inline_template; - } elsif ($data_template) { - # use template in DATA sections - $template = $data_template; - } else { - # read from file - $template = $template_name; - } - my $vars = $c->stash; - my $process_opts = {}; - - my $result = $tt->process($template, $vars, $output, $process_opts); - if (!$result) { - die $tt->error(); - } - return $$output; - }); + my ($self, $app, $conf) = @_; + + $app->renderer->add_handler( 'tt2' => sub { + my ($renderer, $c, $output, $options) = @_; + + my $inline_template = $options->{inline}; + my $template_path = $renderer->template_path($options); + my $data_template = $renderer->get_data_template($options); + my $template_name = $renderer->template_name($options); + my $paths = $renderer->paths; + + my $tt_options = $options || {}; + $tt_options->{INCLUDE_PATH} = $paths; + $tt_options->{ENCODING} = 'utf8'; + $tt_options->{LOAD_TEMPLATES} = [Newslash::Plugin::TT2Renderer::Provider->new($tt_options),]; + + #$log->debug(Dumper($tt_options)); + + my $tt = Template->new($tt_options); + + my $template = ''; + if ($inline_template) { + # use string as a template + $template = $inline_template; + } elsif ($data_template) { + # use template in DATA sections + $template = $data_template; + } else { + # read from file + $template = $template_name; + } + my $vars = $c->stash; + my $process_opts = {}; + + my $result = $tt->process($template, $vars, $output, $process_opts); + if (!$result) { + die $tt->error(); + } + return $$output; + }); } 1; -- 2.11.0