/[Grep]/lib/Grep/Source.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/Grep/Source.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 121 by dpavlin, Sat Apr 28 13:08:50 2007 UTC revision 123 by dpavlin, Sat Apr 28 17:55:37 2007 UTC
# Line 201  sub element_by_triplet { Line 201  sub element_by_triplet {
201          my $args = {@_};          my $args = {@_};
202    
203          my $tree = $args->{tree} || die "no tree";          my $tree = $args->{tree} || die "no tree";
204          my $message = $args->{message};          my $message = $args->{message} || '';
205          my $fatal = $args->{fatal};          my $fatal = $args->{fatal};
206          die "no templates" unless defined( $args->{templates} );          die "no templates" unless defined( $args->{templates} );
207          my @templates = @{ $args->{templates} };          my @templates;
208            if ( ref( $args->{template} ) eq 'ARRAY' ) {
209                    @templates = @{ $args->{templates} };
210            } else {
211                    @templates = ( $args->{templates} );
212            }
213    
214          push @templates, ( undef, undef ) if ( $#templates == 0 );          push @templates, ( undef, undef ) if ( $#templates == 0 );
215    
# Line 212  sub element_by_triplet { Line 217  sub element_by_triplet {
217                  ( $#templates + 1 ) % 3 == 0                  ( $#templates + 1 ) % 3 == 0
218          );          );
219    
220          my ( $result, $el, $attr, $value );          my ( $el, $attr, $value );
221    
222            my @results;
223          my @tags;          my @tags;
224    
225          while ( @templates ) {          while ( @templates ) {
# Line 221  sub element_by_triplet { Line 227  sub element_by_triplet {
227                  my $tag = $attr ? "<$el $attr=\"$value\">" : "<$el>";                  my $tag = $attr ? "<$el $attr=\"$value\">" : "<$el>";
228                  push @tags, $tag;                  push @tags, $tag;
229                  $self->log->debug("looking for $message $tag");                  $self->log->debug("looking for $message $tag");
230                  $result = $tree->look_down( '_tag', $el, sub {                  @results = $tree->look_down( '_tag', $el, sub {
231                                  return 1 unless ( $attr && $value );                                  return 1 unless ( $attr && $value );
232                                  ( $_[0]->attr( $attr ) || '' ) eq $value;                                  ( $_[0]->attr( $attr ) || '' ) eq $value;
233                  });                  });
234                  last if $result;                  last if @results;
235          }          }
236    
237          if ( ! $result ) {          if ( ! @results ) {
238                  my $msg = "can't find $message ", join(" ", @tags);                  my $msg = "can't find $message ", join(" ", @tags);
239                  die $msg if ( $fatal );                  die $msg if ( $fatal );
240                  warn $msg;                  warn $msg;
241                  return;                  return;
242          }          }
243    
244          return $result;          $self->log->debug("found ", $#results + 1, " results");
245    
246            return @results if wantarray;
247            return shift @results;
248  }  }
249    
250  sub scrape {  sub scrape {

Legend:
Removed from v.121  
changed lines
  Added in v.123

  ViewVC Help
Powered by ViewVC 1.1.26