MtPolicyd/Plugin/GeoIPLookup.pm

filter: Statementstmt 64.2% 18 / 28 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 100% 1 / 1 totaltotal 60.5% 23 / 38 CC 2 SCAR 9.2
CC
2
Cov
60%
run
6.0
__ANON__
2.0
__ANON__
2.0
CRAP 2.5
« MtPolicyd/Plugin/Role/SqlUtils.pm ↑ Summary MtPolicyd/Profiler/Timer.pm »
1 package Mail::MtPolicyd::Plugin::GeoIPLookup;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '2.01'; # VERSION
7 # ABSTRACT: mtpolicyd plugin for checking geo information of an client_address
8  
9 1 extends 'Mail::MtPolicyd::Plugin';
10  
11 1 ▶use Mail::MtPolicyd::Plugin::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Geo::IP;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 has '_geoip' => (
17 is => 'ro', isa => 'Geo::IP', lazy => 1,
18 default => sub {
19 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 0 Geo::IP->open( $self->database, GEOIP_STANDARD );
21 },
22 1 );
23  
24 1 has 'database' => ( is => 'rw', isa => 'Str', default => '/usr/share/GeoIP/GeoIP.dat');
25  
26 sub run {
27 0 ▶ my ( $self, $r ) = @_;
Subroutine run: not called CC=2 SCAR=17.9
Pod documented
28 0 my $ip = $r->attr('client_address');
29 0 my $session = $r->session;
30  
31 my ( $result ) = $r->do_cached('geoip-'.$self->name.'-result',
32 0 ▶ sub { $self->_geoip->country_code_by_addr( $ip ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
33  
34 0 ▶ if( ! defined $result ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 0 0 0
35 0 $self->log($r, 'no GeoIP record for '.$ip.' found');
36 }
37  
38 0 return;
39 }
40  
41 1 __PACKAGE__->meta->make_immutable;
42  
43 1 1;
44  
45 __END__
46  
47 =pod
48  
49 =encoding UTF-8
50  
51 =head1 NAME
52  
53 Mail::MtPolicyd::Plugin::GeoIPLookup - mtpolicyd plugin for checking geo information of an client_address
54  
55 =head1 VERSION
56  
57 version 2.01
58  
59 =head1 DESCRIPTION
60  
61 This plugin queries a GeoIP for the country code of the client_address.
62 The plugin is divided in this plugin which does the Lookup and the GeoIPAction
63 plugin which can be used to take actions based on country code.
64  
65 =head1 PARAMETERS
66  
67 =over
68  
69 =item database (default: /usr/share/GeoIP/GeoIP.dat)
70  
71 The path to the geoip country database.
72  
73 =back
74  
75 =head1 MAXMIND GEOIP COUNTRY DATABASE
76  
77 On a debian system you can install the country database with the geoip-database package.
78  
79 You also download it directly from Maxmind:
80  
81 http://dev.maxmind.com/geoip/geoip2/geolite2/
82  
83 (choose "GeoLite2 Country/DB")
84  
85 =head1 AUTHOR
86  
87 Markus Benning <ich@markusbenning.de>
88  
89 =head1 COPYRIGHT AND LICENSE
90  
91 This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.
92  
93 This is free software, licensed under:
94  
95 The GNU General Public License, Version 2, June 1991
96  
97 =cut
« MtPolicyd/Plugin/Role/SqlUtils.pm ↑ Summary MtPolicyd/Profiler/Timer.pm »