Skip to content

Commit

Permalink
use XML::XPath for parsing 00whois.xml
Browse files Browse the repository at this point in the history
XML::Simple is not recommended because it is hard to use correctly. We
can use XML::XPath instead, and the code is actually simpler.
  • Loading branch information
haarg committed Jul 7, 2024
1 parent bcb9d8d commit c7c203a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 74 deletions.
2 changes: 1 addition & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ requires 'Types::URI';
requires 'Twitter::API', '1.0006';
requires 'URI', '5.10';
requires 'version', '0.9929';
requires 'XML::Simple';
requires 'XML::XPath';
requires 'YAML::XS', '0.83'; # Mojolicious::Plugin::OpenAPI YAML loading

# test requirements
Expand Down
92 changes: 33 additions & 59 deletions cpanfile.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -7226,17 +7226,6 @@ DISTRIBUTIONS
Fcntl 0
URI 1.10
perl 5.008001
XML-NamespaceSupport-1.12
pathname: P/PE/PERIGRIN/XML-NamespaceSupport-1.12.tar.gz
provides:
XML::NamespaceSupport 1.12
requirements:
ExtUtils::MakeMaker 6.17
constant 0
perl 5.006
strict 0
vars 0
warnings 0
XML-Parser-2.47
pathname: T/TO/TODDR/XML-Parser-2.47.tar.gz
provides:
Expand All @@ -7251,54 +7240,39 @@ DISTRIBUTIONS
ExtUtils::MakeMaker 0
LWP::UserAgent 0
perl 5.004050
XML-SAX-1.02
pathname: G/GR/GRANTM/XML-SAX-1.02.tar.gz
provides:
XML::SAX 1.02
XML::SAX::DocumentLocator undef
XML::SAX::ParserFactory 1.02
XML::SAX::PurePerl 1.02
XML::SAX::PurePerl::DebugHandler undef
XML::SAX::PurePerl::Exception undef
XML::SAX::PurePerl::Productions undef
XML::SAX::PurePerl::Reader undef
XML::SAX::PurePerl::Reader::Stream undef
XML::SAX::PurePerl::Reader::String undef
XML::SAX::PurePerl::Reader::URI undef
requirements:
ExtUtils::MakeMaker 0
File::Temp 0
XML::NamespaceSupport 0.03
XML::SAX::Base 1.05
XML-SAX-Base-1.09
pathname: G/GR/GRANTM/XML-SAX-Base-1.09.tar.gz
provides:
XML::SAX::Base 1.09
XML::SAX::Base::NoHandler 1.09
XML::SAX::Exception 1.09
requirements:
ExtUtils::MakeMaker 0
perl 5.008
XML-SAX-Expat-0.51
pathname: B/BJ/BJOERN/XML-SAX-Expat-0.51.tar.gz
provides:
XML::SAX::Expat 0.51
requirements:
ExtUtils::MakeMaker 0
XML::NamespaceSupport 0.03
XML::Parser 2.27
XML::SAX 0.03
XML::SAX::Base 1.00
XML-Simple-2.25
pathname: G/GR/GRANTM/XML-Simple-2.25.tar.gz
provides:
XML::Simple 2.25
requirements:
ExtUtils::MakeMaker 0
XML::NamespaceSupport 1.04
XML::SAX 0.15
XML::SAX::Expat 0
perl 5.008
XML-XPath-1.48
pathname: M/MA/MANWAR/XML-XPath-1.48.tar.gz
provides:
XML::XPath 1.48
XML::XPath::Boolean 1.48
XML::XPath::Builder 1.48
XML::XPath::Expr 1.48
XML::XPath::Function 1.48
XML::XPath::Literal 1.48
XML::XPath::LocationPath 1.48
XML::XPath::Node 1.48
XML::XPath::Node::Attribute 1.48
XML::XPath::Node::AttributeImpl 1.48
XML::XPath::Node::Comment 1.48
XML::XPath::Node::Element 1.48
XML::XPath::Node::Namespace 1.48
XML::XPath::Node::PI 1.48
XML::XPath::Node::Text 1.48
XML::XPath::NodeSet 1.48
XML::XPath::Number 1.48
XML::XPath::Parser 1.48
XML::XPath::PerlSAX 1.48
XML::XPath::Root 1.48
XML::XPath::Step 1.48
XML::XPath::Variable 1.48
XML::XPath::XMLParser 1.48
requirements:
ExtUtils::MakeMaker 0
Path::Tiny 0.076
Scalar::Util 1.45
Test::More 0
XML::Parser 2.23
perl 5.010001
XString-0.005
pathname: A/AT/ATOOMIC/XString-0.005.tar.gz
provides:
Expand Down
21 changes: 7 additions & 14 deletions lib/MetaCPAN/Script/Author.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Cpanel::JSON::XS qw( decode_json );
use Log::Contextual qw( :log :dlog );
use MetaCPAN::Document::Author ();
use URI ();
use XML::Simple qw( XMLin );
use XML::XPath ();
use MetaCPAN::Types::TypeTiny qw( Str );
use MetaCPAN::Util qw(diff_struct);

Expand Down Expand Up @@ -87,23 +87,16 @@ has whois_data => (

sub _build_whois_data {
my $self = shift;
my $data = XMLin(
$self->author_fh,
ForceArray => 1,
SuppressEmpty => '',
NoAttr => 1,
KeyAttr => [],
);

my $whois_data = {};

for my $author ( @{ $data->{cpanid} } ) {
my $xp = XML::XPath->new( filename => $self->author_fh );

for my $author ( $xp->find('/cpan-whois/cpanid')->get_nodelist ) {
my $data = {
map {
my $content = $author->{$_};
@$content == 1
&& !ref $content->[0] ? ( $_ => $content->[0] ) : ();
} keys %$author
map +( $_->getLocalName, $_->string_value ),
grep $_->isa('XML::XPath::Node::Element'),
$author->getChildNodes
};

my $pauseid = $data->{id};
Expand Down

0 comments on commit c7c203a

Please sign in to comment.