| 1 | package Net::Whois::Norid; | ||
| 2 | |||
| 3 | use Net::Whois::Raw; | ||
| 4 | use strict; | ||
| 5 | |||
| 6 | our $VERSION='0.04'; | ||
| 7 | use vars qw/$AUTOLOAD/; | ||
| 8 | |||
| 9 | sub AUTOLOAD { | ||
| 10 | my $self=shift; | ||
| 11 | $AUTOLOAD =~ s/.*:://; | ||
| 12 | return $self->get($AUTOLOAD); | ||
| 13 | } | ||
| 14 | |||
| 15 | sub new { | ||
| 16 | my ($proto,$lookup)=@_; | ||
| 17 | my $class=ref $proto||$proto; | ||
| 18 | my $self=bless {},$class; | ||
| 19 | return $self unless $lookup; | ||
| 20 | $self->lookup($lookup); | ||
| 21 | return $self; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub get { | ||
| 25 | my ($self,$key) = @_; | ||
| 26 | $key=lc($key); | ||
| 27 | if (exists $self->{"${key}_handle"} ) { | ||
| 28 | my @objs=(map { $self->new($_) } | ||
| 29 | split (m/\n/,$self->{"${key}_handle"})); | ||
| 30 | return ( wantarray ? @objs : $objs[0] ); | ||
| 31 | } | ||
| 32 | return $self->{$key}; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub lookup { | ||
| 36 | my ($self,$lookup) = @_; | ||
| 37 | return $self->_parse(whois($lookup,'whois.norid.no')); | ||
| 38 | } | ||
| 39 | |||
| 40 | sub _parse { | ||
| 41 | my ($self,$whois)=@_; | ||
| 42 | foreach my $line (split("\n",$whois)) { | ||
| 43 | if (my ($key,$value) = $line =~ m/^(\w+[^.]+)\.{2,}\:\s*(.+)$/) { | ||
| 44 | # replace spaces and - with _ for accessors. | ||
| 45 | $key =~ y/ -/_/; | ||
| 46 | $key = lc($key); | ||
| 47 | $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<Net::Whois::Raw> 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<Net::Whois::Norid> | ||
| 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<Net::Whois::Raw> | ||
| 100 | L<http://www.norid.no> | ||
| 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<mramberg@cpan.org> | ||
| 111 | |||
| 112 | =head1 LICENSE | ||
| 113 | |||
| 114 | This module is distributed under the same terms as Perl itself. | ||
| 115 | |||
| 116 | 1; |