The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Egg::Response - WEB response processing for Egg.

SYNOPSIS

  # The object is acquired.
  my $res= $e->response;
  
  # The contents type is set.
  $res->content_type('text/plain');
   
  # The cache control is set.
  $res->no_cache(1);
    
  # The output contents are set.
  $res->body('Hell world !!');
  
  # The enhancing header is set.
  $res->headers->{'My-Header'}= 'OK';
  
  # Cookie is set.
  $res->cookie( hoge => 'boo' );
  
  # It redirects it.
  $res->redirect('http://ho.com/hellow.html', '302');
  
  # The response header is generated.
  my $scalar_ref= $res->header;

DESCRIPTION

The WEB response processing for the Egg framework is done.

METHODS

The main body of this module is built into the component of the project.

response

The handler object of this module is returned.

  • res

HANDLER METHODS

new

Constructor. It is not necessary to call from the application.

  my $res= $e->response;

body ([BODY_STRING])

Output contents are maintained.

The maintained data is always done by the SCALAR reference.

Undef is set when 0 is given to BODY_STRING and it initializes it.

  my $scalar_ref= $res->body(<<END_BODY);
  Hellow world !!
  END_BODY

headers

Egg::Response::Headers object is returned.

The response header not supported by this module can be set by this.

  $res->headers->{'X-MyHader'}= 'hoge';

header ([BODY_SCALAR_REF])

It returns it making the response header. Egg calls this by a series of processing. It is not necessary to call it from the project.

To measure Content-Length, BODY_SCALAR_REF is passed. $res->body is used when omitted.

The returned value is SCALAR always reference.

content_type ([STRING])

To generate the Content-Type header by the header method, it sets it.

It can be overwrited that content_type is set to the configuration though default is 'text/html'.

Moreover, when the contents type of default is output, it is not necessary to call 'content_type'.

  $res->content_type('text/javascript');

content_language ([STRING])

To generate the Content-Language header by the header method, it sets it.

The Content-Language header is not usually output because there is no default.

  $res->content_language('ja');

no_cache ([BOOL])

It is a flag to generate the header for the cash control by the header method.

  $res->no_cache(1);

nph ([BOOL])

It is a flag to generate the header of NPH scripting by the header method.

  $res->nph(1);

* However, please note the thing not behaving like the NPH script in usual processing about Egg.

no_content_length ([BOOL])

It is a flag so as not to output the Content-Length header.

  $e->no_content_length(1);

The Content-Length header is not output at the following time.

  • It is possible to overwrite in 'no_content_length_regex' of the configuration though default is qr{(?:^text/|/(?:rss\+)?xml)} when matching it to the putter of $res->{no_content_length_regex}.

  • When $e->request->is_head returns ture.

  • When $res->body returns undefined.

is_expires ([ARGS])

To generate the Expires header by the header method, it sets it.

ARGS is a value passed to the expires function of CGI::Util.

  $res->is_expires('+1D');

last_modified ([ARGS])

To generate the Last-Modified header by the header method, it sets it.

ARGS is a value passed to the expires function of CGI::Util.

  $res->last_modified('+1D');

cookies

The HASH reference to set Cookie is returned.

Returned HASH is the one having made it by Egg::Response::TieCookie.

  $res->cookies->{'Hoo'}= '123';

When 'p3p_policy' of the configuration is defined, the value is set if the p3p method is still undefined. Please set 'p3p_policy' to the configuration when you want to transmit the P3P header when Cookie is output.

  package MyApp::config;
  sub out { {
    .............
    ........
    p3p_policy => 'UNI CUR OUR',
    ........
  } }

The list of the key to the data that has been set to omit the argument is returned.

The content of Cookie that corresponds more than the data set to give KEY is returned.

When VALUE is given, Cookie is set.

  my @key_list= $res->cookie;
  
  my $hoo= $res->cookie('Hoo');
  
  $res->cookie( Boo => '456' );

status ([STATUS])

The response status is set.

The following forms are accepted.

  $res->status(403);
  $res->status('403 Forbiden');
  $res->status(403, 'Forbiden');

When the text part is omitted, the value corresponding to status is set from %Egg::Response::Status. The response code not supported by this module can be customized by adding it to %Egg::Response::Status.

0 Is initialized when giving it.

status_string

The text defined by the status method is returned. When the returned value exists, half angle space is sure to be included in the head.

  my $status= 'Status: '. $res->status. $res->status_string;

redirect ([URI], [STATUS_CODE], [OPTION_HASH])

It is prepared to generate Ridairectoheddar.

URL is concretely set in the location method, and STATUS_CODE is set in the status method. And, the result of $e->finished is returned at the end.

There is no default of URL. Please specify it.

The default of STATUS_CODE is 302.

The window target can be specified with OPTION_HASH.

  $res->redirect('/hoge', 302, target=> '_top' );

0 Is canceled when giving it.

location ([URI])

To generate the Location header with the header, it sets it.

This is usually called in the redirect method and set.

Please note no desire as redirecting even if only this method is set.

The value that has already been set is returned at the URI unspecification.

window_target ([TARGET_STRING])

Window-Target is set.

  $res->window_target('foo');

* Because it is the one set in the response header, this is evaluated depending on a browser of the client. Especially, this header might been deleted as for the client that is via the proxy. I do not think that it is in certain target specification.

content_encoding ([ENCODING_STRING])

Content-Encoding is set.

  $res->content_encoding('identity');

content_disposition ([FILE_NAME])

Content-Disposition is set.

This is used to specify the file name when it is made to download.

  $res->content_disposition('myname.txt');
  
  # It is output to the header as follows. 
  Content-Disposition: attachment; filename=myname.txt
  • Alias = attachment

p3p ([SIMPLE_POLICY])

P3P is set.

SIMPLE_POLICY gives the character string of the ARRAY reference or the half angle space district switching off.

  $res->p3p('UNI CUR OUR');
  
  # It is output to the header as follows.
  P3P: policyref="/w3c/p3p.xml", CP="UNI CUR OUR"

clear_body

Undef is set in the value of body and it initializes it.

clear_cookies

The set Cookie data is annulled. And, if the P3P header is set, it also initializes it.

clear

no_cache, no_content_length, content_type, content_language, nph, headers, and clear_cookies are done in this method.

Please note that body is not cleared.

SEE ALSO

Egg::Release Egg::Response::Headers, Egg::Response::TieCookie, CGI::Cookie, CGI::Util, Egg::Base,

AUTHOR

Masatoshi Mizuno <lushe@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2008 Bee Flag, Corp. <http://egg.bomcity.com/>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.