#!/usr/bin/perl -w use strict; use CGI; use XML::Simple; use LWP::Simple; my $q = CGI->new; # Base URL my $pm = 'http://www.perlmonks.org/'; # Chatterbox ticker: my $ticker = $pm . '?node_id=15834'; # Start HTML: print $q->header; print $q->start_html(-title => 'Chatterbox', -head => $q->meta({-http_equiv => 'refresh', -content => '12', -url => $q->self_url})); # Get the chat XML: my $chat = get $ticker; # Mangle it through XML::Simple my $xml = XMLin($chat, forcearray => 1); # Get the messages part: my $messages = $xml->{'message'}; # Is there anyone chatting? if($messages) { # All messages in the chatterbox currently foreach my $msg (@$messages) { my $author = $msg->{'author'}; my $content = $msg->{'content'}; my $user_id = $msg->{'user_id'}; # Strip leading whitespace... $content =~ s/^\s*//; # Compose the url for the author: my $author_url = $q->a({-href => "$pm?node_id=$user_id"}, $author); # Is the authour using '/me '? if($content =~ s{^/me }{}) { print $q->i("$author_url $content"); } # Nope, normal chatter: else { print "<$author_url> $content"; } print $q->br, "\n"; } } # Nope, all is... boring? else { print $q->i('and all is boring...'); } # End HTML: print $q->end_html;