Skip Menu |

This queue is for tickets about the libnet CPAN distribution.

Report information
The Basics
Id: 11198
Status: resolved
Worked: 30 min
Priority: 0/
Queue: libnet

People
Owner: Nobody in particular
Requestors: SREZIC [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: 1.19
Fixed in: (no value)



Subject: Net::SMTP documentation: return value of constructor
The Net::SMTP does not mention that undef is returned if the constructor fails. Extending the SYNOPSIS would also be nice, e.g. $smtp = Net::SMTP->new('mailhost') or die "Can't connect to mailhost"; Regards, Slaven
RT-Send-CC: gbarr [...] pobox.com
On Mo. 24. Jan. 2005, 09:29:43, SREZIC wrote: Show quoted text
> The Net::SMTP does not mention that undef is returned if the > constructor fails.
And, it would be nice to be able to get the status code and message from the server in case there was one, e.g.: $ telnet mailin-01.mx.aol.com smtp Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 554 (RLY:B1) http://postmaster.info.aol.com/errors/554rlyb1.html Connection closed by foreign host. This is a real world example. For monitoring purposes, I'd like to be able to get the server response, but Net::SMTP->new() only returns undef in that case, and the debug mode prints the message to STDERR, whereas I need it as a scalar for further processing. (And I do not want to redirect STDERR to a file and parse that afterwards. :-) ) As a workaround, I used the following patch: --- Net/SMTP.pm 2006-10-27 13:08:07 +0200 +++ my/Net/SMTP.pm 2007-04-19 10:46:22 +0200 @@ -58,7 +58,10 @@ unless ($obj->response() == CMD_OK) { + my $code = ${*$obj}{net_cmd_code}; + my @message = @{ ${*$obj}{net_cmd_resp} }; $obj->close(); + $@ = "$code @message"; return undef; } However, a better IMHO better aproach would be to split the ->new method into one which only initializes the object (e.g. ->init) and another to open the actual SMTP connection (e.g. ->open), which then could use the normal error escalation mechanism, that is return false, but provide methods to access the server reply. Or, perhaps one might use overloading ore some other magic to have ->new return something that evaluates to false in a boolean context but also can be used as an object. What do you think? Please let me know if a patch for one or the other suggestion would be appreciated and would have a chance to be applied. Regards, fany