Greeting fellow monks,
I was about to ask something in chatterbox using Shendal's monkchat when I found it
just didn't work. It didn't show the currently online users and showed no messages at all.
"This must be because of recent changes of this site layout", I thought, then
I grabbed the latest
PerlMonks modules (version 2.2), install it, but the same problem was still there.
After "super searching", I only found the same problem (Does anybody else have this problem?) was reported but no response.
After looking into PerlMonks modules, I found a fundamental problem that the XML parsing is done using regex in
a fragile way, that's why it is broken. Here is a quick fix to PerlMonks/Chat.pm and
PerlMonks/Users.pm, which simply replaces that parsing part with XML::Simple's XMLin().
--- Chat.pm-old Tue Sep 24 17:45:12 2002
+++ Chat.pm Tue Sep 24 17:32:07 2002
@@ -11,6 +11,7 @@
use strict;
use vars qw(@ISA);
use HTML::Entities;
+use XML::Simple;
use PerlMonks;
use PerlMonks::NewestNodes;
@@ -58,7 +59,15 @@
# Get general chat messages
if ($c=$self->getpage(CHAT_URL)) {
$c=~s/[\r\n\t]//g;
- my @msgs=($c=~/message\s+author="([^\"]+)"[^>]+>\s*(.*?)\s*<\/mes
+sage>/g);
+
+ # problematic
+ # my @msgs=($c=~/message\s+author="([^\"]+)"[^>]+>\s*(.*?)\s*<\/m
+essage>/g);
+
+ my $msgs = XMLin($c, forcearray => 1)->{message};
+
+ my @msgs = map { $_->{author} => $_->{content} }
+ sort { $a->{time} <=> $b->{time} } $msgs ? @$msgs : ();
+
if (@msgs) {
while (@msgs) {
my ($author, $msg)=(shift(@msgs),shift(@msgs));
--- Users.pm-old Tue Sep 24 17:45:18 2002
+++ Users.pm Tue Sep 24 17:37:28 2002
@@ -14,6 +14,7 @@
use strict;
use vars qw(@ISA);
+use XML::Simple;
use PerlMonks;
@ISA=qw(PerlMonks);
@@ -63,7 +64,13 @@
my $self=shift;
if ( (time() - $self->{cache_users_ts}) > USERS_REFRESH) {
if (my $c=$self->getpage(USERS_URL)) {
- my %users=($c=~/user\s+username="([^\"]+)"\s+user_id="(\d+)"/g)
+;
+
+ # problematic
+ # my %users=($c=~/user\s+username="([^\"]+)"\s+user_id="(\d+)"
+/g);
+
+ my $users = XMLin($c, forcearray => 1)->{user};
+ my %users = map { $_->{username} => $_->{user_id} } $users ? @
+$users : ();
+
$self->{cache_users}=\%users;
$self->{cache_users_ts}=time();
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.