User:XLinkBot/Code/Diffparser.pm

package DiffParser;

use LWP::UserAgent;

my $diffFetcher=LWP::UserAgent->new; $diffFetcher->agent("LinkWatcher/2.0");

sub parse { my $diffUrl=shift; $diffUrl.="&diffonly=1&action=render"; my $diffContent=$diffFetcher->get($diffUrl)->content; my (@added,@removed,@addedPre,@removedPre);

@addedPre=$diffContent=~m/ (.*?)<\/div><\/td>/sg; @removedPre=$diffContent=~m/ (.*?)<\/div><\/td>/sg;

my ($addedTotal,$removedTotal); $addedTotal=join(' ', @addedPre); $removedTotal=join(' ', @removedPre);

$addedTotal =~ s/ .+?<\/span>//g; $removedTotal  =~ s/ .+?<\/span>//g;

foreach $diff (@addedPre) { my $diffchange=0; foreach my $addition ($diff=~m/ (.*?)<\/span>/g) { push (@added,$addition); $diffchange=1; }       if (!$diffchange) { if ($removedTotal !~ m/\Q$diff\E/) { push(@added,$diff); }       }    }

}   return (@added); }
 * 1)    foreach $diff (@removedPre) {
 * 2)        my $diffchange=0;
 * 3)        foreach my $removal ($diff=~m/ (.*?)<\/span>/g) {
 * 4)            push (@removed,$removal);
 * 5)            $diffchange=1;
 * 6)        }
 * 7)        if (!$diffchange) {
 * 8)            if ($addedTotal !~ m/\Q$diff\E/) {
 * 9)                push(@removed,$diff);
 * 10)            }
 * 11)        }