Nightcat > HTML-TagUtil-1.45 > HTML::TagUtil

Download:
HTML-TagUtil-1.45.tar.gz

Dependencies

Annotate this POD

Related Modules

Text::Balanced
HTML::EasyTags
HTML::Lint
Text::Textile
more...
By perlmonks.org
View/Report Bugs
Module Version: 1.43   Source  

NAME ^

HTML::TagUtil - Perl Utility for HTML tags

SYNOPSIS ^

use HTML::TagUtil; $_ = "<i>Now!</i>";

my $tagger = HTML::TagUtil->new(); print "Tagged!" if ($tagger->tagged()); print "Open Tagged!" if ($tagger->opentagged()); print "Close Tagged!" if ($tagger->closetagged());

DESCRIPTION ^

HTML::TagUtil is a perl module providing a Object-Oriented interface to getting information about HTML/SGML/XML tags and their attributes and content.

METHODS ^

new

new is the constructor for HTML::TagUtil. it can be called like this: my $tagger = new HTML::TagUtil (); my $tagger = HTML::TagUtil->new();

also, you can supply an optional argument as the string to use if none is given to one of the methods. if you do not supply it here, it defaults to the default variable ($_) here and everywhere else.

$tagger->tagged

tagged checks to see if a string has both an end tag and a start tag in it. if it does, it returns true, if not, it returns false. a few examples would be:

$_ = "<html>html stuff</html>"; print "Tagged" if ($tagger->tagged); #prints "Tagged" $_ = "<html>html stuff"; print "Tagged" if ($tagger->tagged); #prints nothing. $_ = "html stuff</html>"; print "Tagged" if ($tagger->tagged); #prints nothing. $_ = "<html blah="blah_blah">html stuff</html>"; print "Tagged" if ($tagger->tagged); #prints "Tagged"

tagged can handle attributes and empty elements.

$tagger->opentagged

opentagged checks to see if a string has one or more start tags in it, ignoring whether it has an end tag in it or not. if it does have a start tag, it returns true. otherwise, it returns false. some examples are:

$_ = "<html>stuff"; print "Open Tagged" if ($tagger->opentagged); #prints "Open Tagged" $_ = "<html>stuff</html>"; print "Open Tagged" if ($tagger->opentagged); #prints "Open Tagged" $_ = "stuff</html>"; print "Open Tagged" if ($tagger->openedtagged); prints nothing $_ = "<html some="cool" attributes="yes">stuff"; print "Open Tagged" if ($tagger->opentagged); #prints "Open Tagged"

opentagged can handle attributes as well as empty elements.

$tagger->closetagged

closetagged checks to see if a string has one or more end tags in it, ignoring whether it has a start tag or not. if it does have an end tag, it returns true, otherwise, it returns false. some examples are:

$_ = "stuff</html>"; print "Close Tagged" if ($tagger->closetagged); #prints "Closed Tagged" $_ = "<html>stuff</html>"; print "Close Tagged" if ($tagger->closetagged); #prints "Closed Tagged" $_ = "<html>stuff"; print "Closed Tagged" if ($tagger->closetagged); #prints nothing. $_ = "stuff</html stuff="cool">"; print "Closed Tagged" if ($tagger->closetagged); #prints nothing.

closedtagged can not handle attributes or empty elements. because end tags can't have attributes or be empty.

$tagger->tagpos

tagpos returns the position that a certain tag is at in a string, 0 meaning that it is not there, and 1 meaning the first position in the string and so on. It will add the < and the > on to the tag you specify if you do not. some examples are:

$_ = "<html>stuff</html>"; my $pos = $tagger->tagpos ($_, '<html>', 0); print $pos; #prints "1" $_ = "<html>stuff</html>"; my $pos = $tagger->tagpos ($_, 'html', 0); print $pos; #prints "1" because the < and > get added on to the 'html'. $_ = "stuff<html>"; my $pos = $tagger->tagpos ($_, '<html>', 0); print $pos; #prints "6" because counting starts from one for this. $_ = "stuff<html>"; my $pos = $tagger->tagpos ($_, 'html', 0); print $pos; #prints "6" again because counting starts from one for this.

tagpos can handle anything that is surrounded by < and >.

$tagger->empty

empty checks to see if the specified string contains an empty element in it. That is, one that ends with " />". it returns true if it does have one in it, or false otherwise. some examples would be:

$_ = "<img />"; print "Empty" if ($tagger->empty); #prints "Empty" $_ = "<img/>"; print "Empty" if ($tagger->empty); #prints "Empty" $_ = "<img></img>"; print "Empty" if ($tagger->empty); #prints nothing $_ = "<img src=\"http://www.example.com/cool.gif\" />"; print "Empty" if ($tagger->empty); #prints "Empty"

empty can handle attributes and varying amounts of space before the end tag.

$tagger->comment

comment checks to see if the specified string contains a comment in it. A comment is any string surrounded by '<!--' and '-->'. Sometimes, people put more than two hyphens in the comment. this is not actually allowed according to the SGML/HTML specification, but is allowable. Allowability of hyphens in comments is by default set to 0, but you can override this by calling $tagger->allow_hyphen(1) or setting $HTML::TagUtil::Allow_Hyphen to 1. (Not recommended.) Some examples are:

 $_ = "<!--comment here-->";
 print "Comment" if ($tagger->comment); #prints "Comment"
 $_ = "<!---comment-here-->";
 print "Comment" if ($tagger->comment); #prints nothing.
 $HTML::TagUtil::Allow_Hyphen = 1;
 $_ = "<!---comment-here-->";
 print "Comment" if ($tagger->comment); #prints "Comment"

comment can handle anything in between '<!--' and '-->', with the option of allowing hyphens in the comment.

EXPORT ^

none. (OO)

BUGS ^

none known.

SEE ALSO ^

HTML::Parser HTML::Tagset

HTML::TagUtil's website is http://www.x-tac.net/html-util.htm/

AUTHOR ^

<nightcat>, <nightcat@crocker.com>

COPYRIGHT AND LICENSE ^

Copyright 2005 by <nightcat>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: