Re: Implementing Mail::SRS in MIMEDefang
Shevek <[email protected]> Tue, 19 Oct 2004 16:51:13 +0100 (BST)
| Newsgroups | gmane.mail.spam.srs.general |
|---|---|
| Message-ID | <[email protected]> |
On Sun, 3 Oct 2004, Michael Faurot wrote: > > In article <[email protected]> you wrote: > > > The "die" statements are quite the standard way of doing things in Perl > > modules. So this is actually really a Perl question. > > I thought my difficulty might involve something like this as I haven't > had much reason to use modules, until now. > > > At any rate, you should enclose SRS calls in an 'eval' function, which will > > return undef upon die. Like so: > [...] > > my $address; > > if (eval {$address = $srs -> reverse ($to)}) { > > This does indeed solve my difficulties. Thanks! > > Perhaps example code using eval could be incorporated into the POD > documentation? Presumably someone that does enough of this stuff, probably > already knows that they should use eval, but for folks like me that are > looking at the docs for example code just to get something working, > would appreciate it. :) Strictly speaking, you should inspect $@ and not rely on the returned value. my $address = eval { $srs->reverse($to); }; unless ($@) { ... } However, if the code ever returns undef (which I don't think it can), that would also be an error, so your code is fine. I will some examples in the documentation forthwith. Perhaps the code in Daemon.pm offers the best examples. S. -- Shevek http://www.anarres.org/ Robust Sender Policy Framework (SPF) http://www.libspf2.org/ SRS for the next generation http://www.libsrs2.org/