File Coverage

blib/lib/Encode/JP/Emoji/FB_EMOJI_GMAIL.pm
Criterion Covered Total %
statement 41 44 93.1
branch 12 16 75.0
condition 1 3 33.3
subroutine 9 9 100.0
pod 1 1 100.0
total 64 73 87.6


line stmt bran cond sub pod time code
1             =encoding utf-8
2              
3             =head1 NAME
4              
5             Encode::JP::Emoji::FB_EMOJI_GMAIL - Emoji fallback functions with Gmail
6              
7             =head1 SYNOPSIS
8              
9             use Encode;
10             use Encode::JP::Emoji;
11             use Encode::JP::Emoji::FB_EMOJI_GMAIL;
12              
13             # DoCoMo Shift_JIS octets
14             # [晴れ]
15             my $sun = "\xF8\x9F";
16             Encode::from_to($sun, 'x-sjis-emoji-docomo', 'x-sjis-emoji-none', FB_EMOJI_GMAIL());
17              
18             # KDDI(web) Shift_JIS octets
19             # [曇り]
20             my $cloud = "\xF6\x65";
21             Encode::from_to($cloud, 'x-sjis-emoji-kddiweb', 'x-sjis-emoji-none', FB_EMOJI_GMAIL());
22              
23             # SoftBank UTF-8 string
24             # [ハムスター]
25             my $hamster = "\x{E524}";
26             $hamster = Encode::encode('x-sjis-e4u-none', $hamster, FB_EMOJI_GMAIL());
27              
28             # Google UTF-8 octets
29             # [クマ]
30             my $bear = "\xF3\xBE\x87\x81";
31             $bear = Encode::decode('x-utf8-e4u-none', $bear, FB_EMOJI_GMAIL());
32              
33             =head1 DESCRIPTION
34              
35             This module exports the following fallback function.
36             Use this with C and C encodings
37             which rejects any emojis.
38             Note that this is B an official service powered by Gmail.
39              
40             =head2 FB_EMOJI_GMAIL()
41              
42             This returns C element for PC to display emoji images.
43             Having conflicts with SoftBank encoding, KDDI(app) encoding is B recommended.
44              
45             =head2 FB_EMOJI_GMAIL()
46              
47             =head1 LINKS
48              
49             =over 4
50              
51             =item * Subversion Trunk
52              
53             L
54              
55             =item * Project Hosting on Google Code
56              
57             L
58              
59             =item * Google Groups and some Japanese documents
60              
61             L
62              
63             =item * RT: CPAN request tracker
64              
65             L
66              
67             =item * AnnoCPAN: Annotated CPAN documentation
68              
69             L
70              
71             =item * Search CPAN
72              
73             L
74              
75             =back
76              
77             =head1 BUGS
78              
79             C 2.22 and less would face a problem on fallback function.
80             Use latest version of C, or use with C
81             in C test directory of the package.
82              
83             =head1 AUTHOR
84              
85             Yusuke Kawasaki, L
86              
87             =head1 SEE ALSO
88              
89             L
90              
91             =head1 COPYRIGHT
92              
93             Copyright 2009 Yusuke Kawasaki, all rights reserved.
94              
95             =cut
96              
97             package Encode::JP::Emoji::FB_EMOJI_GMAIL;
98 5     5   1281357 use strict;
  5         11  
  5         191  
99 5     5   30 use warnings;
  5         9  
  5         190  
100 5     5   40 use base 'Exporter';
  5         9  
  5         445  
101 5     5   27 use Encode ();
  5         11  
  5         84  
102 5     5   25 use Encode::JP::Emoji;
  5         11  
  5         122  
103 5     5   24 use Encode::JP::Emoji::Property;
  5         10  
  5         470  
104 5     5   4730 use Encode::JP::Emoji::FB_EMOJI_TEXT;
  5         7062  
  5         1409  
105              
106             our $VERSION = '0.05';
107              
108             our @EXPORT = qw(
109             FB_EMOJI_GMAIL
110             );
111              
112             our $DOCOMO_FORMAT = '%s';
113             our $KDDI_FORMAT = '%s';
114             our $SOFTBANK_FORMAT = '%s';
115             our $GOOGLE_FORMAT = '%s';
116              
117             my $ascii = Encode::find_encoding('us-ascii');
118             my $utf8 = Encode::find_encoding('utf8');
119             my $mixed = Encode::find_encoding('x-utf8-e4u-mixed');
120             my $none = Encode::find_encoding('x-utf8-e4u-none');
121             my $fbtext = FB_EMOJI_TEXT();
122              
123             sub FB_EMOJI_GMAIL {
124 52   33 52 1 23485 my $fb = shift || $fbtext;
125             sub {
126 52     52   18200 my $code = shift;
127 52         134 my $chr = chr $code;
128 52         67 my $format = $GOOGLE_FORMAT;
129 52         62 my $gcode;
130 52 100       331 if ($chr =~ /\p{InEmojiGoogle}/) {
    50          
131             # google emoji
132 14         25 $gcode = $code;
133             } elsif ($chr =~ /\p{InEmojiAny}/) {
134             # others emoji
135 38 100       11472 if ($chr =~ /\p{InEmojiDoCoMo}/) {
    100          
    100          
    50          
136 12         634 $format = $DOCOMO_FORMAT;
137             } elsif ($chr =~ /\p{InEmojiSoftBank}/) {
138 12         27 $format = $SOFTBANK_FORMAT;
139             } elsif ($chr =~ /\p{InEmojiKDDIweb}/) {
140 10         7520 $format = $KDDI_FORMAT;
141             } elsif ($chr =~ /\p{InEmojiKDDIapp}/) {
142 0         0 $format = $KDDI_FORMAT;
143             }
144 38         1044 my $moct = $utf8->encode(chr $code, $fb); # Mixed UTF-8 octets
145 38         175 my $gstr = $mixed->decode($moct, $fb); # Google UTF-8 string
146 38 50       16658 $gcode = ord $gstr if (1 == length $gstr);
147             }
148 52 50       224 unless (defined $gcode) {
149 0         0 my $aoct = $ascii->encode(chr $code, $fb); # force fallback
150 0         0 return $utf8->decode($aoct, $fb); # UTF-8 string
151             }
152 52         134 my $num = $gcode & 0x0FFF;
153 52         239 my $name = $none->encode(chr $code, $fbtext); # emoji name
154 52         15624 $name = $utf8->decode($name, $fb); # UTF-8 string
155 52         837 sprintf $format => $num, $name;
156 52         548 };
157             }
158              
159             # This file was written in UTF-8
160              
161             1;