56 lines
1.1 KiB
Perl
56 lines
1.1 KiB
Perl
package WebGUI::MailCommand;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
sub isValidCommand {
|
|
my $command = shift;
|
|
|
|
return defined resolveCommandClass( $command );
|
|
}
|
|
|
|
sub new {
|
|
my $class = shift;
|
|
my $session = shift || die "Need a session";
|
|
|
|
bless { _session => $session }, $class;
|
|
}
|
|
|
|
sub process {
|
|
WebGUI::Error::OverrideMe->throw;
|
|
}
|
|
|
|
sub processCommand {
|
|
my $session = shift;
|
|
my $command = shift;
|
|
my $parameter = shift;
|
|
my $sender = shift;
|
|
|
|
my $commandClass = resolveCommandClass( $command )
|
|
|| return;
|
|
|
|
my $commandObject = WebGUI::Pluggable::instanciate( $commandClass, 'new', [ $session ] );
|
|
|
|
return $commandObject->process( $parameter, $sender );
|
|
}
|
|
|
|
sub session {
|
|
return (shift)->{ _session };
|
|
}
|
|
|
|
sub resolveCommandClass {
|
|
my $command = shift;
|
|
|
|
# TODO: Do not hard code.
|
|
my %commands = (
|
|
unsubscribe => 'WebGUI::MailCommand::Unsubscribe',
|
|
subscribe => 'WebGUI::MailCommand::Subscribe',
|
|
bounce => 'WebGUI::MailCommand::Bounce',
|
|
);
|
|
|
|
return $commands{ $command } if exists $commands{ $command };
|
|
return;
|
|
}
|
|
|
|
1;
|
|
|