Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The new Text::Hatena

The new Text::Hatena

Yasuhiro Onishi

August 18, 2012
Tweet

More Decks by Yasuhiro Onishi

Other Decks in Programming

Transcript

  1. ͨ͘͞Μͷ5FYU)BUFOB w 5FYU)BUFOBʙ KLPOEP w IUUQTNFUBDQBOPSHSFMFBTF+,0/%05FYU)BUFOB w 5FYU)BUFOB KLPOEP w

    IUUQTNFUBDQBOPSHNPEVMF5FYU)BUFOB w 5FYU9BUFOB DIP w IUUQTNFUBDQBOPSHNPEVMF5FYU9BUFOB w 5FYU)BUFOB-JUF XBLBCBUBO w IUUQTHJUIVCDPNXBLBCBQFSMUFYUIBUFOBMJUF
  2. 5FYU)BUFOBʙ use  Text::Hatena;  #  0.16 my  $parser  =  Text::Hatena-­‐>new;  

       $parser-­‐>parse($text); my  $html  =  $parser-­‐>html;  
  3. The new Text::Hatena w 5FYU9BUFOB ˜DIP Λϕʔεʹ w ΧελϜσʔλଐੑΛ࢖ͬͯه๏ల։ͱΩʔ ϫʔυϦϯΫΛૄ݁߹Խ

    w աڈʢ΍ྨࣅʣͷΠϯλʔϑΣʔεޓ׵ w ଟ͘ͷ͸ͯͳه๏ʹରԠ w࣮ࡍʹ͸ͯͳϒϩάͰར༻͍ͯ͠Δ
  4. ΠϯλʔϑΣʔεޙํޓ׵ use Text::Hatena; my $parser = Text::Hatena->new; my $html =

    $parser->parse($string); # Text::Hatena 0.16 style my $html = $parser->html; # Text::Hatena 0.20 style my $html = Text::Hatena->parse($string); # Text::Xatena style my $html = $parser->format($string);
  5. 5FYU)BUFOB,FZXPSE EBUBVOMJOLଐੑΛߟྀͯ͠ΩʔϫʔυϦϯΫ my $parser = Text::Hatena::Keyword->new( rules => [ qr/hoge|fuga/

    => sub { sprintf '/keyword/%s', uri_escape($_) }, [qw/foo bar/] => sub { sprintf '/other/%s', uri_escape($_) }, ], ); my $words = $parser->extract($html); # நग़ my $formatted_html = $parser->format($html); # ϦϯΫ