# first arg is an HTML::Element, second arg is a tag to match with lookdown.
# this should only return tags that don't have themselves nested somewhere inside.
# ie, if checking blah red blah blah
# it should only return the inner font tag, not the outer.
# it works, but I don't like the if test using $#. Is there a better way?
sub un_self_nested {
my $element = shift or die "no element";
$element->isa('HTML::Element') or die "not an html element";
my %tag_match = @_ or die "no tag match";
my @unself_nested = $element->look_down( %tag_match,
sub {
my $no_mested_matches = 1; # initialize to no nested matches, which is what we want.
my $tag_matches = 0;
my $tag = $_[0]; # current element
my @nested_same_kind_of_tag = $tag->look_down( %tag_match );
my $nested_same_kind_of_tag = $#nested_same_kind_of_tag;
if ( $nested_same_kind_of_tag ) {
$no_mested_matches = 0;
print "nested_same_kind_of_tag: " . $nested_same_kind_of_tag . "\n";
}
return $no_mested_matches; # only match tags which don't contain themselves as a nested match.
} );
return @unself_nested;
}