Changeset 1737

Show
Ignore:
Timestamp:
01/11/06 19:24:12
Author:
miyagawa
Message:

update so it uses 0.03 API

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Text-Emoticon-MSN/trunk/Changes

    r1579 r1737  
    11Revision history for Perl extension Text::Emoticon::MSN 
     2 
     30.03  Wed Jan 11 10:17:37 UTC 2006 
     4        - Now it requires Text::Emoticon 0.03 
     5        - Use MSN site as a default imgbase now 
    26 
    370.02  Sun May 29 14:55:19 JST 2005 
  • Text-Emoticon-MSN/trunk/Makefile.PL

    r1526 r1737  
    55    'PREREQ_PM' => { 
    66        Test::More => 0.32, 
     7        Text::Emoticon => 0.02, 
    78    }, 
    89); 
  • Text-Emoticon-MSN/trunk/lib/Text/Emoticon/MSN.pm

    r1579 r1737  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = '0.02'; 
    6  
    7 use vars qw(%Default %EmoticonMap $EmoticonRE); 
    8  
    9 %Default = ( 
    10     imgbase => ".", 
    11     xhtml   => 1, 
    12     strict  => 0, 
    13     class   => undef, 
    14 ); 
     5$VERSION = '0.03'; 
     6 
     7use Text::Emoticon 0.03; 
     8use base qw(Text::Emoticon); 
     9 
     10sub default_config { 
     11    return { 
     12        imgbase => "http://messenger.msn.com/Resouce/emoticons", 
     13        xhtml   => 1, 
     14        strict  => 0, 
     15        class   => undef, 
     16    }; 
     17
    1518 
    1619# Table autogernerated from Emoticons.aspx using 
     
    2225# } 
    2326 
    24 %EmoticonMap = ( 
     27__PACKAGE__->register_subclass({ 
    2528':-)' => "regular_smile.gif", 
    2629':)' => "regular_smile.gif", 
     
    124127'(li)' => "73_73.gif", 
    125128'(mo)' => "69_69.gif", 
    126  
    127 ); 
    128  
    129 my $re = join "|", map quotemeta($_), keys %EmoticonMap; 
    130 $EmoticonRE = qr/($re)/; 
    131  
    132 sub new { 
    133     my($class, %opt) = @_; 
    134     my %attr = (%Default, %opt); 
    135     bless \%attr, $class; 
    136 
    137  
    138 sub filter { 
    139     my($self, $text) = @_; 
    140     return unless defined $text; 
    141     if ($self->{strict}) { 
    142       $text =~ s{(?<!\w)$EmoticonRE(?!\w)}{$self->do_filter($EmoticonMap{$1})}eg; 
    143     } else { 
    144       $text =~ s{$EmoticonRE}{$self->do_filter($EmoticonMap{$1})}eg; 
    145     } 
    146     return $text; 
    147 
    148  
    149 sub do_filter { 
    150     my($self, $icon) = @_; 
    151     my $class = $self->{class} ? qq( class="$self->{class}") : ""; 
    152     my $xhtml = $self->{xhtml} ? qq( /) : ""; 
    153  
    154     return qq(<img src="$self->{imgbase}/$icon"$class$xhtml>);  
    155 
     129}); 
    156130 
    1571311; 
     
    198172=item imgbase 
    199173 
    200 Base URL where icon gif files are located. It defaults to ".", meaning it links to images in current directory. Though you can use "http://messenger.msn.com/Resouce/emoticons" (the MSN site) as C<imgbase> value, I don't recommend that, as there's a possibility MSN will ban your site. 
     174Base URL where icon gif files are located. It defaults to 
     175"http://messenger.msn.com/Resouce/emoticons" (the MSN site) but I 
     176don't recommend that, as there's a possibility MSN will ban your site. 
    201177 
    202178=item xhtml 
  • Text-Emoticon-MSN/trunk/t/01_emoticon.t

    r1579 r1737  
    88my @Tests = ( 
    99    # args, filtered_text 
    10     [ { }, 
     10    [ { imgbase => '.' }, 
    1111      qq(blah <img src="./wink_smile.gif" />blah <img src="./clock.gif" />) ], 
    1212    [ { imgbase => "http://example.com/img" }, 
    1313      qq(blah <img src="http://example.com/img/wink_smile.gif" />blah <img src="http://example.com/img/clock.gif" />) ], 
    14     [ { xhtml => 0 }, 
     14    [ { imgbase => '.', xhtml => 0 }, 
    1515      qq(blah <img src="./wink_smile.gif">blah <img src="./clock.gif">) ], 
    16     [ { class => "emo" }, 
     16    [ { imgbase => '.', class => "emo" }, 
    1717      qq(blah <img src="./wink_smile.gif" class="emo" />blah <img src="./clock.gif" class="emo" />) ], 
    18     [ { strict => 1 }, 
     18    [ { imgbase => '.', strict => 1 }, 
    1919      qq!blah ;-)blah <img src="./clock.gif" />! ], 
    2020);