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::Adapter - Creates a case-insensitive hash

SYNOPSIS

  use CGI qw/header/;
  use Blosxom::Header::Adapter;

  my %adaptee = ( -type => 'text/plain' );

  tie my %adapter => 'Blosxom::Header::Adapter' => \%adaptee;

  $adapter{Content_Length} = 1234;

  print header( %adaptee );
  # Content-length: 1234
  # Content-Type: text/plain; charset=ISO-8859-1
  #

DESCRIPTION

Creates a case-insensitive hash.

BACKGROUND

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

  package blosxom;
  use strict;
  use warnings;
  use CGI qw/header/;

  our $header = { -type => 'text/html' };

  # Loads plugins

  print header( $header );

Plugins may modify $header directly because the variable is global. On the other hand, header() doesn't care whether keys of $header are lowercased nor start with a dash. There is no agreement with how to normalize keys of $header.

HOW THIS MODULE NORMALIZES FIELD NAMES

To specify field names consistently, we need to normalize them. If you follow one of normalization rules, you can modify $header consistently. This module normalizes them as follows.

Remember how Blosxom initializes $header:

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

A key -type is starting with a dash and lowercased, and so this module follows the same rules:

  'Status'  # not normalized
  'status'  # not normalized
  '-status' # normalized

How about Content-Length? It contains a dash. To avoid quoting when specifying hash keys, this module transliterates dashes into underscores in field names:

  'Content-Length'  # not normalized
  '-content-length' # not normalized
  '-content_length' # normalized

If you follow the above normalization rule, you can modify $header directly. In other words, this module is compatible with the way modifying $header directly when you follow the above rule.

METHODS

$adapter = tie %adapter, 'Blosxom::Header::Adapter', \%adaptee

Associates a new hash instance with Blosxom::Header::Adapter.

$adapter{ $field } = $value
$value = $adapter{ $field }
$deleted = delete $adapter{ $field }
$bool = exists $adapter{ $field }
$bool = %adapter
$field = each %adapter
( $field, $value ) = each %adapter
%adapter = ()

A shortcut for

  %adaptee = ( -type => q{} );
$adapter->nph()
$adapter->attachment()
$adapter->has_date_header()

DIAGONOSTICS

The Date header is fixed

You attempted to modify the Date header when any of <-cookie>, -nph or -expires was set. See Blosxom::Header::date().

SEE ALSO

Blosxom::Header, perltie

AUTHOR

Ryo Anazawa (anazawa@cpan.org)

LICENSE AND COPYRIGHT

Copyright (c) 2011-2012 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.