You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2005/03/07 07:00:41 UTC
svn commit: r156398 -
spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
Author: jm
Date: Sun Mar 6 22:00:39 2005
New Revision: 156398
URL: http://svn.apache.org/viewcvs?view=rev&rev=156398
Log:
plugins can now set tags to subroutine references, to return dynamic data easily
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm?view=diff&r1=156397&r2=156398
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Sun Mar 6 22:00:39 2005
@@ -1037,8 +1037,20 @@
Set a template tag, as used in C<add_header>, report templates, etc. This API
is intended for use by plugins. Tag names will be converted to an
-all-uppercase representation internally. See C<Mail::SpamAssassin::Conf>'s
-C<TEMPLATE TAGS> section for more details on tags.
+all-uppercase representation internally.
+
+C<$value> can be a subroutine reference, which will be evaluated each time
+the template is expanded. Note that perl supports closures, which means
+that variables set in the caller's scope can be accessed inside this C<sub>.
+For example:
+
+ my $text = "hello world!";
+ $status->set_tag("FOO", sub {
+ return $text;
+ });
+
+See C<Mail::SpamAssassin::Conf>'s C<TEMPLATE TAGS> section for more details on
+how template tags are used.
=cut
@@ -1205,10 +1217,17 @@
);
if (exists $tags{$tag}) {
- return $tags{$tag}->(@_);
- } elsif ($self->{tag_data}->{$tag}) {
- return $self->{tag_data}->{$tag};
- } else {
+ return $tags{$tag}->(@_);
+ }
+ elsif ($self->{tag_data}->{$tag}) {
+ my $data = $self->{tag_data}->{$tag};
+ if (ref $data eq 'CODE') {
+ return $data->(@_);
+ } else {
+ return $data;
+ }
+ }
+ else {
return "";
}
}
Re: svn commit: r156398 - spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
Posted by Daniel Quinlan <qu...@pathname.com>.
jm@apache.org writes:
> plugins can now set tags to subroutine references, to return dynamic
> data easily
Excellent.
Could/should we require them to be named starting with "PLUGIN_" ?
--
Daniel Quinlan
http://www.pathname.com/~quinlan/