Parse::CPAN::Whois - Parse CPAN's authors/00whois.xml file


Parse-CPAN-Whois documentation Contained in the Parse-CPAN-Whois distribution.

Index


Code Index:

NAME

Top

Parse::CPAN::Whois - Parse CPAN's authors/00whois.xml file

DESCRIPTION

Top

CPAN has two author indices, "01mailrc.txt.gz", which Parse::CPAN::Authors parses for you, and "00whois.xml", which is handled by this module.

It tries to be API-compatible with Parse::CPAN::Authors, while providing access to the extra information "00whois.xml" has over "01mailrc.txt.gz".

METHODS

Top

new FILENAME|DATA

new() takes either a path or a scalar containing the data to parse as an argument. It parses the data, and then returns an object you can query for PAUSE ids.

author PAUSEID

returns the Parse::CPAN::Whois::Author object that corresponds to the PAUSE id.

authors

returns a list of Parse::CPAN::Whois::Author objects.

SEE ALSO

Top

Parse::CPAN::Authors

AUTHOR

Top

Martijn van Beers <martijn@cpan.org>

LICENSE

Top

Copyright (c) 2008, Martijn van Beers

This module is free software; you can redistribute it or modify it under the GPL, version 2 or higher. See the LICENSE file for details.


Parse-CPAN-Whois documentation Contained in the Parse-CPAN-Whois distribution.
# vim: sts=3 sw=3 et
package Parse::CPAN::Whois;
use strict;
use warnings;

our $VERSION='0.02';

use XML::SAX::ParserFactory;
use Parse::CPAN::Whois::Author;

use base qw(XML::SAX::Base);

sub new {
   my $class = shift;
   my $file = shift;

   $file = '00whois.xml' unless (defined $file);

   my $handler = $class->SUPER::new;
   my $p = XML::SAX::ParserFactory->parser(Handler => $handler);
   if (substr ($file, 0, 1) eq '<') {
      $p->parse_string ($file);
   } else {
      $p->parse_file($file);
   }

   return delete $handler->{list};
}

sub author {
   my $self = shift;
   my $cpanid = shift;

   return $self->{uc($cpanid)}
}

sub authors {
   my $self = shift;

   return values %$self;
}


# below are the SAX2 methods used.


sub start_element {
   my $self = shift;
   my $elem = shift;

   if ($elem->{LocalName} eq 'cpan-whois') {
      $self->{list} = bless {}, 'Parse::CPAN::Whois';
   } elsif ($elem->{LocalName} eq 'cpanid') {
      $self->{tmp} = bless {}, 'Parse::CPAN::Whois::Author';
   } else {
      $self->{key} = $elem->{LocalName};
      $self->{value} = '';
   }
}

sub characters {
   my $self = shift;
   my $data = shift;

   if (defined $self->{value}) {
      $self->{value} .= $data->{Data};
   }
}

sub end_element {
   my $self = shift;
   my $elem = shift;

   if ($elem->{LocalName} eq 'cpan-whois') {
   } elsif ($elem->{LocalName} eq 'cpanid') {
      my $id = $self->{tmp}->{id};
      my $foo = delete $self->{tmp};
      if ($foo->{type} eq 'author') {
         $self->{list}->{$id} = $foo;
      }
   } else {
      $self->{tmp}->{delete $self->{key}} = delete $self->{value};
   }
}

1;

__END__