| 1 | package OpenFrame::Segment::HTTP::Response; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | #no strict 'subs'; | ||||||||||||||
| 6 | |||||||||||||||
| 7 | 1 | ▶ | use warnings::register; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 1 | ▶ | use CGI::Cookie; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | ▶ | use HTTP::Status; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | ▶ | use HTTP::Headers; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 1 | ▶ | use HTTP::Response; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 1 | ▶ | use Pipeline::Segment; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 1 | ▶ | use OpenFrame::Object; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | 1 | ▶ | use OpenFrame::Response; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | 1 | ▶ | use base qw ( Pipeline::Segment OpenFrame::Object ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | |||||||||||||||
| 19 | 1 | our $VERSION=3.05; | |||||||||||||
| 20 | |||||||||||||||
| 21 | 1 | ▶ | sub dispatch { | ||||||||||||
|
Subroutine
dispatch: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 22 | 1 | my $self = shift; | |||||||||||||
| 23 | 1 | my $store = shift->store(); | |||||||||||||
| 24 | |||||||||||||||
| 25 | 1 | my $response; | |||||||||||||
| 26 | |||||||||||||||
| 27 | 1 | my $cookies = $store->get( 'OpenFrame::Cookies' ); | |||||||||||||
| 28 | 1 | $response = $store->get( 'OpenFrame::Response' ); | |||||||||||||
| 29 | |||||||||||||||
| 30 | 1 | ▶ | if (!$response) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 31 | ## time to make an error response | ||||||||||||||
| 32 | 1 | $response = OpenFrame::Response->new(); | |||||||||||||
| 33 | 1 | $response->code( ofERROR() ); | |||||||||||||
| 34 | 1 | $response->message( | |||||||||||||
| 35 | q{ | ||||||||||||||
| 36 | <h1>There was an error processing your request</h1> | ||||||||||||||
| 37 | <p>No segments produced an OpenFrame::Response object</p> | ||||||||||||||
| 38 | } | ||||||||||||||
| 39 | ); | ||||||||||||||
| 40 | 1 | $self->error("no response available"); | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 1 | return $self->ofr2httpr( $response, $cookies ); | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | ## | ||||||||||||||
| 47 | ## turns an openframe response to an http response | ||||||||||||||
| 48 | ## | ||||||||||||||
| 49 | 1 | ▶ | sub ofr2httpr { | ||||||||||||
|
Subroutine
ofr2httpr: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||
| 50 | 1 | my $self = shift; | |||||||||||||
| 51 | 1 | my $ofr = shift; | |||||||||||||
| 52 | 1 | my $cookies = shift; | |||||||||||||
| 53 | 1 | my $h; | |||||||||||||
| 54 | |||||||||||||||
| 55 | 1 | ▶ | if ( defined( $cookies ) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 56 | 1 | my %cookies = $cookies->get_all(); | |||||||||||||
| 57 | 1 | $h = HTTP::Headers->new(); | |||||||||||||
| 58 | 1 | $h->header('Set-Cookie' => [values(%cookies)]); | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | |||||||||||||||
| 61 | 1 | my $status = $self->ofcode2status( $ofr ); | |||||||||||||
| 62 | 1 | ▶ | if ($status eq RC_FOUND) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 63 | 0 | $h->header('Location' => $ofr->message()); | |||||||||||||
| 64 | } | ||||||||||||||
| 65 | |||||||||||||||
| 66 | 1 | my $mesg = HTTP::Response->new( | |||||||||||||
| 67 | $status, | ||||||||||||||
| 68 | undef, | ||||||||||||||
| 69 | $h, | ||||||||||||||
| 70 | $ofr->message(), | ||||||||||||||
| 71 | ); | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 1 | ▶ | $mesg->content_type( $ofr->mimetype || "text/html" ); | ||||||||||||
|
Condition50%1/2
$ofr->mimetype || 'text/html'
MC/DC0%0/1
$ofr->mimetype || 'text/html'
$ofr->mimetype
Truth table50%1/2
A
A= $ofr->mimetype
| |||||||||||||||
| 74 | |||||||||||||||
| 75 | 1 | return $mesg; | |||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 1 | ▶ | sub ofcode2status { | ||||||||||||
|
Subroutine
ofcode2status: called CC=3 SCAR=12.7
Pod
undocumented
| |||||||||||||||
| 79 | 1 | my $self = shift; | |||||||||||||
| 80 | 1 | my $ofr = shift; | |||||||||||||
| 81 | 1 | ▶ | if ($ofr->code() eq ofOK()) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 82 | 0 | return RC_OK; | |||||||||||||
| 83 | } elsif ($ofr->code() eq ofREDIRECT()) { | ||||||||||||||
| 84 | 0 | return RC_FOUND; | |||||||||||||
| 85 | } else { | ||||||||||||||
| 86 | 1 | return RC_INTERNAL_SERVER_ERROR; | |||||||||||||
| 87 | } | ||||||||||||||
| 88 | } | ||||||||||||||
| 89 | |||||||||||||||
| 90 | 1 | 1; | |||||||||||||
| 91 | |||||||||||||||
| 92 | =head1 NAME | ||||||||||||||
| 93 | |||||||||||||||
| 94 | OpenFrame::Segment::HTTP::Response - creates an HTTP::Response object from an OpenFrame::Response | ||||||||||||||
| 95 | |||||||||||||||
| 96 | =head1 SYNOPSIS | ||||||||||||||
| 97 | |||||||||||||||
| 98 | use OpenFrame::Segment::HTTP::Response; | ||||||||||||||
| 99 | my $response_creator = OpenFrame::Segment::HTTP::Response->new(); | ||||||||||||||
| 100 | $pipeline->add_segment( $response ); | ||||||||||||||
| 101 | |||||||||||||||
| 102 | =head1 DESCRIPTION | ||||||||||||||
| 103 | |||||||||||||||
| 104 | OpenFrame::Segment::HTTP::Response inherits from Pipeline::Segment and is used to turn an | ||||||||||||||
| 105 | OpenFrame::Response object into an HTTP::Response. | ||||||||||||||
| 106 | |||||||||||||||
| 107 | =head1 AUTHOR | ||||||||||||||
| 108 | |||||||||||||||
| 109 | James A. Duncan <jduncan@fotango.com> | ||||||||||||||
| 110 | |||||||||||||||
| 111 | =head1 SEE ALSO | ||||||||||||||
| 112 | |||||||||||||||
| 113 | OpenFrame::Segment::HTTP::Request, Pipeline::Segment | ||||||||||||||
| 114 | |||||||||||||||
| 115 | =cut | ||||||||||||||
| 116 | |||||||||||||||
| 117 | |||||||||||||||
| 118 | |||||||||||||||
| 119 | |||||||||||||||
| 120 | |||||||||||||||
| 121 | |||||||||||||||
| 122 | |||||||||||||||
| 123 | |||||||||||||||
| 124 | |||||||||||||||
| 125 | |||||||||||||||