Changeset 681
- Timestamp:
- 05/05/06 16:13:55
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/lib/Plagger/Plugin/Subscription/OPML.pm
r630 r681 3 3 use base qw( Plagger::Plugin ); 4 4 5 use Plagger::U serAgent;5 use Plagger::Util; 6 6 use URI; 7 7 use XML::OPML; … … 32 32 my($self, $context, $uri) = @_; 33 33 34 my $xml; 35 if (ref($uri) eq 'SCALAR') { 36 $xml = $$uri; 37 } 38 elsif ($uri->scheme =~ /^https?$/) { 39 $context->log(debug => "Fetch remote OPML from $uri"); 40 41 my $response = Plagger::UserAgent->new->fetch($uri, $self); 42 if ($response->is_error) { 43 $context->log(error => "GET $uri failed: " . 44 $response->http_status . " " . 45 $response->http_response->message); 46 } 47 $xml = $response->content; 48 } 49 elsif ($uri->scheme eq 'file') { 50 $context->log(debug => "Open local OPML file " . $uri->path); 51 open my $fh, '<', $uri->path 52 or $context->error( $uri->path . ": $!" ); 53 $xml = join '', <$fh>; 54 } 55 else { 56 $context->error("Unsupported URI scheme: " . $uri->scheme); 57 } 34 my $xml = Plagger::Util::load_uri($uri, $self); 58 35 59 36 if ($HAS_LIBERAL) { trunk/plagger/lib/Plagger/Util.pm
r537 r681 2 2 use strict; 3 3 our @ISA = qw(Exporter); 4 our @EXPORT_OK = qw( strip_html dumbnail decode_content extract_title );4 our @EXPORT_OK = qw( strip_html dumbnail decode_content extract_title load_uri ); 5 5 6 6 use Encode (); … … 79 79 } 80 80 81 sub load_uri { 82 my($uri, $plugin) = @_; 83 84 my $data; 85 if (ref($uri) eq 'SCALAR') { 86 $data = $$uri; 87 } 88 elsif ($uri->scheme =~ /^https?$/) { 89 Plagger->context->log(debug => "Fetch remote file from $uri"); 90 91 my $response = Plagger::UserAgent->new->fetch($uri, $plugin); 92 if ($response->is_error) { 93 Plagger->context->log(error => "GET $uri failed: " . 94 $response->http_status . " " . 95 $response->http_response->message); 96 } 97 $data = $response->content; 98 } 99 elsif ($uri->scheme eq 'file') { 100 Plagger->context->log(debug => "Open local file " . $uri->path); 101 open my $fh, '<', $uri->path 102 or Plagger->context->error( $uri->path . ": $!" ); 103 $data = join '', <$fh>; 104 } 105 else { 106 Plagger->context->error("Unsupported URI scheme: " . $uri->scheme); 107 } 108 109 return $data; 110 } 111 81 112 1;
