Changeset 2246

Show
Ignore:
Timestamp:
05/10/07 07:47:05
Author:
miyagawa
Message:

store $node to $_ in the callback

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Web-Scraper/trunk/lib/Web/Scraper.pm

    r2244 r2246  
    106106            if (ref($key) && ref($key) eq 'CODE' && !defined $val) { 
    107107                for my $node (@nodes) { 
     108                    local $_ = $node; 
    108109                    $key->($node); 
    109110                } 
     
    123124 
    124125    if (ref($val) && ref($val) eq 'CODE') { 
     126        local $_ = $node; 
    125127        return $val->($node); 
    126128    } elsif (blessed($val) && $val->isa('Web::Scraper')) { 
  • Web-Scraper/trunk/t/04_callback.t

    r2239 r2246  
    3939- baz  
    4040- bad 
     41 
     42=== 
     43--- html 
     44<ul> 
     45<li class="foo"><span title="baz">bar1</span></li> 
     46<li class="foo"><span title="bad">bar3</span></li> 
     47</ul> 
     48--- selector 
     49li.foo span 
     50--- callback 
     51$_->attr('title') 
     52--- expected 
     53- baz  
     54- bad