in reply to Bot::BasicBot forkit - help needed

You don't need to spawn a background process for that. In my own IRC bot based on Bot::BasicBot I use the tick method to periodically check the svn repository.

Nothing spectacular, but it seems to work:

#!/usr/bin/perl use strict; use warnings; package SVNBot; use base 'Bot::BasicBot'; use SVN::Log; use Tie::File; my $repo_url = "file:///parrot/trunk/languages/perl6"; tie my @last_rev, 'Tie::File', 'last_revision' or die "Can't tie file last_revision: $!"; sub tick { my $self = shift; # warn "Rertrieving from r$last_rev[0]"; my $revs = SVN::Log::retrieve( $repo_url, $last_rev[0], 'HEAD', ); # the first revision was already printed in the last run splice @$revs, 0, 1; if (scalar @$revs > 5){ splice @$revs, 0, 5 - scalar(@$revs); } for my $r (@$revs){ my ($rn, $author, $msg) = ($r->{revision}, $r->{author}, $r->{message}); # no warnings 'uninitialized'; if (length $msg == 0){ $self->say( channel => '#perl6', body => "r$rn | $author | [no commit message]\n +", ); print "r$rn | $author | [no commit message]\n", } else { for (split /\n/, $msg){ $self->say( channel => '#perl6', body => "r$rn | $author++ | $_\n", ); print "r$rn | $author++ | $_\n", } } $last_rev[0] = $rn; } return 20; } package main; my $bot = SVNBot->new( server => 'irc.freenode.org', channels => ['#perl6'], nick => 'rakudo_svn', alt_nicks => ['rakudosvn', 'rakudo_svn2'], username => 'SVNBot', name => 'pugs SVN bot', charset => 'utf-8', ); $bot->run(); # vim: sw=4 ts=4 expandtab

Replies are listed 'Best First'.
Re^2: Bot::BasicBot forkit - help needed
by rpetre (Sexton) on Jul 20, 2009 at 17:29 UTC

    Thanks, I'll steal the idea, but this still leaves me a couple of questions:

    • I understand I can only have one tick that schedules the next and so on, this makes it pretty complicated if I want to have multiple tasks;
    • I am still at a loss regarding debugging this. I don't think the debugger will be as simple with POE in the mix. I'll try, but logging to stderr would still be nice.
      You could try to dig more into the POE stuff - I'm sure timers aren't that hard.
      but logging to stderr would still be nice

      Nothing prevents you from using warn or print STERR $msg; to achieve that.

      Did you ever come up with a way to schedule multiple tasks? I was thinking of using tick to fork each task each with its own wait time. I think there is some logic problem there, but it's a start.

      # psuedo sub tick { # stuff.... $self->forkit( run => \&task1, channel => $channel, arguments => [ $arg1, 20 ] ); # Where second arg is for a sleep. $self->forkit( run => \&task2, channel => $channel, arguments => [ $arg1, 40 ] ); # Where second arg is for a sleep.

      Neil Watson
      watson-wilson.ca