You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@spamassassin.apache.org by bu...@bugzilla.spamassassin.org on 2011/05/05 16:31:37 UTC

[Bug 6581] New: Add a rules conditional function has(), similar to can()

https://issues.apache.org/SpamAssassin/show_bug.cgi?id=6581

             Bug #: 6581
           Summary: Add a rules conditional function has(), similar to
                    can()
           Product: Spamassassin
           Version: SVN Trunk (Latest Devel Version)
          Platform: PC
        OS/Version: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Libraries
        AssignedTo: dev@spamassassin.apache.org
        ReportedBy: Mark.Martinec@ijs.si
    Classification: Unclassified


Just documenting what is going on here,
existing rules and code is not affected.

Back in March 2011 I added the following change to Conf/Parser.pm:

  r1084790 | mmartinec | 2011-03-23 23:35:22 +0100 (Wed, 23 Mar 2011) | 1 line
  add a dummy function feature_bug6558_free() to allow conditionalizing
  problematic rules; a "feature" function must return a true to be considered

-    return UNIVERSAL::can($module, $meth);
+    return UNIVERSAL::can($module,$meth) && &{$method}();

The idea is for a 'feature' function to be able to determine its
result at run time, not merely by its presence. This was thought
to be necessary in order to implement sub feature_bug6558_free
(but later turned out to be unnecessary). Still, it can be a
useful feature for future conditional rules.

With the way the can() is currently used in rules this works fine,
all can() tests are only testing some 'feature' function, which
all return a true.

The only catch is that a test t/if_can.t was now producing a warning:

  $ prove t/if_can.t 
  t/if_can.t .. May  5 16:08:50.566 [24971] warn:
    Use of uninitialized value $self in concatenation (.) or string
    at ../blib/lib/Mail/SpamAssassin/Plugin/Test.pm line 66.
  t/if_can.t .. ok

Trying to fix this warning I realized that the can() is semantically
overloaded: for some purposes it is desirable to just check for an
existence of some function, in other cases it is desirable to also
invoke it and test its result.

So the solution I chose it to add a new rules-conditional function
has(), which is very much like a can(), except that the can() also
invokes its argument function, whereas the has() only tests for
its existence.

The naming choice seems awkward (considering that a has() is like
a perl UNIVERSAL::can, whereas the can() does one test more).
The reason for this choice is that I wanted existing uses of a
can() in rules to invoke its test function - for added flexiblity.

So I think it's not too bad. The can() does what is most commonly
needed, and the has() is very rarely used (never at the moment),
but exists just in case someone would need it.

-- 
Configure bugmail: https://issues.apache.org/SpamAssassin/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

[Bug 6581] Add a rules conditional function has(), similar to can()

Posted by bu...@bugzilla.spamassassin.org.
https://issues.apache.org/SpamAssassin/show_bug.cgi?id=6581

Mark Martinec <Ma...@ijs.si> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|Undefined                   |3.4.0

-- 
Configure bugmail: https://issues.apache.org/SpamAssassin/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

[Bug 6581] Add a rules conditional function has(), similar to can()

Posted by bu...@bugzilla.spamassassin.org.
https://issues.apache.org/SpamAssassin/show_bug.cgi?id=6581

--- Comment #2 from Mark Martinec <Ma...@ijs.si> 2011-05-05 14:37:37 UTC ---
Btw, the patch also fixes a discrepancy between a documentation and
implementation: the docs claimed that a 1 is returned, but actually
a ref to a code was returned.

-- 
Configure bugmail: https://issues.apache.org/SpamAssassin/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

[Bug 6581] Add a rules conditional function has(), similar to can()

Posted by bu...@bugzilla.spamassassin.org.
https://issues.apache.org/SpamAssassin/show_bug.cgi?id=6581

Kevin A. McGrail <km...@pccc.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |kmcgrail@pccc.com
         Resolution|                            |FIXED

--- Comment #3 from Kevin A. McGrail <km...@pccc.com> 2011-05-05 19:45:30 UTC ---
Resolved and committed

-- 
Configure bugmail: https://issues.apache.org/SpamAssassin/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

[Bug 6581] Add a rules conditional function has(), similar to can()

Posted by bu...@bugzilla.spamassassin.org.
https://issues.apache.org/SpamAssassin/show_bug.cgi?id=6581

--- Comment #1 from Mark Martinec <Ma...@ijs.si> 2011-05-05 14:35:47 UTC ---
Created attachment 4872
  --> https://issues.apache.org/SpamAssassin/attachment.cgi?id=4872
Implements the has(), documentation, test case

trunk:
  Bug 6581: Add a rules conditional function has(), similar to can()
  Sending lib/Mail/SpamAssassin/Conf/Parser.pm
  Sending lib/Mail/SpamAssassin/Conf.pm
  Sending lib/Mail/SpamAssassin/Plugin/Test.pm
  Sending t/if_can.t
Committed revision 1099823.

-- 
Configure bugmail: https://issues.apache.org/SpamAssassin/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.