CGI::ConvertParam - Decorator class which adds several hook to CGI::param.


NAME

CGI::ConvertParam - Decorator class which adds several hook to CGI::param().


SYNOPSIS

  package CGI::ConvertParam::OngetUTF8;
  use base 'CGI::ConvertParam';
  use Jcode;
  sub do_convert_on_get
  {
      my $self = shift;
      my $parameter_value = shift;
      return Jcode->new($parameter_value)->utf8;
  }
  1;
  package client;
  use CGI;
  use CGI::ConvertParam::OngetUTF8;
  $query = CGI::ConvertParam::OngetUTF8->new(CGI->new);
  print $query->param('parameter_foo');


DESCRIPTION

CGI::ConvertParam and the subclass are Decorator which adds some hooks to the CGI::param() method.


EXAMPLE

All parameters are converted to EUC-JP

  package CGI::ConvertParam::EUC;
  use base 'CGI::ConvertParam';
  use Jcode;
  sub initialize
  {
      my $self = shift;
      $self->convert_all_param;
  }
  sub do_convert_all
  {
      my $self    = shift;
      my $strings = shift;
      return Jcode->new($strings)->euc;
  }
  1;
  package main;
  use CGI;
  use CGI::ConvertParam::EUC;
  my $query = CGI::ConvertParam::EUC->new(CGI->new);
  print 'Name(EUC-JP):', $query->param('NAME');

Convert Shift-JIS on Setting the value or values of a named parameter:

  package CGI::ConvertParam::OnsetShiftJIS;
  use base 'CGI::ConvertParam';
  use Jcode;
  sub do_convert_on_set
  {
      my $self    = shift;
      my $strings = shift;
      return Jcode->new($strings)->sjis;
  }
  1;
  package main;
  use CGI;
  use CGI::ConvertParam::OnsetShiftJIS;
  my $query = CGI::ConvertParam::OnsetShiftJIS->new(CGI->new);
  $query->param(NAME => $value);
  print 'Name(Shift-JIS):', $query->param('NAME');

Convert UTF-8 on Fetching the value or values of a named parameter:

  package CGI::ConvertParam::OngetUTF8;
  use base 'CGI::ConvertParam';
  use Jcode;
  sub do_convert_on_get
  {
      my $self    = shift;
      my $strings = shift;
      return Jcode->new($strings)->utf8;
  }
  1;
  package main;
  use CGI;
  use CGI::ConvertParam::OngetUTF8;
  my $query = CGI::ConvertParam::OngetUTF8->new(CGI->new);
  $query->param(NAME => $value);
  print 'Name(UTF-8):', $query->param('NAME');


METHOD

Class method

new(CGI_OBJECT)
The new() method is the constructor for a CGI::ConvertParam and sub-class. CGI_BOJECT is the reference of the CGI instance. It return a specialized CGI instance.

Instance method

convert_all_param()
This method is convert the all named parameter.

Subclassing and Override methods

CGI::ConvertParam implements some methods which are expected to be overridden by implementing them in your subclass module. These methods are as follows:

initialize()
This method is colled by the inherited new() constructor method. The initialize() method should be used to define the following property/methods:

do_convert_on_set()
This method is called by param('name' => $value) method. The do_convert_on_set() method shuld be used to define the converter.

do_convert_on_get()
This method is called by param('name') method. The do_convert_on_get() method shuld be used to define the converter.

do_convert_all_param
This method is called by convert_all_param() method. The do_convert_all_param() method shuld be used to define the converter.

Data-access method

query()
This method is return the original CGI instance.


SEE ALSO

the CGI manpage


AUTHOR

OYAMA Hiroyuki <oyama@crayfish.co.jp> http://perl.infoware.ne.jp/


COPYRIGHT

Copyright(c) 2000, OYAMA Hiroyuki. Japan. All rights reserved.

CGI::ConvertParam class may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit.

 CGI::ConvertParam - Decorator class which adds several hook to CGI::param.