--- lib/Grep/Source.pm 2007/04/28 13:08:50 121 +++ lib/Grep/Source.pm 2007/04/28 17:55:37 123 @@ -201,10 +201,15 @@ my $args = {@_}; my $tree = $args->{tree} || die "no tree"; - my $message = $args->{message}; + my $message = $args->{message} || ''; my $fatal = $args->{fatal}; die "no templates" unless defined( $args->{templates} ); - my @templates = @{ $args->{templates} }; + my @templates; + if ( ref( $args->{template} ) eq 'ARRAY' ) { + @templates = @{ $args->{templates} }; + } else { + @templates = ( $args->{templates} ); + } push @templates, ( undef, undef ) if ( $#templates == 0 ); @@ -212,8 +217,9 @@ ( $#templates + 1 ) % 3 == 0 ); - my ( $result, $el, $attr, $value ); + my ( $el, $attr, $value ); + my @results; my @tags; while ( @templates ) { @@ -221,21 +227,24 @@ my $tag = $attr ? "<$el $attr=\"$value\">" : "<$el>"; push @tags, $tag; $self->log->debug("looking for $message $tag"); - $result = $tree->look_down( '_tag', $el, sub { + @results = $tree->look_down( '_tag', $el, sub { return 1 unless ( $attr && $value ); ( $_[0]->attr( $attr ) || '' ) eq $value; }); - last if $result; + last if @results; } - if ( ! $result ) { + if ( ! @results ) { my $msg = "can't find $message ", join(" ", @tags); die $msg if ( $fatal ); warn $msg; return; } - return $result; + $self->log->debug("found ", $#results + 1, " results"); + + return @results if wantarray; + return shift @results; } sub scrape {