big kahuna
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package CW::Plack::Response;
|
||||
|
||||
use Moo;
|
||||
use Carp ();
|
||||
|
||||
has _response => (
|
||||
is => 'ro',
|
||||
@@ -9,15 +10,53 @@ has _response => (
|
||||
handles => [qw(finalize status body headers header)]
|
||||
);
|
||||
|
||||
has request => (
|
||||
is => 'ro',
|
||||
required => 1,
|
||||
handles => [qw(env)]
|
||||
);
|
||||
|
||||
has h => (
|
||||
is => 'ro',
|
||||
required => 1
|
||||
);
|
||||
|
||||
sub template {
|
||||
my ( $self, $template ) = @_;
|
||||
my $html = $self->h->html($template);
|
||||
my ( $self, $template, $ctx ) = @_;
|
||||
|
||||
my $html;
|
||||
|
||||
# If rendering inline
|
||||
if ( ref($template) && ref($template) eq 'ARRAY' ) {
|
||||
$html = $self->h->html($template);
|
||||
}
|
||||
elsif ( !ref($template) ) {
|
||||
$ctx //= {};
|
||||
$ctx->{env} = $self->env;
|
||||
|
||||
## no strict [BuiltinFunctions::ProhibitStringyEval]
|
||||
my $template_pkg = "CW::Template::$template";
|
||||
eval "use $template_pkg";
|
||||
|
||||
my $layout_pkg =
|
||||
"CW::Layout::" . ( delete( $ctx->{layout} ) // 'Default' );
|
||||
## no strict [BuiltinFunctions::ProhibitStringyEval]
|
||||
eval "use $layout_pkg";
|
||||
|
||||
my $layout = $layout_pkg->new(
|
||||
template => $template_pkg->new( ctx => $ctx ),
|
||||
ctx => $ctx
|
||||
);
|
||||
|
||||
$html = $self->h->html( $layout->render );
|
||||
}
|
||||
else {
|
||||
Carp::croak("Invalid value passed to template call: $template");
|
||||
}
|
||||
|
||||
$self->_response->header( 'Content-Type' => 'text/html; encoding=utf-8' );
|
||||
$self->_response->body($html);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user