Changeset 783

Show
Ignore:
Timestamp:
05/19/06 01:57:54
Author:
youpy
Message:

Refactored

Files:

Legend:

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

    r687 r783  
    11package Plagger::Plugin::Subscription::XOXO; 
    22use strict; 
    3 use base qw( Plagger::Plugin ); 
    4  
    5 use HTML::TreeBuilder::XPath; 
    6 use Plagger::Util; 
    7 use URI; 
    8  
    9 sub register { 
    10     my($self, $context) = @_; 
    11  
    12     $context->register_hook( 
    13         $self, 
    14         'subscription.load' => \&load, 
    15     ); 
    16 
     3use base qw( Plagger::Plugin::Subscription::XPath ); 
    174 
    185sub load { 
    196    my($self, $context) = @_; 
    20     my $uri = URI->new($self->conf->{url}) 
    21         or $context->error("config 'url' is missing"); 
    227 
    23     $self->load_xoxo($context, $uri); 
    24 
    25  
    26 sub load_xoxo { 
    27     my($self, $context, $uri) = @_; 
    28  
    29     my $xhtml = Plagger::Util::load_uri($uri, $self); 
    30     my $tree = HTML::TreeBuilder::XPath->new; 
    31     $tree->parse($xhtml); 
    32     $tree->eof; 
    33  
    34     $self->find_xoxo($tree); 
    35 
    36  
    37 sub find_xoxo { 
    38     my($self, $tree) = @_; 
    39  
    40     for my $child ($tree->findnodes('//ul[@class="xoxo" or @class="subscriptionlist"]//a')) { 
    41         my $href  = $child->attr('href') or next; 
    42         my $title = $child->attr('title') || $child->as_text; 
    43  
    44         my $feed = Plagger::Feed->new; 
    45         $feed->url($href); 
    46         $feed->title($title); 
    47  
    48         Plagger->context->subscription->add($feed); 
    49     } 
     8    $self->conf->{xpath} = '//ul[@class="xoxo" or @class="subscriptionlist"]//a'; 
     9    $self->SUPER::load($context); 
    5010} 
    5111