Changeset 681

Show
Ignore:
Timestamp:
05/05/06 16:13:55
Author:
miyagawa
Message:
  • New plugin: Subscription::XOXO
  • Moved load_uri method to Util ... should be refactored to methods of some class
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/Subscription/OPML.pm

    r630 r681  
    33use base qw( Plagger::Plugin ); 
    44 
    5 use Plagger::UserAgent
     5use Plagger::Util
    66use URI; 
    77use XML::OPML; 
     
    3232    my($self, $context, $uri) = @_; 
    3333 
    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); 
    5835 
    5936    if ($HAS_LIBERAL) { 
  • trunk/plagger/lib/Plagger/Util.pm

    r537 r681  
    22use strict; 
    33our @ISA = qw(Exporter); 
    4 our @EXPORT_OK = qw( strip_html dumbnail decode_content extract_title ); 
     4our @EXPORT_OK = qw( strip_html dumbnail decode_content extract_title load_uri ); 
    55 
    66use Encode (); 
     
    7979} 
    8080 
     81sub 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 
    811121;