File Coverage

blib/lib/Net/Whois/Norid.pm
Criterion Covered Total %
statement 26 33 78.7
branch 6 10 60.0
condition 1 3 33.3
subroutine 7 8 87.5
pod 3 3 100.0
total 43 57 75.4


line stmt bran cond sub pod time code
1             package Net::Whois::Norid;
2              
3 2     2   23358 use Net::Whois::Raw;
  2         172044  
  2         16  
4 2     2   115 use strict;
  2         5  
  2         92  
5              
6             our $VERSION='0.04';
7 2     2   19 use vars qw/$AUTOLOAD/;
  2         6  
  2         990  
8              
9             sub AUTOLOAD {
10 1     1   2 my $self=shift;
11 1         6 $AUTOLOAD =~ s/.*:://;
12 1         3 return $self->get($AUTOLOAD);
13             }
14              
15             sub new {
16 1     1 1 42 my ($proto,$lookup)=@_;
17 1   33     9 my $class=ref $proto||$proto;
18 1         4 my $self=bless {},$class;
19 1 50       6 return $self unless $lookup;
20 0         0 $self->lookup($lookup);
21 0         0 return $self;
22             }
23              
24             sub get {
25 8     8 1 21 my ($self,$key) = @_;
26 8         13 $key=lc($key);
27 8 50       22 if (exists $self->{"${key}_handle"} ) {
28 0         0 my @objs=(map { $self->new($_) }
  0         0  
29             split (m/\n/,$self->{"${key}_handle"}));
30 0 0       0 return ( wantarray ? @objs : $objs[0] );
31             }
32 8         36 return $self->{$key};
33             }
34              
35             sub lookup {
36 0     0 1 0 my ($self,$lookup) = @_;
37 0         0 return $self->_parse(whois($lookup,'whois.norid.no'));
38             }
39              
40             sub _parse {
41 1     1   6 my ($self,$whois)=@_;
42 1         12 foreach my $line (split("\n",$whois)) {
43 32 100       108 if (my ($key,$value) = $line =~ m/^(\w+[^.]+)\.{2,}\:\s*(.+)$/) {
44             # replace spaces and - with _ for accessors.
45 18         20 $key =~ y/ -/_/;
46 18         21 $key = lc($key);
47 18 100       54 $self->{$key} =
48             ($self->{$key} ? $self->{$key}."\n$value" : $value);
49             }
50             }
51             }
52              
53             =head1 NAME
54              
55             Net::Whois::Norid - Lookup WHOIS data from norid.
56              
57             =head1 SYNOPSIS
58              
59             my $whois = Net::Whois::Norid->new('thefeed.no');
60             print $whois->post_address;
61             print $whois->organization->fax_number;
62              
63             =head1 DESCRIPTION
64              
65             This module provides an object oriented API for use with the
66             Norid whois service. It uses L internally to
67             fetch information from Norid.
68              
69             =head2 METHODS
70              
71             =over 4
72              
73             =item new
74              
75             The constructor. Takes a lookup argument. Returns a new object.
76              
77             =item lookup
78              
79             Do a whois lookup in the Norid database and populate the object
80             from the result.
81              
82             =item get
83              
84             Use this to access any data parsed. Note that spaces and '-'s will be
85             converted to underscores (_). For the special "Handle" entries,
86             omitting the _Handle part will return a new L
87             object. The method is a case insensitive.
88              
89             =item AUTOLOAD
90              
91             This module uses the autoload mechanism to provide accessors for any
92             available data through the get mechanism above.
93              
94              
95             =back
96              
97             =head1 SEE ALSO
98              
99             L
100             L
101              
102             =head1 CAVEATS
103              
104             Some rows in the whois data might appear more than once. in that
105             case they are separated with line space. For objects, an array
106             is returned.
107              
108             =head1 AUTHOR
109              
110             Marcus Ramberg C
111              
112             =head1 LICENSE
113              
114             This module is distributed under the same terms as Perl itself.
115              
116             1;