Dual-license your content for inclusion in The Perl 5 Wiki using this HOWTO, or join us for a chat on irc.freenode.net#PerlNet.

PerlNet::Bot

From PerlNet

Jump to: navigation, search

The following is a simple class derived from WWW::Mechanize that may be useful in bot writing.

package PerlNet::Bot;

use base WWW::Mechanize;
use strict;
use warnings;
use Carp;

use constant WIKI_BASE      => "http://perl.net.au/wiki";
use constant LOGIN_URL      => WIKI_BASE."/Special:Userlogin";

sub new {
        my ($class, $user, $pass, $agent) = @_;
        $agent ||= "PerlNet bot";

        # Create my bot.

        my $this = $class->SUPER::new(
                agent => $agent,
        );

        # Login.

        $this->get(LOGIN_URL);
        $this->form_number(1);
        $this->field("wpName",    $user);
        $this->field("wpPassword",$pass);
        $this->click("wpLoginattempt");

        $this->content =~ /Login successful/
                or croak "Login failed!";

        return $this;

}

sub edit {
        my ($this, $page, $content, $summary) = @_;
        $this->get(WIKI_BASE."/?title=$page&action=edit");

        # Edit the page and replace the contents.
        $this->form_number(1);
        $this->field("wpTextbox1", $content);
        $this->field("wpSummary", $summary);

        $this->click("wpSave");
}

1;
Personal tools