The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Blosxom::Header - Missing interface to modify HTTP headers

SYNOPSIS

  use Blosxom::Header qw(headers);

  my $headers = { -type => 'text/html' };

  my $h = headers($headers);
  my $value = $h->get($key);
  my $bool = $h->exists($key);

  $h->set($key, $value); # overwrites existent header
  $h->remove($key);

  $h->{headers}; # same reference as $headers

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 writers modify HTTP headers, they must write as follows:

  package foo;
  $blosxom::header->{'-type'} = 'text/plain';

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

This module allows you to modify them in an object-oriented way. If loaded, you might write as follows:

  my $h = headers($blosxom::header);
  $h->set('Content-Type' => 'text/plain');

METHODS

$h = Blosxom::Header->new($headers);
$h = headers($headers);

Creates a new Blosxom::Header object. The object holds a reference to the original given $headers argument.

$h->get('foo')

Returns a value of the specified HTTP header.

$h->exists('foo')

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

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

Sets a value of the specified HTTP header.

$h->remove('foo')

Deletes the specified element from HTTP headers.

EXAMPLES

  # plugins/content_length
  package content_length;
  use Blosxom::Header qw(headers);

  sub start { 1 }

  sub last {
      my $h = headers($blosxom::header);
      $h->set('Content-Length' => length $blosxom::output);
  }

DEPENDENCIES

Blosxom 2.1.2

SEE ALSO

The interface of this module is inspired by Plack::Util.

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.