| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Mail::MtPolicyd::Plugin::Role::Scoring; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 10 |  |  | 10 |  | 5303 | use Moose::Role; | 
|  | 10 |  |  |  |  | 12 |  | 
|  | 10 |  |  |  |  | 104 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | our $VERSION = '2.01'; # VERSION | 
| 6 |  |  |  |  |  |  | # ABSTRACT: role for plugins using scoring | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | has 'score_field' => ( | 
| 9 |  |  |  |  |  |  | is => 'ro', isa => 'Str', default => 'score', | 
| 10 |  |  |  |  |  |  | ); | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | sub _get_score { | 
| 13 | 22 |  |  | 22 |  | 32 | my ( $self, $r ) = @_; | 
| 14 | 22 |  |  |  |  | 703 | my $session = $r->session; | 
| 15 | 22 | 100 |  |  |  | 716 | if( defined $session->{$self->score_field} ) { | 
| 16 | 16 |  |  |  |  | 462 | return $session->{$self->score_field}; | 
| 17 |  |  |  |  |  |  | } | 
| 18 | 6 |  |  |  |  | 14 | return 0; | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub _set_score { | 
| 22 | 19 |  |  | 19 |  | 28 | my ( $self, $r, $value ) = @_; | 
| 23 | 19 |  |  |  |  | 572 | my $session = $r->session; | 
| 24 | 19 |  |  |  |  | 553 | return $session->{$self->score_field} = $value; | 
| 25 |  |  |  |  |  |  | } | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | sub _push_score_detail { | 
| 28 | 19 |  |  | 19 |  | 41 | my ( $self, $r, $string ) = @_; | 
| 29 | 19 |  |  |  |  | 1009 | my $session = $r->session; | 
| 30 | 19 |  |  |  |  | 578 | my $field = $self->score_field . '_detail'; | 
| 31 | 19 | 100 |  |  |  | 66 | if( ! defined $session->{$field} ) { | 
| 32 | 6 |  |  |  |  | 16 | $session->{$field} = $string; | 
| 33 | 6 |  |  |  |  | 10 | return; | 
| 34 |  |  |  |  |  |  | } | 
| 35 | 13 |  |  |  |  | 179 | $session->{$field} .= ', '.$string; | 
| 36 | 13 |  |  |  |  | 105 | return; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub _get_score_detail { | 
| 40 | 3 |  |  | 3 |  | 3 | my ( $self, $r ) = @_; | 
| 41 | 3 |  |  |  |  | 78 | my $field = $self->score_field . '_detail'; | 
| 42 | 3 |  |  |  |  | 81 | return( $r->session->{$field} ); | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | sub add_score { | 
| 46 | 19 |  |  | 19 | 0 | 1011 | my ( $self, $r, $key, $value ) = @_; | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 19 |  |  |  |  | 71 | my $score = $self->_get_score($r); | 
| 49 | 19 |  |  |  |  | 42 | $score += $value; | 
| 50 | 19 |  |  |  |  | 70 | $self->_set_score($r, $score); | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 19 |  |  |  |  | 130 | $self->_push_score_detail($r, $key.'='.$value); | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 19 |  |  |  |  | 51 | return $score; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | 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 |