|
CGI::ConvertParam - Decorator class which adds several hook to CGI::param. |
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');
convert_all_param()
CGI::ConvertParam implements some methods which are expected to be overridden by implementing them in your subclass module. These methods are as follows:
initialize()new() constructor method. The initialize() method should be used to define the following property/methods:
do_convert_on_set()do_convert_on_get()
query()
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.
|
CGI::ConvertParam - Decorator class which adds several hook to CGI::param. |