やっぱり時代はAnyEventですよね。
Feedが更新されたらon_fetchで指定したcode referenceが実行されます。
といっても、単なるpollingなのでほどほどにね!
#!/usr/bin/env perl
use AnyEvent;
use AnyEvent::Feed;
my $FLICKR_IDOLS_RSS
= 'http://pipes.yahoo.com/pipes/pipe.run?_id=WtqVti0j3BGz37dMJxOy0Q&_render=rss&search=idol+japanese+sexy';
my $POLLING_INTERVAL = 30;
run();
exit;
sub run {
my $done = AnyEvent->condvar;
my $feed_reader = AnyEvent::Feed->new(
url => $FLICKR_IDOLS_RSS,
interval => $POLLING_INTERVAL,
on_fetch => \&on_fetch,
on_error => \&on_error,
on_eof => \&on_eof,
);
$done->recv;
}
sub on_fetch {
my ( $feed_reader, $new_entries, $feed, $error ) = @_;
if ( defined $error ) {
warn "ERROR: $error\n";
return;
}
for my $entry_container (@$new_entries) {
my $hash = $entry_container->[0];
my $entry = $entry_container->[1]->{entry};
warn $entry->{link};
warn $entry->{description};
}
}
sub on_error {
my $error = shift;
warn "ERROR: $error";
$done->send;
}
sub on_eof {
$done->send;
}