Changeset 759

Show
Ignore:
Timestamp:
05/17/06 03:03:57
Author:
miyagawa
Message:

TruePermalink? now resolves URLs recursively. Fixes #237

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/Filter/TruePermalink.pm

    r751 r759  
    4343    my($self, $context, $args) = @_; 
    4444 
    45     $self->rewrite($args->{entry}->permalink, sub { $args->{entry}->link(@_) }); 
     45    $self->rewrite(sub { $args->{entry}->link }, sub { $args->{entry}->link(@_) }); 
    4646    for my $enclosure ($args->{entry}->enclosures) { 
    47         $self->rewrite($enclosure->url, sub { $enclosure->url( URI->new(@_) ) }); 
     47        $self->rewrite(sub { $enclosure->url }, sub { $enclosure->url( URI->new(@_) ) }); 
    4848    } 
    4949} 
    5050 
    5151sub rewrite { 
    52     my($self, $link, $callback) = @_; 
     52    my($self, $getter, $callback) = @_; 
     53 
     54    my $loop; 
     55    while ($self->rewrite_link($getter, $callback)) { 
     56        if ($loop++ >= 100) { 
     57            Plagger->error("Possible infinite loop on " . $getter->()); 
     58        } 
     59    } 
     60
     61 
     62sub rewrite_link { 
     63    my($self, $getter, $callback) = @_; 
    5364 
    5465    my $context = Plagger->context; 
    5566 
     67    my $link = $getter->(); 
    5668    my $orig = $link; # copy 
    5769    my $count = 0; 
     
    7183                $rewritten = $_; 
    7284                $callback->($_); 
     85                last; 
    7386            } 
    7487        } elsif ($plugin->{query_param}) { 
     
    8598        $context->log(info => "Link $orig rewritten to $rewritten"); 
    8699    } 
     100 
     101    return $count; 
    87102} 
    88103