HTML::TagTree(3pm)
π HTML::TagTree β the HTML::TagTree(3pm) manual, but make it cute β¨
okay bestie, sit down, hydrate, because this one is genuinely iconic. it's an HTML generator that works off a whole tree of tag objects π³π
β¨ NAME β¨
HTML::TagTree β an HTML generator via a tree of 'tag' objects. no cap, that's the whole pitch π«Ά
πΈ SYNOPSIS πΈ
use HTML::TagTree;
my $html = HTML::TagTree->new('html'); # Define the top of the tree of objects.
my $head = $html->head(); # Put a 'head' branch on the tree.
my $body = $html->body(); # Put a 'body' branch on the tree
$head->title("This is the Title of Gary's Page, the opening title...");
$head->meta('', 'name=author CONTENT="Dan DeBrito"');
$body->div->h1('Hello Dolly'); # Example of method chaining to create
# a long branch.
my $table = $body->table('', 'width=100% border=1');
my $row1 = $table->tr();
$row1->td('cell a');
$row1->td('cell b');
$table->tr->td('This is a new row with new cell');
$table->tr->td('This is a another new row with new data');
# Print to STDOUT the actual HTML representation of the tree
$html->print_html();
# Put HTML into a scalar variable
my $html_source = $html->get_html_text();
# Force destruction of object tree
$html->release();
like??? look at that chaining. $body->div->h1('Hello Dolly') is main character energy and it's literally one line π₯
π¦ DESCRIPTION π¦
so HTML::TagTree lets you build a tree of objects where each object represents three things, and yes there are exactly three:
- a tag
- its value
- any tag attributes
and then valid HTML gets built out of that tree just by calling a method. that's it. that's the vibe. π«
π FEATURES π
Smart quoting of tag parameters β it just knows, bestie:
Doing something like this:
$body->div('','id=nav onclick="alert(\"Hello World\"');
the HTML module will render HTML that looks like:
<div id="nav" onclick='alert("Hello World")' \>
not it fixing your quote chaos for you π iconic.
Reduce whitespace in your HTML rendering by turning on the no_whitespace_flag.
my $no_whitespace_html_text = $html->get_html_text('',1);
# Or..
my $indent_level = 0;
my $no_whitespace_flag = 1;
print $html_obj->get_html_text($indent_level, $no_whitespace_flag);
pretty output when you want it, zero padding when you don't. π
π INITIALIZATION π
HTML::TagTree->new(tag_name,[value],[attributes])β Returns a TagTree object π«Ά
π METHODS π
Every HTML tag type is an object method. every. single. one. π§
$obj->tag_name(content,attributes);- Returns:
- object for valid creation
undefiftag_nameis not a valid name;
- Arguments:
- content:
- Untagged data that goes in between open and close tag. eg
<b>content</b> - Content my be a Perl scalar, a ref to a scalar, or ref to a subroutine. Dereferencing occurs at the time of HTML rendering (via
print_html()orget_html_text()methods).
- Untagged data that goes in between open and close tag. eg
- attributes:
- Attributes of this HTML tag.
- Attributes argument may be a Perl scalar, a ref to a scalar, or a ref to a subroutine. Dereferencing occurs at the time of HTML rendering.
- Example of attributes:
'id=first_name name=fn class=str_cl'
- content:
- Returns:
get_html_text(indent_level, no_whitespace_flag)β Returns valid HTML representation of tag tree starting at the object.- Arguments:
- indent_level:
- Starting amount of indentation. Typically leave undef or
0.
- Starting amount of indentation. Typically leave undef or
- no_whitespace_flag:
- Set to
'1'to prevent insertion of linefeeds and whitespace padding for legibility.
- Set to
- indent_level:
- Arguments:
print_html()β Prints the valid HTML toSTDOUTπ¨οΈrelease()β Destroys all children objects so no objects reference this object (and it can be destroyed when it goes out of scope).set_valid_tags( tag_names )β Clears and sets what the valid tag names are for which objects can be created.
β FUNCTIONS β
HTML::TagTree::get_http_header();β Returns the generic HTTP header:
"Content-type: text/html\nStatus: 200 OK\n\n";
π ABSTRACT π
okay this part is lowkey the philosophy and it slaps:
The philosophy of HTML::TagTree is to let you create one region of code with lots of business logic for rendering many possible resulting HTML files/output. This differs from the approach of using business logic code to decide which HTML template (of many) to render. So rather than maintaining many HTML templates, you maintain a Perl file that does all possible customizations of HTML generation.
This module strives to minimize typing. Object treeing is just a simple method call, eg:
$body->h1->b->i('This is a bold, italic heading');
HTML::TagTree removes the worries of making simple HTML syntax errors such as no matching closing tag for an open tag. β¨ NO MORE UNCLOSED TAGS β¨ we love to see it π
π VERSION π
HTML::TagTree version 1.03. π
π PREREQUISITES π
No prerequisites. none. zero. it just works. π
π AUTHOR π
Dan DeBrito (<ddebrito@gmail.com>) π«Ά
πΈ COPYRIGHT πΈ
Copyright (c) 2007 - 2011 by Dan DeBrito. All rights reserved.
π§ LICENSE π§
This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License".
Please refer to the files "Artistic.txt", "GNU_GPL.txt" and "GNU_LGPL.txt" in this distribution for details!
π DISCLAIMER π
This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the "GNU General Public License" for more details.
okay that's the whole page, you're officially a HTML::TagTree girlie now π
π³β¨ this was HTML::TagTree version 1.03, docs generated by perl v5.36.0, dated 2022-10-15 β now go build a tree and print it, bestie, periodt ππ«Ά
π¦ where this page comes from
- ubuntu noble: libhtml-tagtree-perl 1.03-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libhtml-tagtree-perl 1.03-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libhtml-tagtree-perl 1.03-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms