Saftpresse/Plugin/GeoIP.pm

filter: Statementstmt 43.3% 13 / 30 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 2 / 5 Podpod 100% 1 / 1 totaltotal 38.1% 16 / 42 SCAR 24.4
CC
5
Cov
36%
process
30.0
__ANON__
2.0
__ANON__
2.0
CRAP 11.5
« Saftpresse/App.pm ↑ Summary Saftpresse/Plugin/Postfix/Smtp.pm »
1 package Log::Saftpresse::Plugin::GeoIP;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: plugin to lookup geoip database
6 1 our $VERSION = '1.5'; # VERSION
7  
8 1 extends 'Log::Saftpresse::Plugin';
9  
10 1 has 'address_fields' => ( is => 'ro', isa => 'Str', default => 'client_ip' );
11  
12 has '_address_fields' => ( is => 'ro', isa => 'ArrayRef', lazy => 1,
13 default => sub {
14 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
15 0 return( [ split(/\s*,\s*/, $self->address_fields) ] );
16 },
17 1 );
18  
19 1 ▶use Geo::IP;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 sub process {
22 0 ▶ my ( $self, $stash ) = @_;
Subroutine process: not called CC=5 SCAR=34.0
Pod documented
23 0 my $addr;
24  
25 0 foreach my $field ( @{$self->_address_fields} ) {
26 0 ▶ if( defined $stash->{$field} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stash->{$field}) 0 0 0
27 0 $addr = $stash->{'client_ip'};
28 }
29 }
30  
31 0 ▶ if( ! defined $addr ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $addr) 0 0 0
32 0 return;
33 }
34  
35 0 my $cc = $self->_geoip->country_code_by_addr( $addr );
36 0 ▶ if( defined $cc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cc) { } 0 0 0
37 0 $stash->{'geoip_cc'} = $cc;
38 } else {
39 0 $stash->{'geoip_cc'} = 'unknown';
40 }
41  
42 0 return;
43 }
44  
45 1 has 'database' => ( is => 'ro', isa => 'Str', default => '/usr/share/GeoIP/GeoIP.dat' );
46  
47 has '_geoip' => (
48 is => 'ro', isa => 'Geo::IP', lazy => 1,
49 default => sub {
50 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 0 return Geo::IP->open( $self->database, GEOIP_STANDARD );
52 },
53 1 );
54  
55 1 1;
56  
57 __END__
58  
59 =pod
60  
61 =encoding UTF-8
62  
63 =head1 NAME
64  
65 Log::Saftpresse::Plugin::GeoIP - plugin to lookup geoip database
66  
67 =head1 VERSION
68  
69 version 1.5
70  
71 =head1 AUTHOR
72  
73 Markus Benning <ich@markusbenning.de>
74  
75 =head1 COPYRIGHT AND LICENSE
76  
77 This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning.
78  
79 This is free software, licensed under:
80  
81 The GNU General Public License, Version 2, June 1991
82  
83 =cut
« Saftpresse/App.pm ↑ Summary Saftpresse/Plugin/Postfix/Smtp.pm »