# -*- Mode: cperl -*- ################################ # LambdaCalculus Module # ################################ package BotModules::LambdaCalculus; use FileHandle; use IPC::Open2; use vars qw(@ISA); @ISA = qw(BotModules); 1; sub Help { my $self = shift; my ($event) = @_; return { '' => 'This module is an interface to Hixie\'s lambda calculus coursework. lc is run in quiet mode and help, warranty and license commands are blocked (because they are noisy).', 'lc' => 'pass a (set of) commands to the LambdaCalculus interpreter. Separate commands with commas, as in: lc R=Lx.xy, S=rz, r=variable 0 S, S=[R/r]S, T=reduce S, print T', }; } sub Told { my $self = shift; my ($event, $message) = @_; if ($message =~ /^\s*lc\s+(.+?)\s*$/osi) { my @commands = split(/,\s*/o, $1); foreach my $command (@commands) { if ($command eq 'help') { $command = '#help'; } elsif ($command eq 'warranty') { $command = '#warranty'; } elsif ($command eq 'license') { $command = '#license'; } } $self->debug("lc doing:", @commands); $self->spawnChild($event, sub { $self->Execute(@_); }, [@commands], 'LambdaCalculus', [undef]); } else { return $self->SUPER::Told(@_); } return 0; # we've dealt with it, no need to do anything else. } sub Execute { my $self = shift; my(@commands) = @_; chdir("/home/ianh/University/LambdaCalculus"); my $pid = open2(*LCREADER, *LCWRITER, './lc', '=qa'); foreach (@commands) { print LCWRITER "$_\n"; } close(LCWRITER); local $/ = undef; my $result = ; waitpid($pid, 0); chdir("/home/ianh/webtools/mozbot"); return $result; } # ChildCompleted - Called when a child process has quit sub ChildCompleted { my $self = shift; my ($event, $type, $output, @data) = @_; if ($type eq 'LambdaCalculus') { $self->say($event, $output); } else { return $self->SUPER::ChildCompleted(@_); } }