File Coverage

blib/lib/Kwiki/Emoticon.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Kwiki::Emoticon;
2 1     1   1252 use Kwiki::Plugin -Base;
  0            
  0            
3             use mixin 'Kwiki::Installer';
4              
5             our $VERSION = 0.03;
6              
7             const class_id => 'emoticon_plugin';
8             const config_file => 'emoticon.yaml';
9              
10             sub register {
11             my $reg = shift;
12             $reg->add(preload => 'emoticon_plugin');
13             $reg->add(hook => 'formatter:formatter_classes', post => 'reformat');
14             $reg->add(hook => 'formatter:all_phrases', post => 'addphrase');
15             }
16              
17             sub reformat {
18             my $hook = pop;
19             my @classes = $hook->returned;
20             push @classes, "Emoticon";
21             return @classes;
22             }
23              
24             sub addphrase {
25             my $hook = pop;
26             my $phrases = $hook->returned;
27             push @$phrases, "emoticon";
28             return $phrases
29             }
30              
31             package Kwiki::Formatter::Emoticon;
32             use Spoon::Formatter;
33             use base 'Spoon::Formatter::Phrase';
34             use Text::Emoticon 0.03;
35              
36             const formatter_id => 'emoticon';
37             field emoticon => {};
38              
39             sub new {
40             $self = super;
41             my $class = $self->hub->config->emoticon_driver || 'MSN';
42             my $emoticon = Text::Emoticon->new($class);
43             $self->emoticon($emoticon);
44             $self;
45             }
46              
47             sub pattern_start {
48             $self->emoticon->pattern;
49             }
50              
51             sub html {
52             my $matched = $self->matched;
53             "" . $self->emoticon->filter_one($self->matched) . ""
54             }
55              
56             package Kwiki::Emoticon;
57              
58             1;
59             __DATA__