#!/usr/bin/perl -w use strict; use LUG; use LUG::Member::LugOfficer; use LUG::Event; # Initialise the LUG, and a few trivial details. my $UW = new LUG("UWLUG"); $UW->addMemberList("/home/lugmaster/member_list.txt"); $Tim = new LUG::Member::LUGOfficer($UW->returnMember("Tim")); # Create a new event. my $LW = new LUG::Event($UW, "LinuxWorld"); # LUG::Event accepts many date formats. $LW->Date("5th October 2005"); $LW->RegistrationDeadline("International Talk Like A Pirate Day"); $LW->messageDeadlinePassed("You're too late - you can't come with the LUG, but you could go by train at a cost of about £20."); # An initialised event usually requires an object of the class # LUG::Member to organise it. LUGOfficer inherits from LUG::Member. $Tim->addTask($LW); $Tim->run(); ################################ # Define the LUGOfficer class. # ################################ package LUG::Member::LUGOfficer; use strict; use LUG::Member; # Create a new LUGOfficer object. sub new { # Takes one argument, a LUG::Member object. my ($self, $Member) = @_; my $LO = bless { "Member" => $Member; "TaskList" => []; "CurrentTask" => ""; }, $self; return $LO; } # Add a task to the LUGOfficer. sub addTask { my ($self, $Task) = @_; push $self->{"TaskList"}, $Task; } # Email handling routine. sub handleEmails { my $self = shift; my @Emails = @_; for my $email in (@Emails) { next if $email->isSpam(); if ( $email->getSubject() == $self->{"CurrentTask"} ) { if ( date() <= $self->{"CurrentTask"}->RegistrationDeadline() ) { $self->{"CurrentTask"}->addInterestedMember(); } elsif ( date() <= $self->{"CurrentTask"}->Date() ) { $email->reply( $self->{"CurrentTask"}->messageDeadlinePassed() ); } else { $email->reply( "That happened already, you ", $self->{"Member"}->randomInsult() ); } } } } # Set the LugOfficer working. sub run { my $self = shift; while (1) { if ($self->{"CurrentTask"} = shift $self->{"TaskList"}) { $self->{"CurrentTask"}->organise(); } } }