Changeset 1738

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

new Text::Emoticon

Files:

Legend:

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

    r1527 r1738  
    11Revision history for Perl extension Text::Emoticon::Yahoo 
     2 
     30.02  Wed Jan 11 10:24:42 UTC 2006 
     4        - Now it requires Text::Emoticon 0.03 framework 
     5        - Use Yahoo! US site as imgbase default 
    26 
    370.01  Sat Mar 26 14:25:00 2005 
  • Text-Emoticon-Yahoo/trunk/Makefile.PL

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

    r1527 r1738  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = '0.01'; 
    6  
    7 use vars qw(%Default %EmoticonMap $EmoticonRE); 
    8  
    9 %Default = ( 
    10     imgbase => ".", 
    11     xhtml   => 1, 
    12     class   => undef, 
    13 ); 
     5$VERSION = '0.02'; 
     6 
     7use Text::Emoticon 0.03; 
     8use base qw(Text::Emoticon); 
     9 
     10sub default_config { 
     11    return { 
     12        imgbase => "http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons6", 
     13        xhtml   => 1, 
     14        class   => undef, 
     15    }; 
     16
    1417 
    1518# Table autogernerated from emoticons.php using 
     
    2528# } 
    2629 
    27 %EmoticonMap = ( 
     30__PACKAGE__->register_subclass({ 
    2831':)'   => '1.gif', 
    2932':('   => '2.gif', 
     
    101104':-j'  => '78.gif', 
    102105'(*)'  => '79.gif', 
    103 ); 
    104  
    105 my $re = join "|", map quotemeta($_), keys %EmoticonMap; 
    106 $EmoticonRE = qr/($re)/; 
    107  
    108 sub new { 
    109     my($class, %opt) = @_; 
    110     my %attr = (%Default, %opt); 
    111     bless \%attr, $class; 
    112 
    113  
    114 sub filter { 
    115     my($self, $text) = @_; 
    116     return unless defined $text; 
    117  
    118     $text =~ s{$EmoticonRE}{$self->do_filter($EmoticonMap{$1})}eg; 
    119     return $text; 
    120 
    121  
    122 sub do_filter { 
    123     my($self, $icon) = @_; 
    124     my $class = $self->{class} ? qq( class="$self->{class}") : ""; 
    125     my $xhtml = $self->{xhtml} ? qq( /) : ""; 
    126  
    127     return qq(<img src="$self->{imgbase}/$icon"$class$xhtml>) 
    128 
     106}); 
    129107 
    1301081; 
     
    171149=item imgbase 
    172150 
    173 Base URL where icon gif files are located. It defaults to ".", meaning it links to images in current directory. Though you can use "http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons6/" (the Yahoo site) as C<imgbase> value, I don't recommend that, as there's a possibility Yahoo! will ban your site. 
     151Base URL where icon gif files are located. It defaults to 
     152"http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons6/" (the Yahoo 
     153site), but I don't recommend that, as there's a possibility Yahoo! 
     154will ban your site. 
    174155 
    175156=item xhtml 
  • Text-Emoticon-Yahoo/trunk/t/01_yahoo.t

    r1527 r1738  
    88my @Tests = ( 
    99    # args, filtered_text 
    10     [ { }, 
     10    [ { imgbase => '.' }, 
    1111      qq(blah <img src="./3.gif" />blah <img src="./4.gif" />) ], 
    1212    [ { imgbase => "http://example.com/img" }, 
    1313      qq(blah <img src="http://example.com/img/3.gif" />blah <img src="http://example.com/img/4.gif" />) ], 
    14     [ { xhtml => 0 }, 
     14    [ { imgbase => '.', xhtml => 0 }, 
    1515      qq(blah <img src="./3.gif">blah <img src="./4.gif">) ], 
    16     [ { class => "emo" }, 
     16    [ { imgbase => '.', class => "emo" }, 
    1717      qq(blah <img src="./3.gif" class="emo" />blah <img src="./4.gif" class="emo" />) ], 
    1818);