You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Pedro David Marco <pe...@yahoo.com> on 2016/09/10 13:09:55 UTC

Plugin development help needed...

Hi there...
i am not an expert OO developer so i am somehow flying blind in here and need your help please
Basically i want to write my own plugin and i have some repeated calculations in each and every plugin method that i would like to reduce to just one, but i am not sure on how to do it...
My understanding is that i can do it inside the constructor (the "sub new") and put the results in a data structure that can be accessed later by any method inside the plugin.
My main problem is that i do not know how to access the email content from inside the "sub new" constructor. Can anyone provide any help and if possible, an example, please???

have a nice weekend!---PedroD

Re: Plugin development help needed...

Posted by RW <rw...@googlemail.com>.
On Sat, 10 Sep 2016 13:09:55 +0000 (UTC)
Pedro David Marco wrote:

> Hi there...
> i am not an expert OO developer so i am somehow flying blind in here
> and need your help please Basically i want to write my own plugin and
> i have some repeated calculations in each and every plugin method
> that i would like to reduce to just one, 

This is usually done in whichever happens to be the first "eval" rule to
be called for each message. A plugin object isn't created per message,
so its constructor isn't the place to do anything with message data. 


For example check_bayes() is evaluated for every BAYES_* rule,
and you have:


  sub check_bayes {
    my ($self, $pms, $fulltext, $min, $max) = @_;
    ...

    if (!exists ($pms->{bayes_score})) {
      my $timer = $self->{main}->time_method("check_bayes");
      $pms->{bayes_score} = $self->scan($pms, $pms->{msg});
    }
    ...

pms is a per message data structure.


See also how _check_dkim_signature() is being called in various places
in Plugin/DKIM.pm.




Re: Plugin development help needed...

Posted by Martin Gregorie <ma...@gregorie.org>.
On Sat, 2016-09-10 at 13:58 +0000, Pedro David Marco wrote:
> Thanks Martin!
> This is exactly the book i have right now but experts opinions are
> always a good idea! :-)
>
IMO the Camel book should be part of every Perl programmer's library.
If you don't write much Perl, I'm primarily a C and Java programmer
BTW, it probably covers everything you'll need.

However, I don't think Perl is a wonderful language to learn about OO
from, because it seems to implement OO by extending other language
features so I may pay you to get comfortable with OO concepts by using
another language - Java and Python are probably best here.�

I think that of the two Java shows the concepts most clearly since its
impossible to write Java without declaring classes, but OTOH it has a
dauntingly large standard class library.

Python, like Perl, can be used both procedurally and for OO
programming, but this may tend to leave OO concepts a bit less clear.

Neither language has any particularly clear introductory texts, though
O'Reilly's "Python in a Nutshell" is OK. �

> Abstracting calculations in a method would mean �one call from each
> other method right? I would prefer�to have done just once (maybe in
> the constrcutor?) but...
>
Procedural abstraction is common in all modern programming languages
from the Algols and C onwards. As you say, abstraction is the concept
of writing a commonly used piece of code only once and calling it
whenever its needed. This has nothing to do with a class's
constructor(s): their only function is to initialise the class when it
is first instantiated. Conversely, it is quite normal for some of a
class's methods to be called by one or more of its constructors.


Martin


Re: Plugin development help needed...

Posted by Pedro David Marco <pe...@yahoo.com>.
Thanks Martin!
This is exactly the book i have right now but experts opinions are always a good idea! :-)
Abstracting calculations in a method would mean  one call from each other method right? I would prefer to have done just once (maybe in the constrcutor?) but...
Thanks again..
---PedroD.

      From: Martin Gregorie <ma...@gregorie.org>
 To: users@spamassassin.apache.org 
 Sent: Saturday, September 10, 2016 3:33 PM
 Subject: Re: Plugin development help needed...
   
On Sat, 2016-09-10 at 13:09 +0000, Pedro David Marco wrote:
> Hi there...
> i am not an expert OO developer so i am somehow flying blind in here
> and need your help please
> Basically i want to write my own plugin and i have some repeated
> calculations in each and every plugin method that i would like to
> reduce to just one, but i am not sure on how to do it...
> My understanding is that i can do it inside the constructor (the "sub
> new") and put the results in a data structure that can be accessed
> later by any method inside the plugin.
>
... or abstract it into a method. It will help a lot if you learn the
basics of OO programming before tackling a plugin.

See "Programming Perl", aka the Camel book, chapter 12. Written by
Larry Wall, Tom Christiansen and Jon Orwant, pub. O'Reilly.


Martin



   

Re: Plugin development help needed...

Posted by Martin Gregorie <ma...@gregorie.org>.
On Sat, 2016-09-10 at 13:09 +0000, Pedro David Marco wrote:
> Hi there...
> i am not an expert OO developer so i am somehow flying blind in here
> and need your help please
> Basically i want to write my own plugin and i have some repeated
> calculations in each and every plugin method that i would like to
> reduce to just one, but i am not sure on how to do it...
> My understanding is that i can do it inside the constructor (the "sub
> new") and put the results in a data structure that can be accessed
> later by any method inside the plugin.
>
... or abstract it into a method. It will help a lot if you learn the
basics of OO programming before tackling a plugin.

See "Programming Perl", aka the Camel book, chapter 12. Written by
Larry Wall, Tom Christiansen and Jon Orwant, pub. O'Reilly.


Martin