CGI::ConvertParam - Decorator class which adds several hook to CGI::param().
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');
CGI::ConvertParam and the subclass are Decorator which adds some hooks to the CGI::param() method.
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');
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');
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');
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.
convert_all_param()
This method is convert the all named parameter.
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.
This method is called by convert_all_param() method. The do_convert_all_param() method shuld be used to define the converter.
query()
This method is return the original CGI instance.
OYAMA Hiroyuki <oyama@crayfish.co.jp> http://perl.infoware.ne.jp/
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.