File Coverage

blib/lib/DNS/BL/Entry.pm
Criterion Covered Total %
statement 41 45 91.1
branch 10 10 100.0
condition n/a
subroutine 11 12 91.6
pod 4 4 100.0
total 66 71 92.9


line stmt bran cond sub pod time code
1             package DNS::BL::Entry;
2              
3 3     3   3614 use 5.006001;
  3         10  
  3         113  
4 3     3   15 use strict;
  3         5  
  3         98  
5 3     3   15 use warnings;
  3         4  
  3         137  
6              
7 3     3   1810 use NetAddr::IP 3;
  3         64629  
  3         26  
8              
9             our $VERSION = '0.00_01';
10             $VERSION = eval $VERSION; # see L
11              
12             sub new
13             {
14 37     37 1 729 return bless
15             {
16             addr => undef,
17             desc => undef,
18             value => '127.0.0.1',
19             time => time,
20             }, $_[0];
21             }
22              
23             sub clone
24             {
25 0     0 1 0 my $o = shift;
26 0         0 my $n = __PACKAGE__->new;
27 0         0 $n->$_($o->$_()) for qw/addr desc value time/;
28 0         0 return $n;
29             }
30              
31             # We'll let AUTOLOAD provide an accessor automatically for
32             # each parameter we get asked to produce.
33              
34             sub AUTOLOAD
35             {
36 3     3   856 no strict "refs";
  3         7  
  3         113  
37 3     3   25 use vars qw($AUTOLOAD);
  3         6  
  3         1090  
38 4     4   711 my $method = $AUTOLOAD;
39 4         22 $method =~ s/^.*:://;
40             *$method = sub
41             {
42 19     19   1799 my $self = shift;
43 19         44 my $ret = $self->{$method};
44 19 100       54 $self->{$method} = shift if @_;
45 19         63 return $ret;
46 4         27 };
47 4         14 goto \&$method;
48             }
49              
50             # The following accessors provide trivial tests over its arguments,
51             # so we provide them manually.
52              
53             sub addr
54             {
55 51     51 1 6071 my $self = shift;
56 51         100 my $ret = $self->{addr};
57 51 100       134 if (@_)
58             {
59 42         153 my $ip = new NetAddr::IP shift;
60 42 100       14239 return $ret unless $ip;
61 41         10721 $self->{addr} = $ip;
62             }
63 50         134 return $ret;
64             }
65              
66             sub time
67             {
68 15     15 1 686 my $self = shift;
69 15         18 my $ret = $self->{time};
70 15 100       31 if (@_)
71             {
72 6         8 my $time = shift;
73 6 100       32 return $ret unless $time =~ /^\d+$/;
74 5         49 $self->{time} = $time;
75             }
76 14         49 return $ret;
77             }
78              
79             1;
80             __END__