4

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 change the code to have 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 have to change the code for set_defaults to look like:

use IO::Socket::SSL qw(set_defaults);

set_defaults(SSL_verify_mode => SSL_VERIFY_NONE);
1
  • Well I just tried changing my code to have use IO::Socket::SSL qw(set_defaults); and set_defaults(SSL_verify_mode => SSL_VERIFY_NONE); and I got an error saying "set_defaults" is not exported by the IO::Socket::SSL module Commented Aug 12, 2013 at 2:12

1 Answer 1

4

Take a look at the code Email/Sendmail/Simple.pm. There is no sendmail subroutine in that program. Instead, if you look at the header, you'll 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'm not familiar with Sub::Exporter, but I did notice this description.

The biggest benefit of Sub::Exporter over existing exporters (including the ubiquitous Exporter.pm) is its ability to build new coderefs for export, rather than to simply export code identical to that found in the exporting package.

Oh...

So, the purpose of using Sub::Exporter is to export subroutine names that aren't subroutines in your package.

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

Thus, Email::Sender::Simple::sendmail isn't a subroutine, but that sendmail can still be exported.

Sign up to request clarification or add additional context in comments.

2 Comments

Maybe too much detail, but I can see where set_defaults is exported by IO::Socket::SSL
If you wanted to avoid importing, you could use Email::Sender::Simple->send(...) instead of Email::Sender::Simple::sendmail(...).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.