Perl - undefined routine

I have the following Perl code:

use Email::Sender::Simple; use IO::Socket::SSL; IO::Socket::SSL::set_defaults(SSL_verify_mode => SSL_VERIFY_NONE); Email::Sender::Simple::sendmail($email, { transport => $transport }); 

When I run it, I get this error:

 Undefined subroutine &Email::Sender::Simple::sendmail called at script.pl line 73. 

If I changed the code for the following, then it works:

 use Email::Sender::Simple qw(sendmail); sendmail($email, { transport => $transport }); 

Can someone explain why I had to change the code for sendmail, while I did not need to change the code for set_defaults to look like this:

 use IO::Socket::SSL qw(set_defaults); set_defaults(SSL_verify_mode => SSL_VERIFY_NONE); 
+4
source share
1 answer

Take a look at the Email/Sendmail/Simple.pm . There is no sendmail routine in this program. Instead, if you look at the headline, you will see:

 use Sub::Exporter -setup => { exports => { sendmail => Sub::Exporter::Util::curry_class('send'), try_to_sendmail => Sub::Exporter::Util::curry_class('try_to_send'), }, }; 

I am not familiar with Sub :: Exporter , but I noticed this description.

Sub :: Exporter's biggest advantage over existing exporters (including the ubiquitous Exporter.pm) is its ability to create new codewords for export, rather than just exporting the code identical to the one contained in the exporting package.

ABOUT...

Thus, the purpose of using Sub::Exporter is to export the names of routines that are not routines in your package.

If you're interested, you can read the Sub :: Exporter tutorial, but it seems like it has the ability to export subroutines under different names.

Thus, Email::Sender::Simple::sendmail not a subroutine, but sendmail can be exported.

+4
source

Source: https://habr.com/ru/post/1496477/


All Articles