memo.xight.org

/ / memo.xight.org

2006-08-02

Perlでモバイルサイト構築

- Summary
1. User-Agentで端末判別
HTTP::MobileAgentを利用
use HTTP::MobileAgent;
 
my $agent = HTTP::MobileAgent->new;
 
if ($agent->is_docomo){
	    # iモード
} elsif ($agent->is_ezweb){
	    # EZweb
} elsif ($agent->is_vodafone){
	    # Vodafone
}


2. 端末に応じてHTML出力
Template-ToolkitHTTP::MobileAgentを利用
#!/usr/bin/perl
 
use CGI;
use Template;
use HTTP::MobileAgent;
 
my $q = CGI->new;
my $agent = HTTP::MobileAgent->new;
my $tt = Template->new({ABSOLUTE => 1});
 
my $output;
 
# sample.htmlのagentパラメータへ
# HTTP::MobileAgentのインスタンスをセットする
$tt->process('/path/to/sample.html', {agent => $agent}, \$output) or die $Template::ERROR;
 
print $q->header(-charset=>'Shift_JIS');
print $output;
 
exit;

<html>
<body>
[% IF agent.is_docomo %]
iモード
[% ELSIF agent.is_ezweb %]
EZweb
[% ELSIF agent.is_vodafone %]
Vodafone Live!
[% ELSE %]
Non Mobile...
[% END %]
</body>
</html>


3. メールアドレスのキャリア判別
Mail::Address::MobileJp
use Mail::Address::MobileJp;
 
if (is_imode($email)){
	# @docomo.ne.jp
}elsif (is_ezweb($email)){
	# @ezweb.ne.jp or @*.ezweb.ne.jp
}elsif (is_vodafone($email)){
	# @jp-*.ne.jp or @*.vodafone.ne.jp
	# (*にはd,h,t,c,k,r,n,s,qのみが適用となる)
}


4. 絵文字対応
HTML::Entities::ImodePictogram
3キャリア対応の絵文字削除
use CGI;
use HTML::Entities::ImodePictogram;
 
my $q = CGI->new;
 
my $text = $q->param('text');
 
# EZwebの絵文字も削除対象にする
$HTML::Entities::ImodePictogram::ExtPictorgram_re .= '|[\xF3\xF4\xF6\xF7][\x40-\x7E\x80-\xFC]';
 
# iモード、EZwebの絵文字を削除
$text = remove_pictogram($text);
 
# Vodafoneの絵文字を削除
$text =~ s/\x1B\$(.+?)\x0F//g;


- Reference
CodeZine - Perlで作るモバイルサイトのコツ:第1回
http://codezine.jp/a/article.aspx?aid=496

HTTP::MobileAgent
Template-Toolkit
Mail::Address::MobileJp
HTML::Entities::ImodePictogram
カテゴリ: [Perl][Mobile]
2006-08 /

Color Reference

ChangeLogを検索
携帯電話からアクセス!

カテゴリ

最近の話題

リンク

過去ログ

Google

QR Code

Since
2002-11-28
Update
2008-09-05 14:14
Copyright © 2005 xight.org All Rights Reserved.