neilwatson has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Avout.
Why does this code not return feed titles or URLs? Even the dump does not look like what I expect. UPDATE fixed, but still not sure why the dump of $e looked so strange.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use feature 'say'; use local::lib; use XML::Feed; my $args = ({}); $args->{debug} = 1; sub atom_feed { my ( $arg ) = @_; # Set defaults # If option given my $newer_than = exists $arg->{newer_than} ? $arg->{newer_than} : 6000; my $url = $arg->{url}; my @events; warn "\n>>>> Getting atom url for [$url] ". "records newer than [$newer_than]min" if $args->{debug}; my $feed = XML::Feed->parse( URI->new( $url )) or die "Feed error with [$url] ".XML::Feed->errstr; my $x=1; for my $e ( $feed->entries ) { last if $x == 3; warn Dumper( $e ) if $args->{debug}; # << looks weird warn "Got bug title [$e->title]" if $args->{debug}; # << nothing if ( $e->title =~ m/\A\w+ # Start with any word \s+ # UPDATE << forgot this! \#\d{4,5} # bug number \s+ \( (Open|Closed|Merged|Rejected) \) # Status of bug /ix ) { push @events, $e->title .", ". $e->link; } $x++; } say $_ foreach ( @events ); # empty !? return \@events; } atom_feed({ url => 'https://dev.cfengine.com/projects/core/activity.atom' }); atom_feed({ url => 'http://www.redmine.org/projects/redmine/activity.atom' }); $ ./atom.pl Warning: XML::LibXML compiled against libxml2 20902, but runtime libxm +l2 is older 20901 >>>> Getting atom url for [https://dev.cfengine.com/projects/core/activity.atom] records newe +r than [6000]min at ./atom.pl line 22. $VAR1 = bless( { 'entry' => bless( { 'version' => '0.3', 'elem' => bless( do{\(my $o = 68470752)}, 'XML::LibXML::Element +' ), 'ns' => 'http://www.w3.org/2005/Atom' }, 'XML::Atom::Entry' ) }, 'XML::Feed::Entry::Format::Atom' ); Got bug title [XML::Feed::Entry::Format::Atom=HASH(0x43b0968)->title] +at ./atom.pl line 33. $VAR1 = bless( { 'entry' => bless( { 'ns' => 'http://www.w3.org/2005/Atom', 'elem' => bless( do{\(my $o = 68348704)}, 'XML::LibXML::Element +' ), 'version' => '0.3' }, 'XML::Atom::Entry' ) }, 'XML::Feed::Entry::Format::Atom' ); Got bug title [XML::Feed::Entry::Format::Atom=HASH(0x3ac4918)->title] +at ./atom.pl line 33. >>>> Getting atom url for [http://www.redmine.org/projects/redmine/activity.atom] records new +er than [6000]min at ./atom.pl line 22. $VAR1 = bless( { 'entry' => bless( { 'version' => '0.3', 'elem' => bless( do{\(my $o = 68856240)}, 'XML::LibXML::Elem +ent' ), 'ns' => 'http://www.w3.org/2005/Atom' }, 'XML::Atom::Entry' ) }, 'XML::Feed::Entry::Format::Atom' ); Got bug title [XML::Feed::Entry::Format::Atom=HASH(0x3b02bd0)->title] +at ./atom.pl line 33. $VAR1 = bless( { 'entry' => bless( { 'version' => '0.3', 'ns' => 'http://www.w3.org/2005/Atom', 'elem' => bless( do{\(my $o = 67673440)}, 'XML::LibXML::Elem +ent' ) }, 'XML::Atom::Entry' ) }, 'XML::Feed::Entry::Format::Atom' ); Got bug title [XML::Feed::Entry::Format::Atom=HASH(0x3f782c8)->title] +at ./atom.pl line 33.
Neil Watson
watson-wilson.ca
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Feed not working
by kcott (Archbishop) on Jul 13, 2015 at 15:07 UTC | |
|
Re: XML::Feed not working
by Athanasius (Archbishop) on Jul 14, 2015 at 04:23 UTC |