File Coverage

blib/lib/Acme/RandomEmoji.pm
Criterion Covered Total %
statement 37 37 100.0
branch 8 8 100.0
condition 3 3 100.0
subroutine 6 6 100.0
pod 0 2 0.0
total 54 56 96.4


line stmt bran cond sub pod time code
1             # THIS FILE IS AUTOMATICALLY GENERATED BY author/generate.pl
2             package Acme::RandomEmoji;
3 1     1   20718 use strict;
  1         2  
  1         25  
4 1     1   5 use warnings;
  1         2  
  1         41  
5 1     1   910 use utf8;
  1         15  
  1         4  
6              
7 1     1   29 use Exporter 'import';
  1         2  
  1         468  
8             our @EXPORT_OK = qw(random_emoji);
9             our $VERSION = '0.01';
10             our $EMOJI = load_emoji();
11              
12             sub load_emoji {
13 1     1 0 2 my @chr;
14 1         9 while (my $line = ) {
15 966         1228 chomp $line;
16 966         1950 $line =~ s/^\s+//; $line =~ s/\s+$//;
  966         3205  
17 966 100 100     4097 next if !$line || $line =~ /^#/;
18 848         4818 $line =~ s/\s*#.*//;
19 848         2109 $line =~ s/\s*;.*//;
20 848 100       2132 if ($line !~ /\s+/) {
21 231         234 my @point;
22 231 100       547 if ($line =~ /^([0-9A-F]+)\.\.([0-9A-F]+)$/) {
23 118         571 @point = hex($1) .. hex($2);
24             } else {
25 113         240 @point = (hex($line));
26             }
27 231         393 for my $point (@point) {
28 1958         2631 my $chr = chr $point;
29 1958 100       3276 $chr .= "\N{U+FE0F}" if $point < 256;
30 1958         3948 push @chr, $chr;
31             }
32             } else {
33 617         1721 my @item = split /\s+/, $line;
34 617         888 my $chr = join "", map { chr hex $_ } @item;
  1352         3386  
35 617         2524 push @chr, $chr
36             }
37             }
38 1         24 close DATA;
39 1         4 \@chr;
40             }
41              
42 10     10 0 964 sub random_emoji { ${ $EMOJI }[ int rand @$EMOJI ] }
  10         87  
43              
44             =encoding utf-8
45              
46             =head1 NAME
47              
48             Acme::RandomEmoji - pick an emoji randomly
49              
50             =head1 SYNOPSIS
51              
52             =for html
53             screenshot
54              
55             =head1 DESCRIPTION
56              
57             Acme::RandomEmoji picks an emoji randomly.
58              
59             Emoji data is taken from:
60              
61             =over 4
62              
63             =item L
64              
65             =item L
66              
67             =item L
68              
69             =back
70              
71             =head1 SEE ALSO
72              
73             Full Emoji Data L
74              
75             =head1 COPYRIGHT AND LICENSE
76              
77             Copyright 2016 Shoichi Kaji
78              
79             This library is free software; you can redistribute it and/or modify
80             it under the same terms as Perl itself.
81              
82             Note that this library embed emoji-data.txt, emoji-sequences.txt and emoji-zwj-sequences.txt,
83             which have their own license. Please refer to L
84              
85             =cut
86              
87             1;
88              
89             __DATA__