| 1 | package Mail::Decency::ContentFilter::Core::WeightTranslate; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 2 | ▶ | use version 0.74; our $VERSION = qv( "v0.1.6" ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | =head1 NAME | ||||||||||||
| 9 | |||||||||||||
| 10 | Mail::Decency::ContentFilter::Core::Virus | ||||||||||||
| 11 | |||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||
| 13 | |||||||||||||
| 14 | For all modules being a virus filter | ||||||||||||
| 15 | |||||||||||||
| 16 | =head1 CLASS ATTRIBUTES | ||||||||||||
| 17 | |||||||||||||
| 18 | =head2 weight_translate : HashRef[Int] | ||||||||||||
| 19 | |||||||||||||
| 20 | Hashref of translation values. | ||||||||||||
| 21 | |||||||||||||
| 22 | Example: | ||||||||||||
| 23 | |||||||||||||
| 24 | weight_translate: | ||||||||||||
| 25 | 10: 100 | ||||||||||||
| 26 | 0: 50 | ||||||||||||
| 27 | -5: -50 | ||||||||||||
| 28 | -10: -100 | ||||||||||||
| 29 | |||||||||||||
| 30 | Will translate anything | ||||||||||||
| 31 | |||||||||||||
| 32 | |||||||||||||
| 33 | =cut | ||||||||||||
| 34 | |||||||||||||
| 35 | 2 | has weight_translate => ( is => 'rw', isa => 'HashRef[Int]', predicate => 'has_weight_translate' ); | |||||||||||
| 36 | |||||||||||||
| 37 | =head2 METHODS | ||||||||||||
| 38 | |||||||||||||
| 39 | =head2 pre_init | ||||||||||||
| 40 | |||||||||||||
| 41 | Add check params: cmd, check, train and untrain to list of check params | ||||||||||||
| 42 | |||||||||||||
| 43 | =cut | ||||||||||||
| 44 | |||||||||||||
| 45 | 0 | ▶ | before init => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 46 | 0 | my ( $self ) = @_; | |||||||||||
| 47 | 0 | ▶ | push @{ $self->{ config_params } ||=[] }, qw/ weight_translate /; | ||||||||||
|
Condition0%0/2
$self->{"config_params"} ||= []
MC/DC0%0/1
$self->{"config_params"} ||= []
$self->{"config_params"}
Truth table0%0/2
A
A= $self->{"config_params"}
| |||||||||||||
| 48 | 2 | }; | |||||||||||
| 49 | |||||||||||||
| 50 | |||||||||||||
| 51 | =head2 translate_weight | ||||||||||||
| 52 | |||||||||||||
| 53 | Uses the weight translation array and determines dececency weighting from module weighting (eg crm114 to decency translation) | ||||||||||||
| 54 | |||||||||||||
| 55 | =cut | ||||||||||||
| 56 | |||||||||||||
| 57 | 0 | ▶ | sub translate_weight { | ||||||||||
|
Subroutine
translate_weight: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 58 | 0 | my ( $self, $received_score ) = @_; | |||||||||||
| 59 | |||||||||||||
| 60 | 0 | my ( $translated_score, $last ); | |||||||||||
| 61 | |||||||||||||
| 62 | # sort ascending (-1, 0, 1) | ||||||||||||
| 63 | 0 | my @sorted = sort { $a <=> $b } map { 1 * $_ } keys %{ $self->weight_translate }; | |||||||||||
| 64 | |||||||||||||
| 65 | $self->logger->debug3( "Translating '$received_score' with '". join( ', ', map { | ||||||||||||
| 66 | 0 | sprintf( '%d -> %d', $_, $self->weight_translate->{ $_ } ); | |||||||||||
| 67 | } @sorted ) ); | ||||||||||||
| 68 | |||||||||||||
| 69 | # received value is smaller then first value | ||||||||||||
| 70 | 0 | ▶ | return $self->weight_translate->{ $sorted[0] } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 71 | if $received_score <= $sorted[0]; | ||||||||||||
| 72 | |||||||||||||
| 73 | # go through sorted score .. -10, -5, 0, 10, 100 | ||||||||||||
| 74 | 0 | foreach my $module_score( @sorted ) { | |||||||||||
| 75 | |||||||||||||
| 76 | # search for the smallest score bigger then the received score | ||||||||||||
| 77 | 0 | ▶ | if ( $received_score < $module_score ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | 0 | return $self->weight_translate->{ $module_score }; | |||||||||||
| 79 | } | ||||||||||||
| 80 | 0 | $last = $module_score; | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | # fallback to last (BIGGEST) score if not found any | ||||||||||||
| 84 | 0 | return $self->weight_translate->{ $last }; | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | =head1 AUTHOR | ||||||||||||
| 88 | |||||||||||||
| 89 | Ulrich Kautz <uk@fortrabbit.de> | ||||||||||||
| 90 | |||||||||||||
| 91 | =head1 COPYRIGHT | ||||||||||||
| 92 | |||||||||||||
| 93 | Copyright (c) 2010 the L</AUTHOR> as listed above | ||||||||||||
| 94 | |||||||||||||
| 95 | =head1 LICENCSE | ||||||||||||
| 96 | |||||||||||||
| 97 | This library is free software and may be distributed under the same terms as perl itself. | ||||||||||||
| 98 | |||||||||||||
| 99 | =cut | ||||||||||||
| 100 | |||||||||||||
| 101 | 2 | 1; | |||||||||||