File Coverage

blib/lib/Net/DNSBLLookup/Result.pm
Criterion Covered Total %
statement 18 51 35.2
branch 0 14 0.0
condition 0 3 0.0
subroutine 6 11 54.5
pod 1 5 20.0
total 25 84 29.7


line stmt bran cond sub pod time code
1             package Net::DNSBLLookup::Result;
2              
3 1     1   4 use Net::DNSBLLookup;
  1         2  
  1         87  
4              
5 1     1   6 use strict;
  1         1  
  1         37  
6              
7 1     1   5 use constant DNSBLLOOKUP_RESULT_OPEN_PROXY => 1;
  1         2  
  1         48  
8 1     1   5 use constant DNSBLLOOKUP_RESULT_SPAM => 2;
  1         1  
  1         41  
9 1     1   4 use constant DNSBLLOOKUP_RESULT_UNKNOWN => 3;
  1         1  
  1         29  
10 1     1   4 use constant DNSBLLOOKUP_RESULT_DYNAMIC_IP => 4;
  1         1  
  1         767  
11              
12             my %result_type = (
13             DNSBLLOOKUP_OPEN_RELAY() => DNSBLLOOKUP_RESULT_SPAM,
14             DNSBLLOOKUP_DYNAMIC_IP() => DNSBLLOOKUP_RESULT_DYNAMIC_IP,
15             DNSBLLOOKUP_CONFIRMED_SPAM() => DNSBLLOOKUP_RESULT_SPAM,
16             DNSBLLOOKUP_SMARTHOST() => DNSBLLOOKUP_RESULT_SPAM,
17             DNSBLLOOKUP_SPAMHOUSE() => DNSBLLOOKUP_RESULT_SPAM,
18             DNSBLLOOKUP_LISTSERVER() => DNSBLLOOKUP_RESULT_SPAM,
19             DNSBLLOOKUP_FORMMAIL() => DNSBLLOOKUP_RESULT_SPAM,
20             DNSBLLOOKUP_OPEN_PROXY() => DNSBLLOOKUP_RESULT_OPEN_PROXY,
21             DNSBLLOOKUP_OPEN_PROXY_HTTP() => DNSBLLOOKUP_RESULT_OPEN_PROXY,
22             DNSBLLOOKUP_OPEN_PROXY_SOCKS() => DNSBLLOOKUP_RESULT_OPEN_PROXY,
23             DNSBLLOOKUP_OPEN_PROXY_MISC() => DNSBLLOOKUP_RESULT_OPEN_PROXY,
24             DNSBLLOOKUP_HIJACKED() => DNSBLLOOKUP_RESULT_SPAM,
25             DNSBLLOOKUP_MULTI_OPEN_RELAY() => DNSBLLOOKUP_RESULT_SPAM,
26             DNSBLLOOKUP_UNKNOWN() => DNSBLLOOKUP_RESULT_UNKNOWN,
27             );
28              
29             sub new {
30 0     0 0   my ($class) = @_;
31 0           my $self = bless {}, $class;
32 0           $self->{results} = {};
33 0           return $self;
34             }
35              
36             sub add {
37 0     0 0   my ($self, $dnsbl, $address) = @_;
38 0           my $address_lookup = $Net::DNSBLLookup::dns_servers{$dnsbl};
39 0 0         if (ref($address_lookup) eq 'HASH') {
    0          
40 0           push @{$self->{results}->{$dnsbl}}, $address_lookup->{$address};
  0            
41             } elsif (ref($address_lookup) eq 'CODE') {
42 0           push @{$self->{results}->{$dnsbl}}, &$address_lookup($address);
  0            
43             }
44             }
45              
46             sub add_dnsbl {
47 0     0 0   my ($self, $dnsbl) = @_;
48 0           $self->{dnsbl_responded}->{$dnsbl} = 1;
49             }
50              
51             sub num_proxies_responded {
52 0     0 0   my ($self) = @_;
53 0           return scalar(keys %{$self->{dnsbl_responded}});
  0            
54             }
55              
56             sub breakdown {
57 0     0 1   my ($self) = @_;
58 0           my ($total_spam, $total_proxy, $total_unknown) = (0,0,0);
59 0 0         return unless exists $self->{results};
60 0           while (my ($dnsbl, $v) = each %{$self->{results}}) {
  0            
61 0           my ($is_spam, $is_proxy, $is_unknown) = (0,0,0);
62 0           for my $retval (@$v) {
63 0           my $result_type = $result_type{$retval};
64 0 0         if ($result_type == DNSBLLOOKUP_RESULT_OPEN_PROXY) {
    0          
    0          
65 0           $is_proxy = 1;
66             } elsif ($result_type == DNSBLLOOKUP_RESULT_SPAM) {
67 0           $is_spam = 1;
68             } elsif ($result_type == DNSBLLOOKUP_RESULT_UNKNOWN) {
69 0           $is_unknown = 1;
70             }
71             }
72 0           $total_proxy += $is_proxy;
73 0           $total_spam += $is_spam;
74 0 0 0       unless ($is_proxy || $is_spam) {
75 0           $total_unknown += $is_unknown;
76             }
77             }
78 0           return ($total_proxy, $total_spam, $total_unknown);
79             }
80              
81             1;
82              
83             __END__