msimerson / mail-dmarc

Mail::DMARC, a complete DMARC implementation in Perl
Other
33 stars 23 forks source link

load report_store modules using Module::Load instead of relying on 'eval' #237

Closed bigio closed 5 months ago

bigio commented 5 months ago

This commit is a fix for issue #234

msimerson commented 5 months ago

Since this PR adds the Module::Load dependency, might as well also do Report::Receive:

index 7ba1561..7385b40 100644
--- a/lib/Mail/DMARC/Report/Receive.pm
+++ b/lib/Mail/DMARC/Report/Receive.pm
@@ -11,6 +11,7 @@ use Email::Simple;
 use Encode;
 use IO::Uncompress::Unzip;
 use IO::Uncompress::Gunzip;
+use Module::Load;
 use XML::LibXML;

 use parent 'Mail::DMARC::Base';
@@ -20,7 +21,7 @@ require Mail::DMARC::Report::Aggregate::Record;

 sub from_imap {
     my $self = shift;
-    eval "require Net::IMAP::Simple";    ## no critic (Eval)
+    load "Net::IMAP::Simple";
     croak "Net::IMAP::Simple seems to not work, is it installed?" if $@;

     my $server = $self->config->{imap}{server} or croak "no imap server conf";
@@ -30,7 +31,7 @@ sub from_imap {
     my $port   = $self->config->{imap}{port} // 993;

     if ($port != 143) {
-        eval "use IO::Socket::SSL";  ## no critic (Eval)
+        load "use IO::Socket::SSL";
         if ( $@ ) {
             croak "Can't load IO::Socket::SSL: $!\n";
         };