飛鳥 真一郎 > CGI-Application-Plugin-Eparam-0.04f > CGI::Application::Plugin::Eparam::Nihongo

Download:
CGI-Application-Plugin-Eparam-0.04f.tar.gz

Annotate this POD

View/Report Bugs
Source  

Name ^

CGI::Application::Plugin::Eparam::Nihongo

SYNOPSIS ^

    package WebApp
    use Jcode;# この他 use Encode するか、自前で $CGI::Application::Plugin::Eparam::econv = sub { ... } と、変換ロジックを実装する
    use CGI::Application::Plugin::Eparam;
    sub cgiapp_init {
            $CGI::Application::Plugin::Eparam::icode = 'sjis';   # 入力される文字コード
            $CGI::Application::Plugin::Eparam::ocode = 'euc-jp'; # 変換したい文字コード
    }
    package WebApp::Pages::Public
    sub page1 {
            my $self = shift;
            my $data = $self->eparam('data');               # 変換後の値
            my $natural_data = $self->query->param('data'); # 変換前の値
    }

Example ^

Get Value

    package WebApp::Pages::Public
    sub page1 {
            my $self = shift;
            my $data = $self->eparam('data');
            my $natural_data = $self->query->param('data');
    }

in Application

    package WebApp
    use Jcode;
    use CGI::Application::Plugin::Eparam;
    sub cgiapp_init {
            $CGI::Application::Plugin::Eparam::icode = 'sjis';
            $CGI::Application::Plugin::Eparam::ocode = 'euc-jp';
    }

in SubClass

    package WebApp::Pages::Public
    sub setup {
            $CGI::Application::Plugin::Eparam::icode = 'sjis';
            $CGI::Application::Plugin::Eparam::ocode = 'euc-jp';
    }
    package WebApp::Pages::Admin
    sub setup {
            $CGI::Application::Plugin::Eparam::icode = 'euc-jp';
            $CGI::Application::Plugin::Eparam::ocode = 'euc-jp';
    }

in Method

    package WebApp::Pages::User::Mailform
    sub mailform {

            # この場合変換は行われません
            $CGI::Application::Plugin::Eparam::icode = 'jis';
            $CGI::Application::Plugin::Eparam::ocode = 'jis';

            # メールの件名にしたい部分だけをjisで得るような事が出来ます
            $CGI::Application::Plugin::Eparam::icode = 'sjis';
            $CGI::Application::Plugin::Eparam::ocode = 'jis';

    }

in Part

    package Myapplication::Pages::User::Mailform
    sub mailform {

            # 一時的に設定を変更する事が出来ます
            $CGI::Application::Plugin::Eparam::temp_icode = 'sjis';
            $CGI::Application::Plugin::Eparam::temp_ocode = 'jis';
            my $val_jis = $self->eparam('val');
            # undefで元に戻せます
            undef $CGI::Application::Plugin::Eparam::temp_icode;
            undef $CGI::Application::Plugin::Eparam::temp_ocode;
            my $val_sjis = $self->eparam('val');

    }

Convert Logic Customize

    # 自分で変換ロジックを組む事が出来ます
    $CGI::Application::Plugin::Eparam::econv = sub {
            my $textref = shift; 
            my $ocode = shift;   # output character code
            my $icode = shift;   # input  character code
            # some logic
            Encode::from_to($$textref, 'Guess', $ocode);
    };
    # temp_を使うと一時的なものになります
    $CGI::Application::Plugin::Eparam::temp_econv = sub {
            my $textref = shift; 
            my $ocode = shift;   # output character code
            my $icode = shift;   # input  character code
            # some logic
            Encode::from_to($$textref, 'Guess', $ocode);
    };
    # undefで元に戻します
    undef $CGI::Application::Plugin::Eparam::temp_econv;

SEE ALSO ^

CGI::Application

AUTHOR ^

Shinichiro Aska

syntax highlighting: