| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #response object | 
| 2 |  |  |  |  |  |  | package CGI::Mungo::Response::Raw; | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | =pod | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | =head1 NAME | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | Response Raw - Raw text view plugin | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | my $response = $mungo->getResponse(); | 
| 13 |  |  |  |  |  |  | $response->setContent("Hello World"); | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | This view plugin allows you to simply append content to the resulting web page. | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | Content is displayed at the end of the page request. | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | =head1 METHODS | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | =cut | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 3 |  |  | 3 |  | 6915 | use strict; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 106 |  | 
| 26 | 3 |  |  | 3 |  | 18 | use warnings; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 112 |  | 
| 27 | 3 |  |  | 3 |  | 19 | use base ("CGI::Mungo::Response::Base"); | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 1600 |  | 
| 28 |  |  |  |  |  |  | ######################################################### | 
| 29 |  |  |  |  |  |  | sub new{ | 
| 30 | 2 |  |  | 2 | 1 | 6 | my($class, $mungo) = @_; | 
| 31 | 2 |  |  |  |  | 20 | my $self = $class->SUPER::new($mungo); | 
| 32 | 2 |  |  |  |  | 7 | $self->{'_outputContent'} = ""; | 
| 33 | 2 |  |  |  |  | 5 | bless $self, $class; | 
| 34 | 2 |  |  |  |  | 8 | return $self; | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  | ######################################################### | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =head2 setContent() | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | $response->setContent("Hello World"); | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | Append a scalar string to the current web page content. If an undefined value is passed any | 
| 43 |  |  |  |  |  |  | currently defined content will be removed. | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | =cut | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | ######################################################### | 
| 48 |  |  |  |  |  |  | sub setContent{ | 
| 49 | 2 |  |  | 2 | 1 | 537 | my($self, $content) = @_; | 
| 50 | 2 | 50 |  |  |  | 7 | if($content){ | 
| 51 | 2 |  |  |  |  | 6 | $self->{'_outputContent'} .= $content; | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  | else{	#clear the current content | 
| 54 | 0 |  |  |  |  | 0 | $self->{'_outputContent'} = ""; | 
| 55 |  |  |  |  |  |  | } | 
| 56 | 2 |  |  |  |  | 10 | return 1; | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  | ######################################################### | 
| 59 |  |  |  |  |  |  | sub display{	#this sub will display the page headers if needed | 
| 60 | 0 |  |  | 0 | 0 | 0 | my $self = shift; | 
| 61 | 0 |  |  |  |  | 0 | my $output; | 
| 62 | 0 | 0 |  |  |  | 0 | if($self->_getDisplayedHeader()){	#just display more content | 
| 63 | 0 |  |  |  |  | 0 | $output = $self->_getContent();	#get the contents of the template | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  | else{	#first output so display any headers | 
| 66 | 0 | 0 |  |  |  | 0 | if(!$self->header("Content-type")){	#set default content type | 
| 67 | 0 |  |  |  |  | 0 | $self->header("Content-type" => "text/html"); | 
| 68 |  |  |  |  |  |  | } | 
| 69 | 0 | 0 |  |  |  | 0 | if(!$self->header("Location")){	#if we dont have a redirect | 
| 70 | 0 |  |  |  |  | 0 | my $content = $self->_getContent();	#get the contents of the template | 
| 71 | 0 |  |  |  |  | 0 | $self->content($content); | 
| 72 |  |  |  |  |  |  | } | 
| 73 | 0 | 0 | 0 |  |  | 0 | if($self->getError() && $self->code() =~ m/^[123]/){	#set the error code when needed | 
| 74 | 0 |  |  |  |  | 0 | $self->code(500); | 
| 75 | 0 |  |  |  |  | 0 | $self->message('Internal Server Error'); | 
| 76 |  |  |  |  |  |  | } | 
| 77 | 0 |  |  |  |  | 0 | $output = "Status: " . $self->as_string(); | 
| 78 |  |  |  |  |  |  | } | 
| 79 | 0 |  |  |  |  | 0 | print $output; | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 0 |  |  |  |  | 0 | $self->_setDisplayedHeader();	#we wont display the header again | 
| 82 | 0 |  |  |  |  | 0 | return 1; | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  | ######################################################### | 
| 85 |  |  |  |  |  |  | # private methods | 
| 86 |  |  |  |  |  |  | ######################################################## | 
| 87 |  |  |  |  |  |  | sub _getContent{ | 
| 88 | 3 |  |  | 3 |  | 6 | my $self = shift; | 
| 89 | 3 | 100 |  |  |  | 18 | if($self->getError()){ | 
| 90 | 1 |  |  |  |  | 3 | return "Error: " . $self->getError(); | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  | else{ | 
| 93 | 2 |  |  |  |  | 8 | return $self->{'_outputContent'}; | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  | } | 
| 96 |  |  |  |  |  |  | ########################################################### | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | =pod | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | =head1 Author | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | MacGyveR | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | Development questions, bug reports, and patches are welcome to the above address | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | =head1 Copyright | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | Copyright (c) 2011 MacGyveR. All rights reserved. | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | =cut | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | ################################################################################## | 
| 115 |  |  |  |  |  |  | return 1; |