Jifty
view release on metacpan or search on metacpan
lib/Jifty/Handler.pm view on Meta::CPAN
return if $self->_view_handlers;
$self->_view_handlers({});
foreach my $class ($self->view_handlers()) {
$self->_view_handlers->{$class} = $class->new();
}
}
=head2 view ClassName
Returns the Jifty view handler for C<ClassName>.
=cut
sub view {
my $self = shift;
my $class = shift;
$self->setup_view_handlers;
return $self->_view_handlers->{$class};
}
=head2 psgi_app_static
Returns a closure for L<PSGI> application that handles all static
content, including plugins.
=cut
sub psgi_app_static {
my $self = shift;
# XXX: this is no longer needed, however TestApp-Mason is having a
# static::handler-less config
my $view_handler = $self->view('Jifty::View::Static::Handler')
or return;;
require Plack::App::Cascade;
require Plack::App::File;
my $static = Plack::App::Cascade->new;
my $app_class = Jifty->app_class;
$static->add( $app_class->psgi_app_static )
if $app_class->can('psgi_app_static');
$static->add(
Plack::App::File->new(
root => Jifty::Util->absolute_path(
Jifty->config->framework('Web')->{StaticRoot}
)
)->to_app
);
for ( grep { defined $_ } map { $_->psgi_app_static } Jifty->plugins ) {
$static->add( $_ );
}
$static->add( Plack::App::File->new
( root => Jifty->config->framework('Web')->{DefaultStaticRoot} )->to_app );
# the buffering and unsetting of psgi.streaming is to vivify the
# responded res from the $static cascade app.
builder {
enable 'Plack::Middleware::ConditionalGET';
enable
sub { my $app = shift;
sub { my $env = shift;
$env->{'psgi.streaming'} = 0;
my $res = $app->($env);
# skip streamy response
return $res unless ref($res) eq 'ARRAY' && $res->[2];
my $h = Plack::Util::headers($res->[1]);;
$h->set( 'Cache-Control' => 'max-age=31536000, public' );
$h->set( 'Expires' => HTTP::Date::time2str( time() + 31536000 ) );
$res;
};
};
enable 'Plack::Middleware::BufferedStreaming';
$static;
};
}
=head2 psgi_app
Returns a closure for L<PSGI> application.
=cut
sub psgi_app {
my $self = shift;
my $app = sub { $self->handle_request(@_) };
my $static = $self->psgi_app_static;
$app = builder {
mount '/static' => $static;
mount '/' => $app
}
if Jifty->config->framework("Web")->{PSGIStatic} && $static;
# CAS wrapper
$app = Jifty::CAS->wrap($app);
# allow plugin to wrap $app
for ( Jifty->plugins ) {
$app = $_->wrap($app);
}
return $app;
}
=head2 handle_request
When your server process (be it Jifty-internal, FastCGI or anything
else) wants to handle a request coming in from the outside world, you
should call C<handle_request>.
=cut
sub handle_request {
my ($self, $env) = @_;
my $req = Plack::Request->new($env);
my $response;
$self->setup_view_handlers;
$self->call_trigger('before_request', $req);
( run in 3.894 seconds using v1.01-cache-2.11-cpan-f56aa216473 )