File Coverage

blib/lib/Text/SlackEmoji.pm
Criterion Covered Total %
statement 17 17 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 27 27 100.0


line stmt bran cond sub pod time code
1 1     1   79655 use strict;
  1         6  
  1         32  
2 1     1   6 use warnings;
  1         2  
  1         44  
3             package Text::SlackEmoji 0.009;
4             # ABSTRACT: data for mapping Slack :emoji_strings: into Unicode text
5              
6 1     1   5 use File::ShareDir ();
  1         2  
  1         190  
7              
8             #pod =head1 SYNOPSIS
9             #pod
10             #pod use Text::SlackEmoji;
11             #pod
12             #pod my $emoji = Text::SlackEmoji->emoji_map;
13             #pod
14             #pod $slack_message =~ s!:([-+a-z0-9_]+):!$emoji->{$1} // ":$1:"!ge;
15             #pod
16             #pod =head1 DESCRIPTION
17             #pod
18             #pod This library is basically just a container around a hash mapping strings like
19             #pod "disappointed_relieved" to Unicode text like 😥 .
20             #pod
21             #pod =head1 SECRET ORIGINS
22             #pod
23             #pod I made the first version of this lookup to power a little C plugin so
24             #pod that when using the Slack IRC gateway, I'd see the same emoji as the people
25             #pod using the Slack app, at least when possible.
26             #pod
27             #pod =cut
28              
29             our %Emoji;
30             sub _initialize_emoji {
31 2 100   2   11 $_[0]->load_emoji unless %Emoji;
32             }
33              
34             #pod =method load_emoji
35             #pod
36             #pod This method reloads the emoji map from disk, allowing the mapping to be updated
37             #pod in (say) your IRC client without forcing the reload of the module.
38             #pod
39             #pod =cut
40              
41             sub load_emoji {
42 1     1 1 5 my $emoji_file = File::ShareDir::dist_file('Text-SlackEmoji', 'emoji.pl');
43 1         167 %Emoji = %{ do $emoji_file };
  1         33161  
44 1         216 return;
45             }
46              
47             __PACKAGE__->_initialize_emoji;
48              
49             #pod =method emoji_map
50             #pod
51             #pod This method takes no arguments and returns a hashref mapping Slack emoji names
52             #pod to Unicode strings. The strings may be more than one character long.
53             #pod
54             #pod =cut
55              
56             sub emoji_map {
57 1     1 1 102 my ($self) = @_;
58 1         6 $self->_initialize_emoji;
59 1         1548 return { %Emoji };
60             }
61              
62             1;
63              
64             __END__