| 1 | package CatalystX::ASP::View; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use CatalystX::ASP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use HTTP::Date qw(time2str); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | extends 'Catalyst::View'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | has 'asp' => ( | |||||||||||||||||||||||||||||||||||||||||
| 13 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | isa => 'CatalystX::ASP', | ||||||||||||||||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | CatalystX::ASP::View - Catalyst View for processing ASP scripts | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | package MyApp::Controller::Foo; | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | sub 'asp' : Regex('\.asp$') { | ||||||||||||||||||||||||||||||||||||||||||
| 26 | my ($self, $c, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | $c->forward( $c->view( 'ASP' ), \@args ); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | This is the Catalyst View to handle ASP scripts. Given a C<$path> to the ASP | ||||||||||||||||||||||||||||||||||||||||||
| 33 | script, this will render the ASP script and populate C<< $c->response >> with | ||||||||||||||||||||||||||||||||||||||||||
| 34 | the computed headers and body. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | =item $self->process($c, @args) | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | Takes a C<$path> or guesses base off C<< $c->request->path >>. After ASP | ||||||||||||||||||||||||||||||||||||||||||
| 43 | renders the output, this will populate C<< $c->response >> accordingly | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | ▶ | sub process { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=1 SCAR=0.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | my ( $self, $c, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 9 | my $path = join '/', @args; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 9 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 9 | $self->render( $c, $path ); | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 7 | my $resp = $self->asp->Response; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 7 | my $status = $resp->Status; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 7 | ▶ | if ( $status >= 500 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $c->error( "Erroring out because HTTP Status set to $status" ); | |||||||||||||||||||||||||||||||||||||||||
| 59 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 7 | my $charset = $resp->Charset; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 7 | my $content_type = $resp->ContentType; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 7 | ▶ | $content_type .= "; charset=$charset" if $charset; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 7 | $c->response->content_type( $content_type ); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 7 | $resp->_flush_Cookies( $c ); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 7 | $c->response->header( Cache_Control => $resp->CacheControl ); | |||||||||||||||||||||||||||||||||||||||||
| 66 | 7 | ▶ | $c->response->header( Expires => time2str( time + $resp->Expires ) ) if $resp->Expires; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 7 | ▶ | $c->response->status( $resp->Status || 200 ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$resp->Status || 200
MC/DC100%1/1
$resp->Status || 200
$resp->Status
Truth table100%2/2
A
A= $resp->Status
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 7 | $c->response->body( $resp->Body ); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=32.3
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | # Passthrough $c->detach | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | $_->rethrow if blessed( $_ ) && $_->isa( 'Catalyst::Exception::Detach' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($_) and $_->isa("Catalyst::Exception::Detach")
MC/DC0%0/2
builtin::blessed($_) and $_->isa("Catalyst::Exception::Detach")
builtin::blessed($_)
$_->isa("Catalyst::Exception::Detach")
Truth table33%1/3
A and B
A= builtin::blessed($_)B= $_->isa("Catalyst::Exception::Detach")
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # If error in other ASP code, return HTTP 500 | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ( blessed( $_ ) && !$_->isa( 'CatalystX::ASP::Exception::End' ) && !$c->has_errors ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
builtin::blessed($_) and not $_->isa("CatalystX::ASP::Exception::End") and not $c->has_errors
builtin::blessed($_) and not $_->isa("CatalystX::ASP::Exception::End")
MC/DC0%0/3
builtin::blessed($_) and not $_->isa("CatalystX::ASP::Exception::End") and not $c->has_errors
builtin::blessed($_)
not $_->isa("CatalystX::ASP::Exception::End")
not $c->has_errors
Truth table0%0/4
A and not(B) and not(C)
A= builtin::blessed($_)B= not $_->isa("CatalystX::ASP::Exception::End")C= not $c->has_errors
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $c->error( "Encountered application error: $_" ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 9 | ▶ | } finally { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | # Ensure destruction! | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 9 | $self->asp->cleanup; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 9 | }; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | =item $self->render($c, $path) | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | This does the bulk work of ASP processing. First parse file, the compile. During | ||||||||||||||||||||||||||||||||||||||||||
| 91 | execution, kick off any hooks configured. Finally, properly handle errors, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | passing through C<< $c->detach >> if called as a result of | ||||||||||||||||||||||||||||||||||||||||||
| 93 | C<< $Response->Redirect >> or C<< $Response->End >> if called in ASP script. | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 9 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=3 SCAR=12.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 9 | my ( $self, $c, $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | # Create localized ENV because ASP modifies and assumes ENV being populated | ||||||||||||||||||||||||||||||||||||||||||
| 101 | # with Request headers as in CGI | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 9 | local %ENV = %ENV; | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 9 | my $asp = $self->asp; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 9 | ▶ | if ( $asp ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 9 | $asp->c( $c ); | |||||||||||||||||||||||||||||||||||||||||
| 107 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $asp = CatalystX::ASP->new( %{ $c->config->{'CatalystX::ASP'} }, c => $c ); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $self->asp( $asp ); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 9 | ▶ | my $compiled = $asp->compile_file( $c, $c->path_to( 'root', $path || $c->request->path ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$path || $c->request->path
MC/DC0%0/2
$path || $c->request->path
$path
$c->request->path
Truth table33%1/3
A || B
A= $pathB= $c->request->path
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 9 | $asp->GlobalASA->Script_OnStart; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 9 | $asp->execute( $c, $compiled->{code} ); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 7 | $asp->GlobalASA->Script_OnFlush; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | =item * L<CatalystX::ASP> | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | =item * L<CatalystX::ASP::Role> | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | =back | ||||||||||||||||||||||||||||||||||||||||||