Changeset 687

Show
Ignore:
Timestamp:
05/05/06 20:12:06
Author:
miyagawa
Message:

Use XPath rather than recursive tree manipulation to find XOXO, thanks to youpy
http://subtech.g.hatena.ne.jp/youpy/20060505/p1

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/Makefile.PL

    r682 r687  
    208208    'Subscription::XOXO' => [ 
    209209        -default => 0, 
    210         recommends('HTML::TreeBuilder'), 
     210        recommends('HTML::TreeBuilder::XPath'), 
    211211    ], 
    212212); 
  • trunk/plagger/lib/Plagger/Date.pm

    r686 r687  
    77use UNIVERSAL::require; 
    88 
    9 sub rebless { bless $_[1], $_[0] } 
     9sub rebless { 
     10    my($class, $dt) = @_; 
     11    bless $dt, $class; 
     12
    1013 
    1114sub parse { 
     
    2124 
    2225    my $dt = $module->parse_datetime($date) or return; 
    23  
    24     # If parsed datetime is floating, don't set timezone here. It should be "fixed" in caller plugins 
    25     unless ($dt->time_zone->is_floating) { 
    26         $dt->set_time_zone( Plagger->context->conf->{timezone} || 'local' ); 
    27     } 
    28  
    29     bless $dt, $class; 
     26    $class->rebless($dt); 
    3027} 
    3128 
  • trunk/plagger/lib/Plagger/Plugin/Subscription/XOXO.pm

    r683 r687  
    33use base qw( Plagger::Plugin ); 
    44 
    5 use HTML::TreeBuilder
     5use HTML::TreeBuilder::XPath
    66use Plagger::Util; 
    77use URI; 
     
    2828 
    2929    my $xhtml = Plagger::Util::load_uri($uri, $self); 
    30     my $tree = HTML::TreeBuilder->new; 
     30    my $tree = HTML::TreeBuilder::XPath->new; 
    3131    $tree->parse($xhtml); 
    3232    $tree->eof; 
     
    3838    my($self, $tree) = @_; 
    3939 
    40     for my $child ($tree->content_list) { 
    41         next unless ref $child; 
    42         if ($child->tag eq 'ul' || $child->tag eq 'ol') { 
    43             my $class = $child->attr('class') || ''; 
    44             if ($class eq 'xoxo' || $class eq 'subscriptionlist') { 
    45                 $self->find_list($child); 
    46             } 
    47         } else { 
    48             $self->find_xoxo($child); 
    49         } 
    50     } 
    51 
     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; 
    5243 
    53 sub find_list { 
    54     my($self, $tree) = @_; 
     44        my $feed = Plagger::Feed->new; 
     45        $feed->url($href); 
     46        $feed->title($title); 
    5547 
    56     for my $child ($tree->content_list) { 
    57         next unless ref $child; 
    58         if ($child->tag eq 'a') { 
    59             my $href  = $child->attr('href') or next; 
    60             my $title = $child->attr('title') || $child->as_text; 
    61  
    62             my $feed = Plagger::Feed->new; 
    63             $feed->url($href); 
    64             $feed->title($title); 
    65  
    66             Plagger->context->subscription->add($feed); 
    67         } else { 
    68             $self->find_list($child); 
    69         } 
     48        Plagger->context->subscription->add($feed); 
    7049    } 
    7150}