Refactoring postfix transport script to allow pluggable commands.
This commit is contained in:
parent
a735068f25
commit
37120bafa8
4 changed files with 184 additions and 35 deletions
53
lib/WebGUI/MailCommand.pm
Normal file
53
lib/WebGUI/MailCommand.pm
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
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 $commandClass = resolveCommandClass( $command )
|
||||
|| return;
|
||||
|
||||
my $commandObject = WebGUI::Pluggable::instanciate( $commandClass, 'new', [ $session ] );
|
||||
|
||||
return $commandObject->process( $parameter );
|
||||
}
|
||||
|
||||
sub session {
|
||||
return (shift)->{ _session };
|
||||
}
|
||||
|
||||
sub resolveCommandClass {
|
||||
my $command = shift;
|
||||
|
||||
# TODO: Do not hard code.
|
||||
my %commands = (
|
||||
bounce => 'WebGUI::MailCommand::Bounce',
|
||||
);
|
||||
|
||||
return $commands{ $command } if exists $commands{ $command };
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue