(Well, that is, if you strip out the comments and blank lines = 42 lines). :)

Really only a good example on why you should use available modules. This is a Chatterbox "nodelet", much like the one you can see in the fullpage chat. It uses LWP::Simple to fetch the XML, XML::Simple to parse the content and CGI.pm to present the result.

It does not handle the [something] type links, but that should be possible to add with not too much trouble. Otherwise it pretty much mimicks the standard behaviour, and it does not add random whitespace here and there (what I've noted so far). :)

All written in a very short time, courtesy of the really cool people that write excellent modules and then distribute them. Which was what I wanted to show. :)

As usual, there is a place to take a test spin.

Update: Fixed stupid /me display bug.

Update 2: Changed title to something less confusing, as per request.

Update 3: Lots of thanks to wil for noticing that I had a forcearray bug and pointed this out to me. The code has now been updated with wil's suggestion.

#!/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"}, $aut +hor); # 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;

In reply to Your own Chatterbox nodelet in less than 50 lines of code. by Dog and Pony

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.