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

NAME

Blosxom::Header - Missing interface to modify HTTP headers

SYNOPSIS

  # blosxom.cgi
  package blosxom;
  our $header = { -type => 'text/html' };

  # plugins/foo
  package foo;
  use Blosxom::Header;

  my $h     = Blosxom::Header->new($blosxom::header);
  my $value = $h->get('type');
  my $bool  = $h->exists('type');

  $h->set( type => 'text/plain' );
  $h->remove('type');

DESCRIPTION

Blosxom, a weblog application, exports a global variable $header which is a reference to hash. This application passes $header CGI::header() to generate HTTP headers.

When plugin developers modify HTTP headers, they must write as follows:

  package foo;
  $blosxom::header->{'-status'} = '304 Not Modified';

It's obviously bad practice. Blosxom misses the interface to modify them.

This module allows you to modify them in an object-oriented way:

  my $h = Blosxom::Header->new($blosxom::header);
  $h->set(Status => '304 Not Modified');

You don't need to mind whether to put a hyphen before a key, nor whether to make a key lowercased or camelized.

METHODS

$h = Blosxom::Header->new($blosxom::header)

Creates a new Blosxom::Header object.

$h->exists('foo')

Returns a Boolean value telling whether the specified HTTP header exists.

$h->get('foo')

Returns a value of the specified HTTP header.

$h->remove('foo')

Deletes the specified element from HTTP headers.

$h->set('foo' => 'bar')

Sets a value of the specified HTTP header.

EXAMPLES

CGI::header recognizes the following parameters.

attachment

Can be used to turn the page into an attachment. Represents suggested name for the saved file.

  $h->set(attachment => 'foo.png');

In this case, the outgoing header will be formatted as:

  Content-Disposition: attachment; filename="foo.png"
charset

Represents the character set sent to the browser. If not provided, defaults to ISO-8859-1.

  $h->set(charset => 'utf-8');

Represents the Set-Cookie header. The parameter can be an arrayref or a string.

  $h->set(cookie => [$cookie1, $cookie2]);
  $h->set(cookie => $cookie);

Refer to CGI::cookie.

expires

Represents the Expires header. You can specify an absolute or relative expiration interval. The following forms are all valid for this field.

  $h->set(expires => '+30s'); # 30 seconds from now
  $h->set(expires => '+10m'); # ten minutes from now
  $h->set(expires => '+1h' ); # one hour from now
  $h->set(expires => '-1d' ); # yesterday
  $h->set(expires => 'now' ); # immediately
  $h->set(expires => '+3M' ); # in three months
  $h->set(expires => '+10y'); # in ten years time

  # at the indicated time & date
  $h->set(expires => 'Thu, 25 Apr 1999 00:40:33 GMT');
nph

If set to a true value, will issue the correct headers to work with a NPH (no-parse-header) script:

  $h->set(nph => 1);
p3p

Will add a P3P tag to the outgoing header. The parameter can be an arrayref or a space-delimited string.

  $h->set(p3p => [qw(CAO DSP LAW CURa)]);
  $h->set(p3p => 'CAO DSP LAW CURa');

In either case, the outgoing header will be formatted as:

  P3P: policyref="/w3c/p3p.xml" cp="CAO DSP LAW CURa"
type

Represents the Content-Type header.

  $h->set(type => 'text/plain');

DEPENDENCIES

Blosxom 2.1.2

SEE ALSO

CGI

AUTHOR

Ryo Anazawa (anazawa@cpan.org)

LICENSE AND COPYRIGHT

Copyright (c) 2011 Ryo Anazawa. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.