| Tripletail documentation | Contained in the Tripletail distribution. |
Tripletail::Filter::MemCached - MemCached を使用するときに使用するフィルタ
$TL->setContentFilter('Tripletail::Filter::MemCached',key => 'key', mode => 'pass-through', form => $form, formcharset => 'Shift_JIS', cachedata => $cachedata);
MemCached の使用を支援する。 このフィルタを使用する場合、最後に使用しなければならない。
MemCached で使用する key を設定する。
MemCached への書き込みか、 MemCached からの読み込みかを選択する。
write で書き込み、pass-throughで読み込み。省略可能。
デフォルトはwrite。
inで書き込みをする際に、出力文字列中に最後に埋め込みを行う情報をTripletail::Form クラスのインスタンスで指定する。 Tripletail::Formクラスのキーが出力文字列中に存在している場合、値に置換する。省略可能。
formの値をUTF-8から変換する際の文字コードを指定する。省略可能。
使用可能なコードは次の通り。 UTF-8,Shift_JIS,EUC-JP,ISO-2022-JP
デフォルトはShift_JIS。
pass-through時のみに使用される。
出力する MemCached のデータを渡す。
直接出力されるため、ヘッダや文字コードに注意する必要がある。
Copyright 2006 YMIRLINK Inc.
This framework is free software; you can redistribute it and/or modify it under the same terms as Perl itself
このフレームワークはフリーソフトウェアです。あなたは Perl と同じライセンスの 元で再配布及び変更を行うことが出来ます。
Address bug reports and comments to: tl@tripletail.jp
HP : http://tripletail.jp/
| Tripletail documentation | Contained in the Tripletail distribution. |
# ----------------------------------------------------------------------------- # Tripletail::Filter::MemCached - MemCachedã使ç¨ããã¨ãã«ä½¿ç¨ãããã£ã«ã¿ # ----------------------------------------------------------------------------- package Tripletail::Filter::MemCached; use strict; use warnings; use Tripletail; require Tripletail::Filter; our @ISA = qw(Tripletail::Filter); # ãã®ãã£ã«ã¿ã¯å¿ ãæå¾ã«å¼ã³åºãããªããã°ãªããªãã # ãªãã·ã§ã³ä¸è¦§: # * key => MemCachedããèªã¿è¾¼ãéã®ãã¼ # * mode => MemCachedã¸ã®æ¸ãè¾¼ã¿(write)ããMemCachedããã®åºå(pass-through)ãã # * form => æ¸ãè¾¼ã¿æã«åãè¾¼ããã¼ã¿ãTripletail::Fromã¯ã©ã¹ã®å½¢ã§æ¸¡ãã # * formcharset => æ¸ãè¾¼ã¿æã«åãè¾¼ããã¼ã¿ã夿ããããã®ãåºåã®æåã³ã¼ãã(UTF-8ãã夿ããã) # ããã©ã«ã: Shift_JIS # * cachedata => ã¡ã¢ãªã¼ã«ãã£ãã·ã¥ããã¦ãããã¼ã¿ã渡ãã 1; sub _new { my $class = shift; my $this = $class->SUPER::_new(@_); # ããã©ã«ãå¤ãåããã my $defaults = [ [formcharset => 'Shift_JIS'], [key => undef], [mode => 'in'], [form => undef], [cachedata => undef], ]; $this->_fill_option_defaults($defaults); # ãªãã·ã§ã³ã®ãã§ã㯠my $check = { formcharset => [qw(defined no_empty scalar)], key => [qw(defined no_empty scalar)], mode => [qw(defined no_empty scalar)], form => [qw(no_empty)], cachedata => [qw(no_empty scalar)], }; $this->_check_options($check); if($this->{option}{mode} ne 'write' && $this->{option}{mode} ne 'pass-through') { die "TL#setContentFilter: option [mode] for [Tripletail::Filter::MemCache] ". "must be 'write' or 'pass-through', not [$this->{option}{mode}].". " (modeã¯writeãpass-throughã®ãããããæå®ãã¦ãã ãã)\n"; } if($this->{option}{mode} eq 'pass-through' && defined($this->{option}{cachedata})) { $this->{buffer} = $this->{option}{cachedata}; } else { $this->{buffer} = ''; } $this; } sub print { my $this = shift; my $data = shift; if(ref($data)) { die __PACKAGE__."#print: arg[1] is a reference. [$data] (第1弿°ããªãã¡ã¬ã³ã¹ã§ã)\n"; } return '' if($data eq ''); if($this->{option}{mode} eq 'write') { $this->{buffer} .= $data; } else { if($this->{buffer} eq '') { $this->{buffer} = $data; } else { die __PACKAGE__."#print: some data have already been printed. (æ¢ã«ä½ããã®åºåãããã¦ãã¾ã)\n"; } } ''; } sub flush { my $this = shift; my $output; if($this->{option}{mode} eq 'write') { my $nowtime = time; $output = q{Last-Modified: } . $TL->newDateTime->setEpoch($nowtime)->toStr('rfc822') . qq{\r\n} . $this->{buffer}; my $value = $nowtime . q{,} . $output; $TL->newMemCached->set($this->{option}{key},$value); if(defined($this->{option}{form})) { foreach my $key2 ($this->{option}{form}->getKeys){ my $val = $TL->charconv($this->{option}{form}->get($key2), 'UTF-8' => $this->{option}{formcharset}); $output =~ s/$key2/$val/g; } } } else { $output = $this->{buffer}; } $output; } sub reset { my $this = shift; $this->SUPER::reset; $this->{buffer} = ''; $this; } __END__