WEB+DB press vol.35

WEB+DB PRESS Vol.35

WEB+DB PRESS Vol.35

・Recent Perl World
O/Rマッパについての記事。
O/RマッパはCDBICatalystのPluginで触った程度なので
あんまり良く知らなかったんですが
CDBIDBIC以外にもいろいろあるんですねえ。
Jifty::DBIとData::ObjectDriverというのが紹介されてました。
Data::ObjectDriverはSixApart開発だとか。


・速習コードリーディング
ちょうどPlaggerのソース読んでるところなのでタイミング良ス。
残念ながら取り上げられてるのはJavaPHP・Cだけども。


Ajaxの定石
Javascript知らないのでまだあんまり読めてないけど、Ajax楽しそう!

Notify::YahooMessenger

を書いてみたけど既にあった。やっぱしorz


でももったいないから貼り付けてみる。

package Plagger::Plugin::Notify::YahooMessenger;
use strict;
use base qw( Plagger::Plugin );

use Net::YahooMessenger;

sub register {
    my($self, $context) = @_;
    $context->register_hook(
        $self,
        'plugin.init'  => \&initialize,
        'publish.feed' => \&notify,
    );
}

sub initialize {
    my($self, $context, $args) = @_;

    for (qw/id password recipient_id/) {
        $self->conf->{$_} or $context->error("$_ is required");
    }
        
    $self->conf->{pre_login_url} ||= 'http://edit.my.yahoo.co.jp/config/';
    $self->conf->{hostname}      ||= 'cs.yahoo.co.jp';
    $self->conf->{charset}       ||= 'sjis';

    $self->{ym} = Net::YahooMessenger->new( %{$self->conf} );
    $self->{ym}->login or $context->error("Couldn't login Yahoo Messenger");

    $context->log(debug => 'Login success');
}

sub notify {
    my($self, $context, $args) = @_;

    $context->log(
        info => "Notifying "
                . $args->{feed}->title
                . " to Yahoo Messenger"
    );

    my $body = $self->templatize('ym_notify.tt', $args);

    Encode::_utf8_off($body) if Encode::is_utf8($body);
    Encode::from_to($body, 'utf-8', $self->conf->{charset})
        if $self->conf->{charset} ne 'utf-8';

    for my $line (split("\n", $body)) {
        $self->{ym}->send($self->conf->{recipient_id}, $line);
        sleep 1;
    }
}

1;

config.yaml

  - module: Notify::YahooMessenger
    config: 
      id:            Yahoo ID
      password:      パスワード
      recipient_id:  送信先のYahoo ID
      #pre_login_url: http://edit.my.yahoo.co.jp/config/
      #hostname:      cs.yahoo.co.jp
      #charset:       sjis

ほぼNotify::IRCのコピペ。
assetも使いまわし。


plugin.initでログインしてるので、
フィードの新着があろうとなかろうと
メッセンジャーが「オンラインになりました」と反応してしまうのがなんとも・・・

Sleipnirの検索バーでCPAN検索

ってネタを書こうと思ったら既にあった。
こちら
ぷにる使いの人はぜひ試してみてくださいな。
ちなみに僕はmodule名で検索するのがほとんどなので、
リクエストを

http://search.cpan.org/search?query={all}&mode=module

こういう風にして使ってます。