karpet / search-opensearch-feedparser

Search::OpenSearch::Response::XML parser
0 stars 0 forks source link

When build_time not in document, parse fails #1

Closed will-in-wi closed 9 years ago

will-in-wi commented 9 years ago

Error is

Undef did not pass type constraint "Num" (in $args->{"build_time"}) at (eval 128) line 60
"Num" is a subtype of "LaxNum"
"LaxNum" is a subtype of "Str"
"Str" is a subtype of "Value"
"Value" is a subtype of "Defined"
Undef did not pass type constraint "Defined" (in $args->{"build_time"})
"Defined" is defined as: (defined($_))

Code:

#!/usr/bin/env perl
use strict;
use warnings;
use File::Slurp;
use Data::Dump qw( dump );
use Search::OpenSearch::FeedParser;

my $feed_file = 'marketplace-feed-example.xml';
my $parser    = Search::OpenSearch::FeedParser->new();
my $feed_data = scalar read_file($feed_file);
# dump $feed_data;
my $feed      = $parser->parse( $feed_data );

Feed:

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
<id>http://www.marketplace.org/rss/app</id>
<title>Latest Stories on Marketplace.org</title>
<link rel="self" href="http://www.marketplace.org/rss/app?start=300&amp;rows=50"/>
<subtitle>Latest Stories from the Business World on Marketplace.org</subtitle>
<updated>2014-03-31T10:04:53-05:00</updated>
<opensearch:totalResults>1</opensearch:totalResults>
<opensearch:itemsPerPage>25</opensearch:itemsPerPage>
<opensearch:startIndex>1</opensearch:startIndex>
<entry>
  <id>http://www.marketplace.org/topics/health-care/another-delay-affordable-care-act</id>
  <link href="http://www.marketplace.org/topics/health-care/another-delay-affordable-care-act"/>
  <title>Another delay for the Affordable Care Act?</title>
  <published>2014-03-05T02:54:08-06:00</published>
  <updated>2014-03-05T10:21:23-06:00</updated>
  <summary type="html">
    <![CDATA[
    What happens if the implementation of healthcare reform is pushed back again?
    ]]>
  </summary>
  <author>
    <name>Nancy Marshall-Genzer</name>
  </author>
  <content type="application/xml">
    <fields xmlns="http://dezi.org/sos/schema">
      <nid>132221</nid>
      <body><![CDATA[<p>Remember last fall, when health insurers sent out cancellation letters because some policies didn't meet the Affordable Care Acts requirements? President Obama decided to let people keep those policies a while longer - in some cases, for a year.</p><p>Which means they'd be getting cancellation letters again this fall, right before the congressional elections. So the Obama administration could announce as soon as this week that it's rolling back the deadline for people to get off these barebones plans. How many people would be affected?</p><p>"Probably we're talking about thousands. Certainly not hundreds of thousands, " says former insurance executive Wendell Potter.</p><p>But these thousands of people could have an outsized impact if they decide to go without health insurance. That's because they're young and healthy -- just the kind of people the Affordable Care Act needs in its insurance pool.</p>]]></body>
      <audio nid="132221" fid="251701" url="http://download.publicradio.org/podcast/marketplace/segments/2014/03/05/marketplace_segment06_20140305_64.mp3" type=""/>
      <show>Marketplace Morning Report for Wednesday, March 5, 2014</show>
      <respond>no</respond>
      <syndications>
        <syndication>PMP</syndication>
      </syndications>
      <topics>
        <topic>Health Care</topic>
      </topics>
      <authors>
        <author>Nancy Marshall-Genzer</author>
      </authors>
      <picture primary="TRUE">
        <picture url="http://www.marketplace.org/sites/default/files/styles/primary-image-900x500/public/bpressure_0.jpg?itok=Qsgb4nRM" fid="190686" nid="132221" type="image/jpeg" isDefault="TRUE" caption="" credit="PHILIPPE HUGUEN/AFP/GettyImages"/>
        <picture url="http://www.marketplace.org/sites/default/files/styles/primary-image-610x340/public/bpressure_0.jpg?itok=a6GNWLtC" fid="190686" type="image/jpeg" isDefault="FALSE" caption="" credit="PHILIPPE HUGUEN/AFP/GettyImages"/>
      </picture>
    </fields>
  </content>
</entry>
</feed>
will-in-wi commented 9 years ago

It looks like when https://github.com/karpet/search-opensearch-feedparser/blob/master/lib/Search/OpenSearch/FeedParser.pm#L171 is Undef, https://github.com/karpet/search-opensearch-feedparser/blob/master/lib/Search/OpenSearch/Feed.pm#L16 fails.

karpet commented 9 years ago

master should have a fix. if that works for you, I can open a PR against APMG repo.

will-in-wi commented 9 years ago

It looks like that fixed the ticketed bug, although query is now also erroring.

Undef did not pass type constraint "Str" (in $args->{"query"}) at (eval 130) line 281
"Str" is a subtype of "Value"
"Value" is a subtype of "Defined"
Undef did not pass type constraint "Defined" (in $args->{"query"})
"Defined" is defined as: (defined($_))
pkarman commented 9 years ago

b8111c0 should make more attributes optional. 'query' in particular is defined as optional by the spec.

will-in-wi commented 9 years ago

It looks like that did it. Thanks!