| 1 | # vim: sts=3 sw=3 et | ||||||||||||||
| 2 | package Parse::CPAN::Whois; | ||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 1 | our $VERSION='0.02'; | |||||||||||||
| 7 | |||||||||||||||
| 8 | =head1 NAME | ||||||||||||||
| 9 | |||||||||||||||
| 10 | Parse::CPAN::Whois - Parse CPAN's authors/00whois.xml file | ||||||||||||||
| 11 | |||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||
| 13 | |||||||||||||||
| 14 | CPAN has two author indices, "01mailrc.txt.gz", which L<Parse::CPAN::Authors> parses for you, and "00whois.xml", which is handled by this module. | ||||||||||||||
| 15 | |||||||||||||||
| 16 | It tries to be API-compatible with L<Parse::CPAN::Authors>, while providing | ||||||||||||||
| 17 | access to the extra information "00whois.xml" has over "01mailrc.txt.gz". | ||||||||||||||
| 18 | |||||||||||||||
| 19 | =cut | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 1 | ▶ | use XML::SAX::ParserFactory; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | 1 | ▶ | use Parse::CPAN::Whois::Author; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 23 | |||||||||||||||
| 24 | 1 | ▶ | use base qw(XML::SAX::Base); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 25 | |||||||||||||||
| 26 | =head1 METHODS | ||||||||||||||
| 27 | |||||||||||||||
| 28 | =head2 new FILENAME|DATA | ||||||||||||||
| 29 | |||||||||||||||
| 30 | new() takes either a path or a scalar containing the data to parse | ||||||||||||||
| 31 | as an argument. It parses the data, and then returns an object you | ||||||||||||||
| 32 | can query for PAUSE ids. | ||||||||||||||
| 33 | |||||||||||||||
| 34 | =cut | ||||||||||||||
| 35 | |||||||||||||||
| 36 | 1 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||
| 37 | 1 | my $class = shift; | |||||||||||||
| 38 | 1 | my $file = shift; | |||||||||||||
| 39 | |||||||||||||||
| 40 | 1 | ▶ | $file = '00whois.xml' unless (defined $file); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | |||||||||||||||
| 42 | 1 | my $handler = $class->SUPER::new; | |||||||||||||
| 43 | 1 | my $p = XML::SAX::ParserFactory->parser(Handler => $handler); | |||||||||||||
| 44 | 1 | ▶ | if (substr ($file, 0, 1) eq '<') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | 0 | $p->parse_string ($file); | |||||||||||||
| 46 | } else { | ||||||||||||||
| 47 | 1 | $p->parse_file($file); | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 1 | return delete $handler->{list}; | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | =head2 author PAUSEID | ||||||||||||||
| 54 | |||||||||||||||
| 55 | returns the L<Parse::CPAN::Whois::Author> object that corresponds to | ||||||||||||||
| 56 | the PAUSE id. | ||||||||||||||
| 57 | |||||||||||||||
| 58 | =cut | ||||||||||||||
| 59 | |||||||||||||||
| 60 | 2 | ▶ | sub author { | ||||||||||||
|
Subroutine
author: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 61 | 2 | my $self = shift; | |||||||||||||
| 62 | 2 | my $cpanid = shift; | |||||||||||||
| 63 | |||||||||||||||
| 64 | 2 | return $self->{uc($cpanid)} | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | |||||||||||||||
| 67 | =head2 authors | ||||||||||||||
| 68 | |||||||||||||||
| 69 | returns a list of L<Parse::CPAN::Whois::Author> objects. | ||||||||||||||
| 70 | |||||||||||||||
| 71 | =cut | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 0 | ▶ | sub authors { | ||||||||||||
|
Subroutine
authors: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 74 | 0 | my $self = shift; | |||||||||||||
| 75 | |||||||||||||||
| 76 | 0 | return values %$self; | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | |||||||||||||||
| 80 | # below are the SAX2 methods used. | ||||||||||||||
| 81 | |||||||||||||||
| 82 | |||||||||||||||
| 83 | 38 | ▶ | sub start_element { | ||||||||||||
|
Subroutine
start_element: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 84 | 38 | my $self = shift; | |||||||||||||
| 85 | 38 | my $elem = shift; | |||||||||||||
| 86 | |||||||||||||||
| 87 | 38 | ▶ | if ($elem->{LocalName} eq 'cpan-whois') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 88 | 1 | $self->{list} = bless {}, 'Parse::CPAN::Whois'; | |||||||||||||
| 89 | } elsif ($elem->{LocalName} eq 'cpanid') { | ||||||||||||||
| 90 | 5 | $self->{tmp} = bless {}, 'Parse::CPAN::Whois::Author'; | |||||||||||||
| 91 | } else { | ||||||||||||||
| 92 | 32 | $self->{key} = $elem->{LocalName}; | |||||||||||||
| 93 | 32 | $self->{value} = ''; | |||||||||||||
| 94 | } | ||||||||||||||
| 95 | } | ||||||||||||||
| 96 | |||||||||||||||
| 97 | 75 | ▶ | sub characters { | ||||||||||||
|
Subroutine
characters: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 98 | 75 | my $self = shift; | |||||||||||||
| 99 | 75 | my $data = shift; | |||||||||||||
| 100 | |||||||||||||||
| 101 | 75 | ▶ | if (defined $self->{value}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 102 | 32 | $self->{value} .= $data->{Data}; | |||||||||||||
| 103 | } | ||||||||||||||
| 104 | } | ||||||||||||||
| 105 | |||||||||||||||
| 106 | 38 | ▶ | sub end_element { | ||||||||||||
|
Subroutine
end_element: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||
| 107 | 38 | my $self = shift; | |||||||||||||
| 108 | 38 | my $elem = shift; | |||||||||||||
| 109 | |||||||||||||||
| 110 | 38 | ▶ | if ($elem->{LocalName} eq 'cpan-whois') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 111 | } elsif ($elem->{LocalName} eq 'cpanid') { | ||||||||||||||
| 112 | 5 | my $id = $self->{tmp}->{id}; | |||||||||||||
| 113 | 5 | my $foo = delete $self->{tmp}; | |||||||||||||
| 114 | 5 | ▶ | if ($foo->{type} eq 'author') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 115 | 4 | $self->{list}->{$id} = $foo; | |||||||||||||
| 116 | } | ||||||||||||||
| 117 | } else { | ||||||||||||||
| 118 | 32 | $self->{tmp}->{delete $self->{key}} = delete $self->{value}; | |||||||||||||
| 119 | } | ||||||||||||||
| 120 | } | ||||||||||||||
| 121 | |||||||||||||||
| 122 | 1 | 1; | |||||||||||||
| 123 | |||||||||||||||
| 124 | __END__ | ||||||||||||||