Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add example

  • Loading branch information...
commit 4fd4f906c7a62efac1e3513994eb702cc09ee039 1 parent 200ce86
Gabor Szabo authored March 06, 2012

Showing 1 changed file with 57 additions and 0 deletions. Show diff stats Hide diff stats

  1. 57  eg/check_feed.pl
57  eg/check_feed.pl
... ...
@@ -0,0 +1,57 @@
  1
+use strict;
  2
+use warnings;
  3
+use v5.10;
  4
+
  5
+=head1 DESCRIPTION
  6
+
  7
+Given a URL of an Atom or RSS feed or a filename of an already downloaded
  8
+feed, this script will try to parse it and print out what it understands
  9
+from the feed.
  10
+
  11
+=cut
  12
+
  13
+use XML::Feed;
  14
+
  15
+my $src = shift;
  16
+
  17
+die "Usage: $0 FILE|URL\n" if not $src;
  18
+
  19
+my $source = $src;
  20
+if ($src =~ m{^https?://}) {
  21
+	$source = URI->new($src);
  22
+} else {
  23
+	if (not -f $source) {
  24
+		die "'$source' does not look like a URL and it does not exist on the file-system either.\n";
  25
+	}
  26
+}
  27
+
  28
+my $feed = XML::Feed->parse( $source ) or die XML::Feed->errstr;
  29
+say 'Title:     ' . ($feed->title     // '');
  30
+say 'Tagline:   ' . ($feed->tagline   // '');
  31
+say 'Format:    ' . ($feed->format    // '');
  32
+say 'Author:    ' . ($feed->author    // '');
  33
+say 'Link:      ' . ($feed->link      // '');
  34
+say 'Base:      ' . ($feed->base      // '');
  35
+say 'Language:  ' . ($feed->language  // '');
  36
+say 'Copyright: ' . ($feed->copyright // '');
  37
+say 'Modified:  ' . ($feed->modified  // ''); # DateTime object
  38
+say 'Generator: ' . ($feed->generator // '');
  39
+
  40
+for my $entry ($feed->entries) {
  41
+	say '';
  42
+	say '    Link:      ' . ($entry->link          // '');
  43
+	say '    Author:    ' . ($entry->author        // '');
  44
+	say '    Title:     ' . ($entry->title         // '');
  45
+	say '    Caregory:  ' . ($entry->category      // '');
  46
+	say '    Id:        ' . ($entry->id            // '');
  47
+	say '    Issued:    ' . ($entry->issued        // ''); # DateTime object
  48
+	say '    Modified:  ' . ($entry->modified      // ''); # DateTime object
  49
+	say '    Lat:       ' . ($entry->lat           // '');
  50
+	say '    Long:      ' . ($entry->long          // '');
  51
+	say '    Format:    ' . ($entry->format        // '');
  52
+	say '    Tags:      ' . ($entry->tags          // '');
  53
+	say '    Enclosure: ' . ($entry->enclosure     // '');
  54
+	say '    Summary:   ' . ($entry->summary->body // '');
  55
+	say '    Content:   ' . ($entry->content->body // '');
  56
+}
  57
+

0 notes on commit 4fd4f90

Please sign in to comment.
Something went wrong with that request. Please try again.