CatalystX-ASP

 view release on metacpan or  search on metacpan

lib/CatalystX/ASP/View.pm  view on Meta::CPAN

package CatalystX::ASP::View;

use namespace::autoclean;
use Moose;
use CatalystX::ASP;
use Scalar::Util qw(blessed);
use HTTP::Date qw(time2str);
use Try::Tiny;

extends 'Catalyst::View';

has 'asp' => (
    is  => 'rw',
    isa => 'CatalystX::ASP',
);

=head1 NAME

CatalystX::ASP::View - Catalyst View for processing ASP scripts

=head1 SYNOPSIS

  package MyApp::Controller::Foo;

  sub 'asp' : Regex('\.asp$') {
    my ($self, $c, @args) = @_;
    $c->forward( $c->view( 'ASP' ), \@args );
  }

=head1 DESCRIPTION

This is the Catalyst View to handle ASP scripts. Given a C<$path> to the ASP
script, this will render the ASP script and populate C<< $c->response >> with
the computed headers and body.

=head1 METHODS

=over

=item $self->process($c, @args)

Takes a C<$path> or guesses base off C<< $c->request->path >>. After ASP
renders the output, this will populate C<< $c->response >> accordingly

=cut

sub process {
    my ( $self, $c, @args ) = @_;

    my $path = join '/', @args;

    try {
        $self->render( $c, $path );

        my $resp   = $self->asp->Response;
        my $status = $resp->Status;
        if ( $status >= 500 ) {
            $c->error( "Erroring out because HTTP Status set to $status" );
        } else {
            my $charset      = $resp->Charset;
            my $content_type = $resp->ContentType;
            $content_type .= "; charset=$charset" if $charset;
            $c->response->content_type( $content_type );
            $resp->_flush_Cookies( $c );
            $c->response->header( Cache_Control => $resp->CacheControl );
            $c->response->header( Expires => time2str( time + $resp->Expires ) ) if $resp->Expires;
            $c->response->status( $resp->Status || 200 );
            $c->response->body( $resp->Body );



( run in 0.694 second using v1.01-cache-2.11-cpan-39bf76dae61 )