| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Log::Saftpresse::Plugin::Role::CounterUtils; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 575 | use Moose::Role; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 10 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | # ABSTRACT: role for plugins to gather statistics/counters | 
| 6 |  |  |  |  |  |  | our $VERSION = '1.6'; # VERSION | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | has 'per_host_counters' => ( is => 'rw', isa => 'Bool', default => 1 ); | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | sub _get_event_host { | 
| 11 | 0 |  |  | 0 |  |  | my ( $self, $event ) = @_; | 
| 12 | 0 | 0 |  |  |  |  | if( ! $self->per_host_counters ) { | 
| 13 | 0 |  |  |  |  |  | return; | 
| 14 |  |  |  |  |  |  | } | 
| 15 | 0 | 0 |  |  |  |  | if( defined $event->{'host'} ) { | 
| 16 | 0 |  |  |  |  |  | return( $event->{'host'}); | 
| 17 |  |  |  |  |  |  | } | 
| 18 | 0 |  |  |  |  |  | return 'empty'; | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub incr_host { | 
| 22 | 0 |  |  | 0 | 0 |  | my ( $self, $event, @params ) = @_; | 
| 23 | 0 |  |  |  |  |  | return $self->incr( ($self->_get_event_host($event)), @params ); | 
| 24 |  |  |  |  |  |  | } | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub incr_host_one { | 
| 27 | 0 |  |  | 0 | 0 |  | my ( $self, $event, @params ) = @_; | 
| 28 | 0 |  |  |  |  |  | return $self->incr_one( ($self->_get_event_host($event)), @params ); | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | sub incr_host_max { | 
| 32 | 0 |  |  | 0 | 0 |  | my ( $self, $event, @params ) = @_; | 
| 33 | 0 |  |  |  |  |  | return $self->incr_max( ($self->_get_event_host($event)), @params ); | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | sub count_array_field_values { | 
| 37 | 0 |  |  | 0 | 0 |  | my ( $self, $stash, $field ) = @_; | 
| 38 | 0 | 0 | 0 |  |  |  | if( ! defined $stash->{$field} || ref($stash->{$field}) ne 'ARRAY' ) { | 
| 39 | 0 |  |  |  |  |  | return; | 
| 40 |  |  |  |  |  |  | } | 
| 41 | 0 |  |  |  |  |  | foreach my $test ( @{$stash->{$field}} ) { | 
|  | 0 |  |  |  |  |  |  | 
| 42 | 0 |  |  |  |  |  | $self->incr_host_one($stash, $field, $test ); | 
| 43 |  |  |  |  |  |  | } | 
| 44 | 0 |  |  |  |  |  | return; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | sub count_fields_value { | 
| 48 | 0 |  |  | 0 | 0 |  | my ( $self, $stash, @fields ) = @_; | 
| 49 | 0 |  |  |  |  |  | foreach my $field ( @fields ) { | 
| 50 | 0 | 0 |  |  |  |  | if( ! defined $stash->{$field} ) { next; } | 
|  | 0 |  |  |  |  |  |  | 
| 51 | 0 |  |  |  |  |  | $self->incr_host($stash, $field, $stash->{$field} ); | 
| 52 |  |  |  |  |  |  | } | 
| 53 | 0 |  |  |  |  |  | return; | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | sub count_fields_occur { | 
| 57 | 0 |  |  | 0 | 0 |  | my ( $self, $stash, @fields ) = @_; | 
| 58 | 0 |  |  |  |  |  | foreach my $field ( @fields ) { | 
| 59 | 0 | 0 |  |  |  |  | if( ! defined $stash->{$field} ) { next; } | 
|  | 0 |  |  |  |  |  |  | 
| 60 | 0 |  |  |  |  |  | $self->incr_host_one($stash, $field, $stash->{$field} ); | 
| 61 |  |  |  |  |  |  | } | 
| 62 | 0 |  |  |  |  |  | return; | 
| 63 |  |  |  |  |  |  | } | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | 1; | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | __END__ | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =pod | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =encoding UTF-8 | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =head1 NAME | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | Log::Saftpresse::Plugin::Role::CounterUtils - role for plugins to gather statistics/counters | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =head1 VERSION | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | version 1.6 | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =head1 AUTHOR | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | Markus Benning <ich@markusbenning.de> | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning. | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | This is free software, licensed under: | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | The GNU General Public License, Version 2, June 1991 | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | =cut |