diff options
author | Jannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de> | 2022-04-25 16:52:57 +0200 |
---|---|---|
committer | Jannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de> | 2022-04-25 16:52:57 +0200 |
commit | a97f1a5eb6649e93bfd6584ed590e37c1290755f (patch) | |
tree | fe5858e3d1f23ee991566db6c0995604b0b40910 /lib/JWebmail.pm | |
parent | 5c3fa491eebc690fbac8a963996a0244882813c7 (diff) |
Refactored ReadMails into a role
Diffstat (limited to 'lib/JWebmail.pm')
-rw-r--r-- | lib/JWebmail.pm | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/lib/JWebmail.pm b/lib/JWebmail.pm index 2c03d1b..82c94c1 100644 --- a/lib/JWebmail.pm +++ b/lib/JWebmail.pm @@ -1,15 +1,12 @@ -package JWebmail v1.1.0; +package JWebmail v1.2.0; use Mojo::Base 'Mojolicious'; use JWebmail::Controller::Webmail; -use JWebmail::Model::ReadMails; -use JWebmail::Model::Driver::QMailAuthuser; +use JWebmail::Model::ReadMails::Role; +use JWebmail::Model::ReadMails::QMailAuthuser; use JWebmail::Model::WriteMails; -use JWebmail::Model::Driver::MockJSON; -use JWebmail::Model::Driver::MockMaildir; - sub startup { my $self = shift; @@ -31,22 +28,23 @@ sub startup { delete $self->config->{secret}; # initialize models - no warnings "experimental::smartmatch"; - my $driver = do { - given ($self->config->{development}{use_read_mock}) { - when (/^json/) { JWebmail::Model::Driver::MockJSON->new() } - when (/^maildir/) { JWebmail::Model::Driver::MockMaildir->new(extractor => 'rust') } - default { - JWebmail::Model::Driver::QMailAuthuser->new( - logfile => $self->home->child('log', 'extract.log'), - %{ $self->config->{model}{read}{driver} // {} }) - } + my $read_mails = do { + if ($mode eq 'development') { + my $cls = $self->config->{development}{read_mock}; + eval "require $cls" || die "Issue for module $cls with: $@"; + $cls->new; + } + else { + JWebmail::Model::ReadMails::QMailAuthuser->new( + logfile => $self->home->child('log', 'extract.log'), + ); } }; - my $read_mails = JWebmail::Model::ReadMails->new(driver => $driver); + die "given class @{[ ref $read_mails ]} does not ReadMails" + unless $read_mails->DOES('JWebmail::Model::ReadMails::Role'); $self->helper(users => sub { $read_mails }); $self->helper(send_mail => sub { my ($c, $mail) = @_; JWebmail::Model::WriteMails::sendmail($mail) }); - $JWebmail::Model::WriteMails::Block_Writes = 1 if $self->config->{development}{block_writes}; + $JWebmail::Model::WriteMails::Block_Writes = 1 if $mode eq 'development'; $self->defaults(version => __PACKAGE__->VERSION); @@ -57,7 +55,7 @@ sub startup { sub route { my $self = shift; - my $r = shift // $self->routes; + my $r = shift || $self->routes; $r->get('/' => 'noaction')->to('Webmail#noaction'); $r->get('/about')->to('Webmail#about'); @@ -86,7 +84,7 @@ JWebmail - Provides a web based e-mail client meant to be used with s/qmail. =head1 SYNOPSIS - hypnotoad script/jwebmail + hypnotoad script/jwebmail And use a server in reverse proxy configuration. |