Corporate Perl in Recruit, OpenSocial and Emoji - YAPC::Asia 2009 Tokyo
YAPC::Asia 2009 Tokyo
C
orporate Perl in Recruit,
OpenSocial and Emoji
2009.09.10
Yusuke Kawasaki (kawanet)
Recruit Media Technology Labs
http://mtl.recruit.co.jp/
YAPC::Asia 2009 Tokyo 1
Yusuke Kawasaki(川﨑 有亮)
http://www.kawa.net/
http://twitter.com/kawanet
YAPC::Asia 2009 Tokyo 2
XML::TreePP
• XML string from/to Perl hash object
Pure Perl, fast, easy and stable
• use XML::TreePP;
my $tpp = XML::TreePP->new();
my $hash = {elem=>"value"};
print $tpp->write($hash); # XML string
• my $xml = "<elem>value</elem>";
my $tree = $tpp->parse($xml);
print Dumper($tree); # Perl hash object
YAPC::Asia 2009 Tokyo 4
Emoji
Picture characters commonly
used on mobile phones in Japan
YAPC::Asia 2009 Tokyo 5
Emoji in private code point
• Mobile phone companys use their own code
point in PUA (private use area). Ex. “heart”
• DoCoMo KDDI SoftBank
U+E6EC U+E595 U+E022
SJIS-F991 SJIS-F7B2 SJIS-F962
• We need translation maps for each pair of
Emoji sets.
YAPC::Asia 2009 Tokyo 6
Google’s code points
• Gmail supports “emoticon” characters.
• They also uses PUA again and has their
translation map from/to Japanese Emojis.
• Then, Google’s “emoji4unicode” project has
proposed unified code points of Japanese
Emojis to Unicode standard. Thanks!
• http://emoji4unicode.googlecode.com/
YAPC::Asia 2009 Tokyo 7
Two Perl Modules Released
• Unicode::Emoji::E4U
– Emoji mappings based on Google’s
emoji4unicode project
– Pure Perl OO interface for their table
• Encode::JP::Emoji
– Emoji encodings and cross-mapping
tables in pure Perl
– Pure Perl encodings for Encode.pm
– XS (UCM) version of this was canceled.
YAPC::Asia 2009 Tokyo 8
Encode::JP::Emoji Usage
use Encode;
use Encode::JP::Emoji;
# from DoCoMo <U+E6E2> to Google <U+FE82E>
my $keycap1 = "¥xEE¥x9B¥xA2";
Encode::from_to($keycap1, 'x-utf8-e4u-docomo', 'utf8');
# from KDDI <SJIS+F7F5> to SoftBank <SJIS+F747>
my $scream = "¥xF7¥xF5";
Encode::from_to($scream, 'x-sjis-e4u-kddiapp',
'x-sjis-e4u-softbank3g');
Encode::JP::Mobile is an alternative module to do above.
YAPC::Asia 2009 Tokyo 10
Encode::JP::Emoji Internal
例:KDDI Shift_JIS から KDDI Unicode に変換する内部コード。(概念)
内部的には、いったん CP932 で decode してから、tr// 等で置換する仕組み。
sub decode {
my ($self, $octets, $check) = @_;
$self->before_decode($octets, $check);
my $string = $self->byte_encoding->decode($octets, $check);
$self->after_decode($string, $check);
$string;
}
sub after_decode {
$_[1] =~ tr
[¥x{E234}-¥x{E342}¥x{E5B5}-¥x{E5DF}]
[¥x{E5CD}-¥x{E5DF}¥x{EA80}-¥x{EAFA}¥x{EB0E}-¥x{EB8E}
¥x{EAFB}-¥x{EB0D}¥x{E5B5}-¥x{E5CC}];
}
YAPC::Asia 2009 Tokyo 11
Ex. Emoji for Dung
• DoCoMo (don’t have emoji for dung)
• KDDI PUA <U+E4F5>
• SoftBank PUA <U+E05A>
• Google PUA <U+FE4F4>
• Unicode Standard proposed <U+1F410>
• 4バイトUTF-8 なので、MySQL 5 は非対応
YAPC::Asia 2009 Tokyo 12
OpenSocial Container
By Perl
RECRUIT は OpenSocial
コンテナを実装中です
YAPC::Asia 2009 Tokyo 13
OpenSocial
• OpenSocial is a set of APIs for SNS.
• Many SNSs in the world, including Mixi in
Japan, support OpenSocial apps.
• Two way to access to social network ■
– JavaScript library interface ■
– RESTful XML / JSON-RPC protocols ■
YAPC::Asia 2009 Tokyo 15
Apache Shindig
• An OpenSocial container implemention
by Apache incubation project.
• Consists of four parts:
– Gadget Container JavaScript
– Gadget Rendering Server
– OpenSocial Container JavaScript
– OpenSocial Data Server
• Java and PHP version of it released.
• No Perl version yet.
YAPC::Asia 2009 Tokyo 16
Importing Shindig to Perl
• We’re importing Shindig’s RPC Data API
handling servlets to Perl!
• Apache + FastCGI + HTTP::Engine
ApiServlet.pm
Database Layer AppDataHandler.pm
AppDataService.pm
CollectionOptions.pm
SNS Data Gadget DataRequestHandler.pm
Website RPC API Render DataServiceServlet.pm
Core Servlet Servlet JsonRpcServlet.pm
PersonHandler.pm
PersonService.pm
FastCGI / Perl PHP
RequestItem.pm
ResponseItem.pm
Apache RestRequestItem.pm
RpcRequestItem.pm
:
YAPC::Asia 2009 Tokyo 17
osapi(通称:オサピー)supported
• 従来の OpenSocial JavaScript インターフェースに加えて、
osapi(通称:オサピー)に対応しています。
• newIdSpec 不要で簡潔な記述となり、開発の敷居を下げます。
• バッチリクエストにより、多数の API 呼び出しを束ねて高速化。
XML:
<Require feature="osapi" />
JavaScript:
var batch = new osapi.newBatch();
batch.add('members', osapi.people.get({
userId: '@self',
fields: ['id','displayName','thumbnailUrl']
}));
batch.execute(callback);
YAPC::Asia 2009 Tokyo 18
ChaMap – MA4 Grand Prix
Geo location based
chat communication
platform service
using Google Maps,
Language API and
some other APIs.
Real time translation
and read out in English.
http://www.chamap.net/
YAPC::Asia 2009 Tokyo 26
Get 1,000,000 Yen on MA5!
最優秀賞は
賞金100万円!
参加登録は今スグ!
mashupaward.jp
YAPC::Asia 2009 Tokyo 27