Skip to content

Commit c7c203a

Browse files
committed
use XML::XPath for parsing 00whois.xml
XML::Simple is not recommended because it is hard to use correctly. We can use XML::XPath instead, and the code is actually simpler.
1 parent bcb9d8d commit c7c203a

File tree

3 files changed

+41
-74
lines changed

3 files changed

+41
-74
lines changed

cpanfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ requires 'Types::URI';
139139
requires 'Twitter::API', '1.0006';
140140
requires 'URI', '5.10';
141141
requires 'version', '0.9929';
142-
requires 'XML::Simple';
142+
requires 'XML::XPath';
143143
requires 'YAML::XS', '0.83'; # Mojolicious::Plugin::OpenAPI YAML loading
144144

145145
# test requirements

cpanfile.snapshot

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7226,17 +7226,6 @@ DISTRIBUTIONS
72267226
Fcntl 0
72277227
URI 1.10
72287228
perl 5.008001
7229-
XML-NamespaceSupport-1.12
7230-
pathname: P/PE/PERIGRIN/XML-NamespaceSupport-1.12.tar.gz
7231-
provides:
7232-
XML::NamespaceSupport 1.12
7233-
requirements:
7234-
ExtUtils::MakeMaker 6.17
7235-
constant 0
7236-
perl 5.006
7237-
strict 0
7238-
vars 0
7239-
warnings 0
72407229
XML-Parser-2.47
72417230
pathname: T/TO/TODDR/XML-Parser-2.47.tar.gz
72427231
provides:
@@ -7251,54 +7240,39 @@ DISTRIBUTIONS
72517240
ExtUtils::MakeMaker 0
72527241
LWP::UserAgent 0
72537242
perl 5.004050
7254-
XML-SAX-1.02
7255-
pathname: G/GR/GRANTM/XML-SAX-1.02.tar.gz
7256-
provides:
7257-
XML::SAX 1.02
7258-
XML::SAX::DocumentLocator undef
7259-
XML::SAX::ParserFactory 1.02
7260-
XML::SAX::PurePerl 1.02
7261-
XML::SAX::PurePerl::DebugHandler undef
7262-
XML::SAX::PurePerl::Exception undef
7263-
XML::SAX::PurePerl::Productions undef
7264-
XML::SAX::PurePerl::Reader undef
7265-
XML::SAX::PurePerl::Reader::Stream undef
7266-
XML::SAX::PurePerl::Reader::String undef
7267-
XML::SAX::PurePerl::Reader::URI undef
7268-
requirements:
7269-
ExtUtils::MakeMaker 0
7270-
File::Temp 0
7271-
XML::NamespaceSupport 0.03
7272-
XML::SAX::Base 1.05
7273-
XML-SAX-Base-1.09
7274-
pathname: G/GR/GRANTM/XML-SAX-Base-1.09.tar.gz
7275-
provides:
7276-
XML::SAX::Base 1.09
7277-
XML::SAX::Base::NoHandler 1.09
7278-
XML::SAX::Exception 1.09
7279-
requirements:
7280-
ExtUtils::MakeMaker 0
7281-
perl 5.008
7282-
XML-SAX-Expat-0.51
7283-
pathname: B/BJ/BJOERN/XML-SAX-Expat-0.51.tar.gz
7284-
provides:
7285-
XML::SAX::Expat 0.51
7286-
requirements:
7287-
ExtUtils::MakeMaker 0
7288-
XML::NamespaceSupport 0.03
7289-
XML::Parser 2.27
7290-
XML::SAX 0.03
7291-
XML::SAX::Base 1.00
7292-
XML-Simple-2.25
7293-
pathname: G/GR/GRANTM/XML-Simple-2.25.tar.gz
7294-
provides:
7295-
XML::Simple 2.25
7296-
requirements:
7297-
ExtUtils::MakeMaker 0
7298-
XML::NamespaceSupport 1.04
7299-
XML::SAX 0.15
7300-
XML::SAX::Expat 0
7301-
perl 5.008
7243+
XML-XPath-1.48
7244+
pathname: M/MA/MANWAR/XML-XPath-1.48.tar.gz
7245+
provides:
7246+
XML::XPath 1.48
7247+
XML::XPath::Boolean 1.48
7248+
XML::XPath::Builder 1.48
7249+
XML::XPath::Expr 1.48
7250+
XML::XPath::Function 1.48
7251+
XML::XPath::Literal 1.48
7252+
XML::XPath::LocationPath 1.48
7253+
XML::XPath::Node 1.48
7254+
XML::XPath::Node::Attribute 1.48
7255+
XML::XPath::Node::AttributeImpl 1.48
7256+
XML::XPath::Node::Comment 1.48
7257+
XML::XPath::Node::Element 1.48
7258+
XML::XPath::Node::Namespace 1.48
7259+
XML::XPath::Node::PI 1.48
7260+
XML::XPath::Node::Text 1.48
7261+
XML::XPath::NodeSet 1.48
7262+
XML::XPath::Number 1.48
7263+
XML::XPath::Parser 1.48
7264+
XML::XPath::PerlSAX 1.48
7265+
XML::XPath::Root 1.48
7266+
XML::XPath::Step 1.48
7267+
XML::XPath::Variable 1.48
7268+
XML::XPath::XMLParser 1.48
7269+
requirements:
7270+
ExtUtils::MakeMaker 0
7271+
Path::Tiny 0.076
7272+
Scalar::Util 1.45
7273+
Test::More 0
7274+
XML::Parser 2.23
7275+
perl 5.010001
73027276
XString-0.005
73037277
pathname: A/AT/ATOOMIC/XString-0.005.tar.gz
73047278
provides:

lib/MetaCPAN/Script/Author.pm

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use Cpanel::JSON::XS qw( decode_json );
1313
use Log::Contextual qw( :log :dlog );
1414
use MetaCPAN::Document::Author ();
1515
use URI ();
16-
use XML::Simple qw( XMLin );
16+
use XML::XPath ();
1717
use MetaCPAN::Types::TypeTiny qw( Str );
1818
use MetaCPAN::Util qw(diff_struct);
1919

@@ -87,23 +87,16 @@ has whois_data => (
8787

8888
sub _build_whois_data {
8989
my $self = shift;
90-
my $data = XMLin(
91-
$self->author_fh,
92-
ForceArray => 1,
93-
SuppressEmpty => '',
94-
NoAttr => 1,
95-
KeyAttr => [],
96-
);
9790

9891
my $whois_data = {};
9992

100-
for my $author ( @{ $data->{cpanid} } ) {
93+
my $xp = XML::XPath->new( filename => $self->author_fh );
94+
95+
for my $author ( $xp->find('/cpan-whois/cpanid')->get_nodelist ) {
10196
my $data = {
102-
map {
103-
my $content = $author->{$_};
104-
@$content == 1
105-
&& !ref $content->[0] ? ( $_ => $content->[0] ) : ();
106-
} keys %$author
97+
map +( $_->getLocalName, $_->string_value ),
98+
grep $_->isa('XML::XPath::Node::Element'),
99+
$author->getChildNodes
107100
};
108101

109102
my $pauseid = $data->{id};

0 commit comments

Comments
 (0)