| 1 | package Mail::MtPolicyd::Plugin::Role::Scoring; | ||||||||||
| 2 | |||||||||||
| 3 | 10 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 10 | our $VERSION = '2.01'; # VERSION | |||||||||
| 6 | # ABSTRACT: role for plugins using scoring | ||||||||||
| 7 | |||||||||||
| 8 | 10 | has 'score_field' => ( | |||||||||
| 9 | is => 'ro', isa => 'Str', default => 'score', | ||||||||||
| 10 | ); | ||||||||||
| 11 | |||||||||||
| 12 | sub _get_score { | ||||||||||
| 13 | 22 | ▶ | my ( $self, $r ) = @_; | ||||||||
|
Subroutine
_get_score: called CC=2 SCAR=6.9
| |||||||||||
| 14 | 22 | my $session = $r->session; | |||||||||
| 15 | 22 | ▶ | if( defined $session->{$self->score_field} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 16 | return $session->{$self->score_field}; | |||||||||
| 17 | } | ||||||||||
| 18 | 6 | return 0; | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | sub _set_score { | ||||||||||
| 22 | 19 | ▶ | my ( $self, $r, $value ) = @_; | ||||||||
|
Subroutine
_set_score: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 19 | my $session = $r->session; | |||||||||
| 24 | 19 | return $session->{$self->score_field} = $value; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | sub _push_score_detail { | ||||||||||
| 28 | 19 | ▶ | my ( $self, $r, $string ) = @_; | ||||||||
|
Subroutine
_push_score_detail: called CC=2 SCAR=6.9
| |||||||||||
| 29 | 19 | my $session = $r->session; | |||||||||
| 30 | 19 | my $field = $self->score_field . '_detail'; | |||||||||
| 31 | 19 | ▶ | if( ! defined $session->{$field} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 6 | $session->{$field} = $string; | |||||||||
| 33 | 6 | return; | |||||||||
| 34 | } | ||||||||||
| 35 | 13 | $session->{$field} .= ', '.$string; | |||||||||
| 36 | 13 | return; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | sub _get_score_detail { | ||||||||||
| 40 | 3 | ▶ | my ( $self, $r ) = @_; | ||||||||
|
Subroutine
_get_score_detail: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 3 | my $field = $self->score_field . '_detail'; | |||||||||
| 42 | 3 | return( $r->session->{$field} ); | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | sub add_score { | ||||||||||
| 46 | 19 | ▶ | my ( $self, $r, $key, $value ) = @_; | ||||||||
|
Subroutine
add_score: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 47 | |||||||||||
| 48 | 19 | my $score = $self->_get_score($r); | |||||||||
| 49 | 19 | $score += $value; | |||||||||
| 50 | 19 | $self->_set_score($r, $score); | |||||||||
| 51 | |||||||||||
| 52 | 19 | $self->_push_score_detail($r, $key.'='.$value); | |||||||||
| 53 | |||||||||||
| 54 | 19 | return $score; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 10 | 1; | |||||||||
| 58 | |||||||||||
| 59 | __END__ | ||||||||||
| 60 | |||||||||||
| 61 | =pod | ||||||||||
| 62 | |||||||||||
| 63 | =encoding UTF-8 | ||||||||||
| 64 | |||||||||||
| 65 | =head1 NAME | ||||||||||
| 66 | |||||||||||
| 67 | Mail::MtPolicyd::Plugin::Role::Scoring - role for plugins using scoring | ||||||||||
| 68 | |||||||||||
| 69 | =head1 VERSION | ||||||||||
| 70 | |||||||||||
| 71 | version 2.01 | ||||||||||
| 72 | |||||||||||
| 73 | =head1 AUTHOR | ||||||||||
| 74 | |||||||||||
| 75 | Markus Benning <ich@markusbenning.de> | ||||||||||
| 76 | |||||||||||
| 77 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 78 | |||||||||||
| 79 | This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. | ||||||||||
| 80 | |||||||||||
| 81 | This is free software, licensed under: | ||||||||||
| 82 | |||||||||||
| 83 | The GNU General Public License, Version 2, June 1991 | ||||||||||
| 84 | |||||||||||
| 85 | =cut | ||||||||||