instead of
3.12 2002-07-30
Release by Sean M. Burke
Added as_trimmed_text method to HTML::Element, as described
(prophesied?) in the fantabulous new book /Perl & LWP/.
Bugfix: fixed unshift_content when given a LoL. (_parent wasn't
getting set right.)
HTML::Element and HTML::TreeBuilder now enforce at least some
minimal sanity on what can be in a tag name. (Notably, no spaces,
slashes, or control characters.)
Semi-bugfix: $element->replace_with(...) can now take LoLs in its
replacement list.
Bumped HTML::Element version up to 3.12 (right from 3.09)
Semi-bugfix: as_XML now doesn't use named entities in its return
value -- it always uses numeric entities.
Added behavior: new_frow_lol can now do clever things in list
context.
HTML::Tree -- added blurb for /Perl & LWP/
HTML::TreeBuilder -- added blurb for /Perl & LWP/
Also added a few tweaks to do better with XHTML parsing.
Added guts() and disembowel() methods, for parsing document fragments.
TODO: desperately need to add tests to t/
3.11 2001-03-14
Release by Sean M. Burke
Bugfix: Klaus-Georg Adams reported that
the topmost frameset element in an HTML::TreeBuilder tree wasn't
getting its _parent attribute set. Fixed.
Minor bugfix: the root element of a new HTML::TreeBuilder tree was
missing its initial "_implicit" attribute. Fixed.
Two handy new methods in HTML::TreeBuilder:
* HTML::TreeBuilder->new_from_content(...)
* HTML::TreeBuilder->new_from_file($filename)
a.k.a.: HTML::TreeBuilder->new_from_file($fh)
3.10 2001-03-10
Release by Sean M. Burke
Now bundling three relevent The Perl Journal articles by me:
HTML::Tree::AboutObjects, HTML::Tree::AboutTrees, and
HTML::Tree::Scanning.
Vadims_Beilins@swh-t.lv observes that $h->push_content(LoL)
doesn't take care of _parent bookkeeping right. FIXED.
John Woffindin notes a similar bug in clone();
FIXED.
Adding no_space_compacting feature to TreeBuilder, at suggestion of
Victor Wagner .
Incorporating the clever suggestion (from Martin H. Sluka,
) that $element->extract_links's returned LoL
should contain a third item (for the attribute name) in the
per-link listref. I also add a fourth item, the tagname of the
element.
New method, "elementify", in HTML::TreeBuilder.
Various improvements and clarifications to the POD in
HTML::TreeBuilder and HTML::Element.
Some new methods in HTML::Element: "number_lists",
"objectify_text", and "deobjectify_text".
HTML::Element and HTML::TreeBuilder versions both bumped up from
3.08 to 3.10, to keep pace with the HTML::Tree version.
3.09 2001-01-21
Release by Sean M. Burke
Changed HTML/Element/traverse.pod to HTML/Element/traverse.pm
Wrote overview file: HTML/Tree.pm
3.08 2000-11-03
Release by Sean M. Burke
In Element and TreeBuilder: fixed handling of textarea content --
Thanks to Ronald J Kimball for
catching this.
In Element: a few internal changes to make it subclassable by the
forthcoming XML::Element et al.
3.07 2000-10-20
Release by Sean M. Burke
In Element: made new_from_lol accept existing HTML::Element objects
as part of the loltree. Thanks for Bob Glickstein
for the suggestion.
In Element: feeding an arrayref to push_content, unshift_content,
or splice_content now implicitly calls new_from_lol.
In Element: reversed the change in as_HTML/XML/Lisp_form that would
skip dumping attributes with references for values. It reacted
undesirably with objects that overload stringify; to wit, URI.pm
objects.
3.06 2000-10-15
Release by Sean M. Burke
In Element: methods added: $x->id, $x->idf, $x->as_XML,
$x->as_Lisp_form
In Element: internal optimization: as_HTML no longer uses the
tag() accessor. Should cause no change in behavior.
In Element: as_HTML (via starttag) no longer tries to dump
attributes whose values are references, or whose names
are null-string or "/". This should cause no change in
behavior, as there's no normal way for any document to parse
to a tree containing any such attributes.
In Element: minor rewordings or typo-fixes in the POD.
3.05 2000-10-02
Release by Sean M. Burke
In Element: fixed typo in docs for the content_refs_list method.
Had:
foreach my $item ($h->content_array_ref) {
Corrected to:
foreach my $item (@{ $h->content_array_ref }) {
In Element: fixed bug in $h->left that made it useless in scalar
context. Thanks to Toby Thurston for
spotting this.
In Element: added new method $h->tagname_map
In TreeBuilder: Some minor corrections to the logic of handling TD
and TH elements -- basically bug fixes, in response to an astute
bug report from Toby Thurston .
In TreeBuilder: Fixed lame bug that made strict-p mode nearly
useless. It may now approach usability!
This dist contains a simple utility called "htmltree" that parses
given HTML documents, and dumps their parse tree. (It's not
actually new in this version, but was never mentioned before.)
In TreeBuilder, a change of interest only to advanced programmers
familiar with TreeBuilder's source and perpetually undocumented
features: there is no $HTML::TreeBuilder::Debug anymore.
If you want to throw TreeBuilder into Debug mode, you have to do it
at compile time -- by having a line like this BEFORE any line that
says "use HTML::TreeBuilder":
sub HTML::TreeBuilder::DEBUG () {3};
where "5" is whatever debug level (0 for no debug output) that you
want TreeBuilder to be in. All the in TreeBuilder that used to say
print "...stuff..." if $Debug > 1;
now say
print "...stuff..." if DEBUG > 1;
where DEBUG is the constant-sub whose default value set at compile
time is 0. The point of this is that for the typical
compilation-instance of TreeBuilder will run with DEBUG = 0, and
having that set at compile time means that all the "print ... if
DEBUG" can be optimized away at compile time, so they don't appear
in the code tree for TreeBuilder. This leads to a typical ~10%
speedup in TreeBuilder code, since it's no longer having to
constantly interrogate $Debug.
Note that if you really do NEED the debug level to vary at runtime,
say:
sub HTML::TreeBuilder::DEBUG () { $HTML::TreeBuilder::DEBUG };
and then change that variable's value as need be. Do this only if
necessary, tho.
BTW, useful line to have in your ~/.cshrc:
alias deparse 'perl -MO=Deparse \!*'
I found it useful for deparsing TreeBuilder.pm to make sure that
the DEBUG-conditional statements really were optimized away
as I intended.
3.04 2000-09-04
Release by Sean M. Burke
In TreeBuilder: added p_strict, an option to somewhat change
behavior of implicating ""s.
Added store_comments, store_declarations, store_pis, to control
treatment of comments, declarations, and PIs when parsing.
In Element: documented the pseudo-elements (~comment, ~declaration,
~pi, and ~literal). Corrected as_HTML dumping of ~pi elements.
Removed formfeeds from source of Element and TreeBuilder --
different editors (and Perl) treat them differently as far as
incrementing the line counter; so Perl might report an error on
line 314, but preceding formfeeds might make your editor think that
that line is actually 316 or something, resulting in confusion all
around. Ahwell.
3.03 2000-08-26
Release by Sean M. Burke
Introduced an optimization in TreeBuilder's logic for checking that
body-worthy elements are actually inserted under body. Should
speed things up a bit -- it saves two method calls per typical
start-tag. Hopefully no change in behavior.
Whoops -- 3.01's change in the return values of TreeBuilder's
(internal) end(...) method ended up breaking the processing of list
elements. Fixed. Thanks to Claus Schotten for spotting this.
Whoops 2 -- Margarit A. Nickolov spotted that TreeBuilder
documented a implicit_body_p_tag method, but the module didn't
define it. I must have deleted it some time or other. Restored.
3.02 2000-08-20
Release by Sean M. Burke
Fixed a silly typo in Element that made delete_ignorable_whitespace
useless.
Made Element's $tree->dump take an optional output-filehandle
argument.
Added (restored?) "use integer" to TreeBuilder.
3.01 2000-08-20
Release by Sean M. Burke
Now depends on HTML::Tagset for data tables of HTML elements and
their characteristics.
Version numbers for HTML::TreeBuilder and HTML::Element, as well as
for the package, moved forward to 3.01.
Minor changes to HTML::TreeBuilder's docs.
HTML::TreeBuilder now knows not to amp-decode text children of
CDATA-parent elements. Also exceptionally stores comments under
CDATA-parent elements.
TreeBuilder should now correctly parse documents with frameset
elements. Tricky bunch of hacks.
TreeBuilder now ignores those pointless "x-html" tags that a
certain standards-flouting monopolistic American software/OS
company's mailer wraps its HTML in.
Introduced "tweaks" in HTML::TreeBuilder -- an experimental
(and quite undocumented) feature to allow specifying callbacks
to be called when specific elements are closed; makes possible
rendering (or otherwise scanning and/or manipulating) documents
as they are being parsed. Inspired by Michel Rodriguez's clever
XML::Twig module. Until I document this, email me if you're
interested.
HTML::Element's as_HTML now knows not to amp-escape children of
CDATA-parent elements. Thanks to folks who kept reminding me about this.
HTML::Element's as_HTML can now take an optional parameter
specifying which non-empty elements will get end-tags omitted.
HTML::Element's traverse's docs moved into separate POD,
HTML::Element::traverse.
Added HTML::Element methods all_attr_names and
all_external_attr_names. Fixed bug in all_external_attr.
Added HTML::Element method delete_ignorable_whitespace.
(Actually just moved from HTML::TreeBuilder, where it was
undocumented, and called tighten_up.)
Adding a bit of sanity checking to Element's look_down, look_up.
Added some formfeeds to the source of Element and TreeBuilder,
to make hardcopy a bit more readable.
0.68 2000-06-28
Release by Sean M. Burke
Fixed doc typo for HTML::Element's lineage_tag_names method.
Fixed lame bug in HTML::Element's all_external_attr that made it
quite useless. Thanks to Rich Wales for the bug
report and patch.
Changed as_text to no longer DEcode entities, as it formerly did,
and was documented to. Since entities are already decoded by time
text is stored in the tree, another decoding step is wrong. Neither
me nor Gisle Aas can remember what that was doing there in the
first place.
Changed as_text to not traverse under 'style' and 'script'
elements. Rewrote as_text's traverser to be iterative.
Added a bit of text to HTML::AsSubs to recommend using XML::Generator.
0.67 2000-06-12
Release by Sean M. Burke
Just changes to HTML::Element...
Introduced look_up and look_down. Thanks to the folks on the
libwww list for helping me find the right form for that idea.
Deprecated find_by_attribute
Doc typo fixed: at one point in the discussion of "consolidating
text", I said push_content('Skronk') when I meant
unshift_content('Skronk'). Thanks to Richard Y. Kim (ryk@coho.net)
for pointing this out.
Added left() and right() methods.
Made address([address]) accept relative addresses (".3.0.1")
Added content_array_ref and content_refs_list.
Added a bit more clarification to bits of the Element docs here and there.
Made find_by_tag_name work iteratively now, for speed.
0.66 2000-05-18
Release by Sean M. Burke
Noting my new email address.
Fixed bug in HTML::Element::detach_content -- it would return
empty-list, instead of returing the nodes detached.
Fixed big in HTML::Element::replace_with_content -- it would
accidentally completely kill the parent's content list!
Thanks to Reinier Post and others for spotting this error.
Fixed big in HTML::Element::replace_with -- it put replacers
in the content list of of the new parent, !but! forgot to update
each replacer's _parent attribute.
Thanks to Matt Sisk for spotting this error.
0.65 2000-03-26
Release by Sean M. Burke
Important additions to HTML::Element :
Totally reimplemented the traverse() method, and added features,
now providing a somewhat-new interface. It's still
backwards-compatible both syntactically and semantically.
Added methods: content_list, detach_content, replace_linkage,
normalize_content, preinsert, postinsert, and has_insane_linkage.
$h->attr('foo', undef) now actually deletes the attribute
'foo' from $h, instead of setting it to undef. Hopefully
this won't break any existing code!
Rearranged the order of some sections in the Element docs
for purely pedagogical reasons.
Bugfix: $tree->clone failed to delete the internal
_head and _body attributes of the clone (used by TreeBuilder),
$tree->clone->delete ended up deleting most/all of the original!
Fixed. Added cavets to the docs warning against cloning
TreeBuilder objects that are in mid-parse (not that I think most
users are exactly rushing to do this).
Thanks to Bob Glickstein for finding and reporting this bug.
Added some regression/sanity tests in t/
A bit more sanity checking in TreeBuilder: checks for _head and
_body before including it.
Modded TreeBuilder's calls to traverse() to be use new [sub{...},0]
calling syntax, for sake of efficiency.
Added some undocumented and experimental code in Element and
TreeBuilder for using HTML::Element objects to represent
comments, PIs, declarations, and "literals".
0.64 2000-03-08
Release by Sean M. Burke
Bugfix: $element->replace_with_content() would cause
a fatal error if any of $element's content nodes were
text segments. Fixed.
0.63 2000-03-08
Release by Sean M. Burke
Fixed a typo in the SYNOPSIS of TreeBuilder.pm: I had "->destroy" for
"->delete"!
Added $element->clone and HTML::Element->clone_list(nodes) methods,
as Marek Rouchal very helpfully suggested.
$tree->as_HTML can now indent, hopefully properly. The logic to do
so is pretty frightening, and regrettably doesn't wrap, and it's
not obvious how to make it capable of doing so.
$tree->as_text can now take a 'skip_dels' parameter.
Added $h->same_as($j) method.
Added $h->all_attr method.
Added $h->new_from_lol constructor method.
0.62 1999-12-18
Release by Sean M. Burke
Incremented HTML::AsSubs version to 1.13, and HTML::Parse version
to 2.7, to avoid version confusion with the old (<0.60) HTML-Tree
dist.
Re-simplified the options to HTML::Element::traverse, removing the
verbose_for_text option. (The behavior that it turned on, is now
always on; this should not cause any problems with any existing
code.)
Fixed HTML::Element::delete_content, and made an
HTML::TreeBuilder::delete to override it for TreeBuilder nodes,
which have their own special attributes.
HTML::Element::find_by_attribute, find_by_attribute, and get_attr_i
now behave differently in scalar context, if you're the sort that
likes context on method calls. HTML::Element::descendant is now
optimized in scalar context.
Fixed up some of the reporting of lineages in some $Debug-triggered
messages.
Fixed minor bug in updating pos when a text node under HTML
implicates BODY (and maybe P).
You should not use release 0.61
0.61 1999-12-15
Release by Sean M. Burke
Versions in this dist:
HTML::Parse: 2.6
HTML::TreeBuilder: 2.91
HTML::Element: 1.44
HTML::AsSubs: 1.12
No longer including the Formatter modules.
Lots of new methods and changes in HTML::Element; reorganized docs.
Added new HTML tags to HTML::Element's and HTML::TreeBuilder's
internal tables.
Reworked the logic in HTML::TreeBuilder. Previous versions dealt
badly with tables, and attempts to enforce content-model rules
occasionally went quite awry. This new version is much less
agressive about content-model rules, and works on the principle
that if the HTML source is cock-eyed, there's limits to what can be
done to keep the syntax tree from being cock-eyed.
HTML::TreeBuilder now also tries to ignore ignorable whitespace.
The resulting parse trees often have half (or fewer) the number of
nodes, without all the ignorable " " nodes like before.
0.53 1999-12-15
Release by Gisle Aas
Make it compatible with HTML-Parser-3.00
0.52 1999-11-10
Release by Gisle Aas
Fix SYNOPSIS for HTML::FormatText as suggested by
Michael G Schwern
Updated my email address.
0.51 1998-07-07
Release by Gisle Aas
Avoid new warnings introduced by perl5.004_70
0.50 1998-04-01
Release by Gisle Aas
the HTML::* modules that dealt with HTML syntax trees
was unbundled from libwww-perl-5.22.
HTML-Tree-5.03/LICENSE 0000644 0001750 0001750 00000043642 12027460670 012230 0 ustar cjm cjm This software is copyright (c) 1998 by Gisle Aas.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
Terms of the Perl programming language system itself
a) the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any
later version, or
b) the "Artistic License"
--- The GNU General Public License, Version 1, February 1989 ---
This software is Copyright (c) 1998 by Gisle Aas.
This is free software, licensed under:
The GNU General Public License, Version 1, February 1989
GNU GENERAL PUBLIC LICENSE
Version 1, February 1989
Copyright (C) 1989 Free Software Foundation, Inc.
51 Franklin St, Suite 500, Boston, MA 02110-1335 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The license agreements of most software companies try to keep users
at the mercy of those companies. By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.
When we speak of free software, we are referring to freedom, not
price. Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must tell them their rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License. The
"Program", below, refers to any such program or work, and a "work based
on the Program" means either the Program or any work containing the
Program or a portion of it, either verbatim or with modifications. Each
licensee is addressed as "you".
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program. You may charge a fee for the physical act of
transferring a copy.
2. You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:
a) cause the modified files to carry prominent notices stating that
you changed the files and the date of any change; and
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.
3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:
a) accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,
b) accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal charge
for the cost of distribution) a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of
Paragraphs 1 and 2 above; or,
c) accompany it with the information you received as to where the
corresponding source code may be obtained. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
Source code for a work means the preferred form of the work for making
modifications to it. For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.
4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License. However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.
5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions. You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.
7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of the license which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.
8. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
Copyright (C) 19yy
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19xx name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
program `Gnomovision' (a program to direct compilers to make passes
at assemblers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
That's all there is to it!
--- The Artistic License 1.0 ---
This software is Copyright (c) 1998 by Gisle Aas.
This is free software, licensed under:
The Artistic License 1.0
The Artistic License
Preamble
The intent of this document is to state the conditions under which a Package
may be copied, such that the Copyright Holder maintains some semblance of
artistic control over the development of the package, while giving the users of
the package the right to use and distribute the Package in a more-or-less
customary fashion, plus the right to make reasonable modifications.
Definitions:
- "Package" refers to the collection of files distributed by the Copyright
Holder, and derivatives of that collection of files created through
textual modification.
- "Standard Version" refers to such a Package if it has not been modified,
or has been modified in accordance with the wishes of the Copyright
Holder.
- "Copyright Holder" is whoever is named in the copyright or copyrights for
the package.
- "You" is you, if you're thinking about copying or distributing this Package.
- "Reasonable copying fee" is whatever you can justify on the basis of media
cost, duplication charges, time of people involved, and so on. (You will
not be required to justify it to the Copyright Holder, but only to the
computing community at large as a market that must bear the fee.)
- "Freely Available" means that no fee is charged for the item itself, though
there may be fees involved in handling the item. It also means that
recipients of the item may redistribute it under the same conditions they
received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated disclaimers.
2. You may apply bug fixes, portability fixes and other modifications derived
from the Public Domain or from the Copyright Holder. A Package modified in such
a way shall still be considered the Standard Version.
3. You may otherwise modify your copy of this Package in any way, provided that
you insert a prominent notice in each changed file stating how and when you
changed that file, and provided that you do at least ONE of the following:
a) place your modifications in the Public Domain or otherwise make them
Freely Available, such as by posting said modifications to Usenet or an
equivalent medium, or placing the modifications on a major archive site
such as ftp.uu.net, or by allowing the Copyright Holder to include your
modifications in the Standard Version of the Package.
b) use the modified Package only within your corporation or organization.
c) rename any non-standard executables so the names do not conflict with
standard executables, which must also be provided, and provide a separate
manual page for each non-standard executable that clearly documents how it
differs from the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
4. You may distribute the programs of this Package in object code or executable
form, provided that you do at least ONE of the following:
a) distribute a Standard Version of the executables and library files,
together with instructions (in the manual page or equivalent) on where to
get the Standard Version.
b) accompany the distribution with the machine-readable source of the Package
with your modifications.
c) accompany any non-standard executables with their corresponding Standard
Version executables, giving the non-standard executables non-standard
names, and clearly documenting the differences in manual pages (or
equivalent), together with instructions on where to get the Standard
Version.
d) make other distribution arrangements with the Copyright Holder.
5. You may charge a reasonable copying fee for any distribution of this
Package. You may charge any fee you choose for support of this Package. You
may not charge a fee for this Package itself. However, you may distribute this
Package in aggregate with other (possibly commercial) programs as part of a
larger (possibly commercial) software distribution provided that you do not
advertise this Package as a product of your own.
6. The scripts and library files supplied as input to or produced as output
from the programs of this Package do not automatically fall under the copyright
of this Package, but belong to whomever generated them, and may be sold
commercially, and may be aggregated with this Package.
7. C or perl subroutines supplied by you and linked into this Package shall not
be considered part of this Package.
8. The name of the Copyright Holder may not be used to endorse or promote
products derived from this software without specific prior written permission.
9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
The End
HTML-Tree-5.03/Build.PL 0000644 0001750 0001750 00000001713 12027460670 012510 0 ustar cjm cjm use 5.008;
use strict;
use warnings;
use inc::My_Build;
my $builder = inc::My_Build->new(
module_name => 'HTML::Tree',
license => 'perl',
dist_author => 'Christopher J. Madsen ',
dist_version_from => 'lib/HTML/Element.pm',
'build_requires' => {
'Encode' => '0',
'Module::Build' => '0.2808',
'Test::Fatal' => '0',
'Test::More' => '0',
'base' => '0'
},
'configure_requires' => {
'Module::Build' => '0.2808'
},
'recommends' => {
'HTML::FormatText' => '0',
'LWP::UserAgent' => '5.815'
},
'requires' => {
'Carp' => '0',
'Exporter' => '0',
'HTML::Entities' => '0',
'HTML::Parser' => '3.46',
'HTML::Tagset' => '3.02',
'Scalar::Util' => '0',
'integer' => '0',
'perl' => '5.008'
},
add_to_cleanup =>
[ 'HTML-Tree-*', 'tmp', 'blib', 'lwp-test-*', 'MANIFEST.bak' ],
script_files => 'bin',
);
$builder->create_build_script();
HTML-Tree-5.03/MANIFEST 0000644 0001750 0001750 00000001275 12027460670 012350 0 ustar cjm cjm Build.PL
Changes
LICENSE
MANIFEST
META.json
META.yml
README
TODO
bin/htmltree
inc/My_Build.pm
lib/HTML/AsSubs.pm
lib/HTML/Element.pm
lib/HTML/Element/traverse.pm
lib/HTML/Parse.pm
lib/HTML/Tree.pm
lib/HTML/Tree/AboutObjects.pod
lib/HTML/Tree/AboutTrees.pod
lib/HTML/Tree/Scanning.pod
lib/HTML/TreeBuilder.pm
t/00-all_prereqs.t
t/00system.t
t/assubs.t
t/attributes.t
t/body.t
t/building.t
t/children.t
t/clonei.t
t/construct_tree.t
t/doctype.t
t/escape.t
t/leaktest.t
t/oldparse.html
t/oldparse.t
t/parents.t
t/parse.t
t/parsefile.t
t/refloop.t
t/sample.txt
t/split.t
t/subclass.t
t/tag-rendering.t
t/unicode.t
t/whitespace.t
xt/author/zz_perlcritic.t
xt/release/pod-coverage.t
xt/release/pod-syntax.t
HTML-Tree-5.03/t/ 0000755 0001750 0001750 00000000000 12027460670 011455 5 ustar cjm cjm HTML-Tree-5.03/t/body.t 0000644 0001750 0001750 00000006260 12027460670 012603 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
use Test::More tests => 18;
use HTML::TreeBuilder;
EMPTY: {
my $root = HTML::TreeBuilder->new();
$root->implicit_body_p_tag(1);
$root->xml_mode(1);
$root->parse('');
$root->eof();
is( $root->as_HTML(), "" );
}
BR_ONLY: {
my $root = HTML::TreeBuilder->new();
$root->implicit_body_p_tag(1);
$root->xml_mode(1);
$root->parse(' ');
$root->eof();
is( $root->as_HTML(),
" " );
}
TEXT_ONLY: {
my $root = HTML::TreeBuilder->new();
$root->implicit_body_p_tag(1);
$root->xml_mode(1);
$root->parse('text');
$root->eof();
is( $root->as_HTML(), "
text" );
}
EMPTY_TABLE: {
my $root = HTML::TreeBuilder->new();
$root->implicit_body_p_tag(1);
$root->xml_mode(1);
$root->parse('
');
$root->eof();
is( $root->as_HTML(),
"" );
}
ESCAPES: {
my $root = HTML::TreeBuilder->new();
my $escape = 'This ſoftware has ſome bugs';
my $html = $root->parse($escape)->eof->elementify();
TODO: {
local $TODO = 'HTML::Parser::parse mucks with our escapes';
is( $html->as_HTML(),
"$escape" );
}
}
OTHER_LANGUAGES: {
my $root = HTML::TreeBuilder->new();
my $escape = 'Gebühr vor Ort von € 30,- pro Woche'; # RT 14212
my $html = $root->parse($escape)->eof;
is( $html->as_HTML(),
"Gebühr vor Ort von € 30,- pro Woche"
);
}
RT_18570: {
my $root = HTML::TreeBuilder->new();
my $escape = 'This ∼ is a twiddle';
my $html = $root->parse($escape)->eof->elementify();
is( $html->as_HTML(), "$escape" );
}
RT_18571: {
my $root = HTML::TreeBuilder->new();
my $html = $root->parse('$self->escape ')->eof->elementify();
is( $html->as_HTML(),
"\$self->escape " );
is( $html->as_HTML(''),
"\$self->escape " );
is( $html->as_HTML("\0"),
"\$self->escape " )
; # 3.22 compatability
}
sub has_no_content
{
my ($html, $name, $tag) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 1;
is( ok( $html =~ m!(<$tag>.*$tag>)!s, "$name contains <$tag>" )
? $1 : undef,
"<$tag>$tag>", "$name <$tag> contains nothing" );
} # end has_no_content
RT_70385: {
my $root = HTML::TreeBuilder->new();
my $html = $root->parse_content(
" "
);
my $unindented = $html->as_HTML;
my $indented = $html->as_HTML(undef, " ");
has_no_content($unindented, qw(unindented pre));
has_no_content($unindented, qw(unindented textarea));
has_no_content($indented, qw(indented pre));
has_no_content($indented, qw(indented textarea));
}
HTML-Tree-5.03/t/parse.t 0000644 0001750 0001750 00000013411 12027460670 012754 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
use Test::More;
my $DEBUG = 2;
BEGIN { plan tests => 44 }
use HTML::TreeBuilder;
use HTML::Element;
print "#Using HTML::TreeBuilder version v$HTML::TreeBuilder::VERSION\n";
print "#Using HTML::Element version v$HTML::Element::VERSION\n";
print "#Using HTML::Parser version v", $HTML::Parser::VERSION || "?", "\n";
print "#Using HTML::Entities version v", $HTML::Entities::VERSION || "?",
"\n";
print "#Using HTML::Tagset version v", $HTML::Tagset::VERSION || "?", "\n";
print "# Running under perl version $] for $^O",
( chr(65) eq 'A' ) ? "\n" : " in a non-ASCII world\n";
print "# Win32::BuildNumber ", &Win32::BuildNumber(), "\n"
if defined(&Win32::BuildNumber)
and defined &Win32::BuildNumber();
print "# MacPerl verison $MacPerl::Version\n"
if defined $MacPerl::Version;
printf
"# Current time local: %s\n# Current time GMT: %s\n",
scalar( localtime($^T) ), scalar( gmtime($^T) );
ok 1;
{
my $tree = HTML::TreeBuilder->new;
$tree->parse('foo I like pie');
$tree->eof;
ok( $tree->as_XML,
"
foo "
. "I like pie
\n" );
$tree->delete;
}
ok !same( 'x' => 'y', 1 );
ok !same( '' => 'y', 1 );
ok same( '' => '' );
ok same( '' => ' ' );
ok same( '' => ' ' );
ok same( '' => '' );
ok same( '' => '' );
ok same( '' => \'
' );
ok same( '' => '' );
ok same( '' => \'' );
ok same( ' ' => ' ' );
ok same( ' ' => ' ' );
ok same( ' ' => ' ' );
ok !same( ' ' => ' ', 1 );
ok same( 'abc xyz' => 'abc xyz' );
ok same( 'abc xyz' => 'abc xyz' );
ok same( 'abc+xyz' => 'abc+xyz' );
ok same( 'abc+xyz' => 'abc+xyz' );
ok same( 'abc+xyz' => 'abc+xyz' );
ok same( 'abc+xyz' => 'abc+xyz' );
print "#\n# Now some list tests.\n#\n";
ok same( 'after' => 'after' );
ok same( 'after' => 'after' );
ok same( 'after' =>
'after' );
ok same( 'after' => \
'after' );
print "#\n# Now some table tests.\n#\n";
ok same( 'xy z' =>
'' );
ok same( 'xy z' =>
'' );
ok same( '' =>
'' );
ok same(
'' => \
''
);
ok same( 'x' => 'x' );
ok same( 'x' => 'x' );
ok same( 'x' => 'x' );
ok same( 'x' => 'x' );
ok same( 'x' => 'x' );
ok same( 'x' => 'x' );
print "#\n# Now some p tests.\n#\n";
ok same( 'x
y
z' => '
x
y
z' );
ok same( '
x
y
z' => '
x
y
z
' );
ok same( 'x
y
z' => '
x
y
z
' );
ok same( 'x
y
z' => \'
x
y
z
' );
sub same {
my ( $code1, $code2, $flip ) = @_;
my $t1 = HTML::TreeBuilder->new;
my $t2 = HTML::TreeBuilder->new;
if ( ref $code1 ) { $t1->implicit_tags(0); $code1 = $$code1 }
if ( ref $code2 ) { $t2->implicit_tags(0); $code2 = $$code2 }
$t1->parse($code1);
$t1->eof;
$t2->parse($code2);
$t2->eof;
my $out1 = $t1->as_XML;
my $out2 = $t2->as_XML;
my $rv = ( $out1 eq $out2 );
#print $rv? "RV TRUE\n" : "RV FALSE\n";
#print $flip? "FLIP TRUE\n" : "FLIP FALSE\n";
if ( $flip ? ( !$rv ) : $rv ) {
if ( $DEBUG > 2 ) {
print
"In1 $code1\n",
"In2 $code2\n",
"Out1 $out1\n",
"Out2 $out2\n",
"\n\n";
}
}
else {
local $_;
foreach my $line (
'',
"The following failure is at " . join( ' : ', caller ),
"Explanation of failure: "
. ( $flip ? 'same' : 'different' )
. " parse trees!",
"Input code 1:",
$code1,
"Input code 2:",
$code2,
"Output tree (as XML) 1:",
$out1,
"Output tree (as XML) 2:",
$out2,
)
{
$_ = $line;
s/\n/\n# /g;
print "# ", $_, "\n";
}
}
$t1->delete;
$t2->delete;
return $rv;
}
# By default HTML::Parser will convert the & to &
my $tree = HTML::TreeBuilder->new_from_content('&foo; &bar;');
# No escaping of XML since custom entities are fine.
like( $tree->as_XML(),
qr{&foo; &bar;}, "" );
# HTML gets escaped on output
like( $tree->as_HTML(),
qr{&foo; &bar;}, "" );
# ignoring entities when parsing source makes it work like you expect XML to
my $tree3 = HTML::TreeBuilder->new( no_expand_entities => 1 );
$tree3->parse("&foo; &bar; ' &l
");
like( $tree3->as_HTML(),
qr{&foo; &bar; ' &l},
"" );
like(
$tree3->as_XML(),
qr{
&foo; &bar; ' &l
},
""
);
HTML-Tree-5.03/t/split.t 0000644 0001750 0001750 00000004721 12027460670 013001 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
# Testing of the incremental parsing. Try to split a HTML document at
# every possible position and make sure that the result is the same as
# when parsing everything in one chunk.
# Now we use a shorter document, because we don't have all day on
# this.
my ( $HTML, $notests );
BEGIN {
$HTML = <<'EOT';
Tittel
Overskrift
Text bold
italic
some entities (å)
EOT
$notests = length($HTML); # A test for each char in the test doc
$notests *= 3; # done twice
$notests += 3; # plus more for the the rest of the tests
}
use Test::More tests => $notests; # Tests
use HTML::TreeBuilder;
my $h = new HTML::TreeBuilder;
isa_ok( $h, "HTML::TreeBuilder" );
$h->parse($HTML)->eof;
my $html = $h->as_HTML;
$h->delete;
# Each test here tries to parse the doc when we split it in two.
for my $pos ( 0 .. length($HTML) - 1 ) {
my $first = substr( $HTML, 0, $pos );
my $last = substr( $HTML, $pos );
is( $first . $last, $HTML, "File split okay" );
my $h1;
eval {
$h1 = new HTML::TreeBuilder;
isa_ok( $h1, 'HTML::TreeBuilder' );
$h1->parse($first);
$h1->parse($last);
$h1->eof;
};
if ($@) {
print "Died when splitting at position $pos:\n";
my $before = 10;
$before = $pos if $pos < $before;
print "", substr( $HTML, $pos - $before, $before );
print "\n";
print substr( $HTML, $pos, 10 );
print "\n";
print "not ok $pos\n";
$h1->delete;
next;
}
my $new_html = $h1->as_HTML;
my $before = 10;
$before = $pos if $pos < $before;
is( $new_html, $html, "Still Parsing as the same after split at $pos" )
or diag(
"Something is different when splitting at position $pos:\n", "",
substr( $HTML, $pos - $before, $before ), "\n",
substr( $HTML, $pos, 10 ), "\n",
"\n$html$new_html\n",
);
$h1->delete;
} # for
# Also try what happens when we feed the document one-char at a time
# print "#\n#\nNow parsing document once char at a time...\n";
my $perChar = new HTML::TreeBuilder;
isa_ok( $perChar, 'HTML::TreeBuilder' );
while ( $HTML =~ /(.)/sg ) {
$perChar->parse($1);
}
$perChar->eof;
my $new_html = $perChar->as_HTML;
is( $new_html, $html, "Testing per Char parsing" );
$perChar->delete;
HTML-Tree-5.03/t/assubs.t 0000644 0001750 0001750 00000002145 12027460670 013144 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
use Test::More;
use HTML::AsSubs;
use HTML::Tagset;
plan tests => scalar @HTML::AsSubs::TAGS + 3;
### verify all subroutines in HTML::AsSubs ;
map {
my $h = eval "HTML::AsSubs::$_(\"$_\")";
my $string
= ( $HTML::Tagset::optionalEndTag{$_}
|| $HTML::Tagset::emptyElement{$_} )
? "<$_>$_"
: "<$_>$_<\/$_>";
is( $h->as_HTML, "$string", "Test of tag: $_" );
} (@HTML::AsSubs::TAGS);
### verify passing href to tag.
{
my $string = " test ";
my $h = HTML::AsSubs::a( { href => "http://cpan.org" }, "test" );
is( $h->as_HTML, "$string", "Test of tag properties" );
}
### Improve coverage by passing undef as first parm to _elem via wrapper function.
{
my $string = "test ";
my $h = HTML::AsSubs::a( undef, "test" );
is( $h->as_HTML, "$string", "undef test" );
}
### Improve coverage by passing no parameters to _elem via wrapper function.
{
my $string = " ";
my $h = HTML::AsSubs::a();
is( $h->as_HTML, "$string", "empty tag test" );
}
HTML-Tree-5.03/t/clonei.t 0000644 0001750 0001750 00000001004 12027460670 013106 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
use Test::More tests => 3;
use HTML::TreeBuilder;
my $t = HTML::TreeBuilder->new;
$t->parse('stuff lalal ');
$t->eof;
my $c = $t->clone();
#these are correct tests. Of what, I'm not sure.
ok( $c->same_as($t), "\$c is the same as \$t, according to HTML::Element" );
ok( $t->same_as($c), "\$t is the same as \$c, according to HTML::Element" );
$c->delete();
ok( $t->find_by_attribute( 'name', 'foo' ), "My name is foo after delete" );
$t->delete();
HTML-Tree-5.03/t/escape.t 0000644 0001750 0001750 00000004575 12027460670 013115 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
# Tests that the following translations take place, and none other:
#
# & => &
# < => <
# > => >
# ' => '
# " => "
#
# Further tests that already-escaped things are not further escaped.
#
# Escapes are defined in the XML spec:
# http://www.w3.org/TR/2006/REC-xml11-20060816/#dt-escape
my %translations;
my $tests = 0;
BEGIN {
%translations = (
'x > 3' => 'x > 3',
'x < 3' => 'x < 3',
'< 3 >' => '< 3 >',
"he's" => "he's",
## MS "smart" quotes don't get escaped (single)
"he’s" => "he’s",
'"his"' => '"his"',
## MS "smart" quotes don't get escaped (single)
'‘his’' => '‘his’',
## MS "smart" quotes don't get escaped (double)
'“his”' => '“his”',
'1&2' => '1&2',
'1&2' => '1&2',
'1&2' => '1&2',
'1& 2' => '1& 2',
'1& 2' => '1& 2',
'abc' => 'abc',
'número' => 'número',
'⇓' => '⇓',
'Œ' => 'Œ',
'²' => '²',
'&no\go;' => '&no\go;',
'&foo;' => '&foo;',
'&foo; &bar;' => '&foo; &bar;',
## RT 18568
'This ſoftware has ſome bugs' =>
'This ſoftware has ſome bugs',
);
$tests = keys(%translations) + 1;
}
use Test::More tests => $tests + 3;
use HTML::Element;
$HTML::Element::encoded_content = 1;
foreach my $orig ( keys %translations ) {
my $new = $orig;
HTML::Element::_xml_escape($new);
is( $new, $translations{$orig}, "Properly escaped: $orig" );
}
# test that multiple runs don't change the value
my $test_orig = '&foo; &bar;';
my $test_str = $test_orig;
HTML::Element::_xml_escape($test_str);
is( $test_str, $test_orig, "Multiple runs 1" );
HTML::Element::_xml_escape($test_str);
is( $test_str, $test_orig, "Multiple runs 2" );
HTML::Element::_xml_escape($test_str);
is( $test_str, $test_orig, "Multiple runs 3" );
# test default path, always encode '&'
$HTML::Element::encoded_content = 0;
$test_str = $test_orig;
my $test_expected = '&foo; &bar;';
HTML::Element::_xml_escape($test_str);
is( $test_str, $test_expected, "Default encode" );
HTML-Tree-5.03/t/doctype.t 0000644 0001750 0001750 00000001723 12027460670 013314 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
use Test::More tests => 4;
use HTML::TreeBuilder;
my $html = <<'EOHTML';
blah blah
EOHTML
WITH_DECLARATION: { # Check default state
my $tree = HTML::TreeBuilder->new;
isa_ok( $tree, "HTML::TreeBuilder" );
$tree->parse($html);
$tree->eof;
my @lines = split( "\n", $tree->as_HTML( undef, " " ) );
like( $lines[0], qr/DOCTYPE/, "DOCTYPE is in the first line" );
}
WITHOUT_DECLARATION: {
my $tree = HTML::TreeBuilder->new;
isa_ok( $tree, "HTML::TreeBuilder" );
$tree->store_declarations(0);
$tree->parse($html);
$tree->eof;
my @lines = split( "\n", $tree->as_HTML( undef, " " ) );
unlike( $lines[0], qr/DOCTYPE/, "DOCTYPE is NOT in the first line" );
}
HTML-Tree-5.03/t/parents.t 0000644 0001750 0001750 00000005105 12027460670 013317 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
use Test::More tests => 123;
use HTML::Element;
#---------------------------------------------------------------------
# Test whether each child links back to its parent (recursively):
sub check_parents {
my ( $elt, $test_name ) = @_;
my $index = -1;
foreach my $child ( $elt->content_list ) {
++$index;
next unless ref $child;
is( $child->parent, $elt, "$test_name.$index" );
check_parents( $child, "$test_name.$index" );
}
} # end check_parents
#---------------------------------------------------------------------
# Test both explicit and implicit constructors:
sub test_method {
my ( $method, $initial_tree, $address, @to_add ) = @_;
# Test method using implicit lol:
my $implicit = HTML::Element->new_from_lol($initial_tree);
my $elt = $implicit->address($address);
$elt->$method(@to_add);
check_parents( $implicit, "$method with implicit lol 0" );
# Create a new tree for the explicit constructor test:
my $explicit = HTML::Element->new_from_lol($initial_tree);
$elt = $explicit->address($address);
# Apply explicit constructor to each listref:
foreach my $e (@to_add) {
$e = HTML::Element->new_from_lol($e) if ref $e eq 'ARRAY';
}
# Test method using pre-constructed nodes:
$elt->$method(@to_add);
check_parents( $explicit, "$method with explicit lol 0" );
# Make sure they created the same tree:
is( $implicit->as_XML, $explicit->as_XML,
"$method implicit vs. explicit" );
} # end test_method
#=====================================================================
# Tests begin here:
#=====================================================================
# This is the base document:
my $base_tree = [
html => [ head => [ title => "Sample" ] ],
[ body => [ p => 'P1' ],
[ p => 'P2' ],
[ p => 'P3' ],
[ p => 'P4' ],
[ p => 'P5' ],
[ p => 'P6' ],
[ p => 'P7' ]
]
];
# Make sure new_from_lol sets parents correctly:
my $html = HTML::Element->new_from_lol($base_tree);
check_parents( $html, 'new_from_lol 0' );
$html->delete;
test_method(
push_content => $base_tree,
'0.1', [ p => 'P8' ], [ div => 'End' ]
);
test_method(
unshift_content => $base_tree,
'0.1.1', [ i => 'Italics' ]
);
test_method(
splice_content => $base_tree,
'0.1', #
3, 2, [ p => 'Replaces two paragraphs' ]
);
test_method( preinsert => $base_tree, '0.1.5', [ p => 'P5.5' ] );
test_method( postinsert => $base_tree, '0.1.3', [ p => 'P4.5' ] );
HTML-Tree-5.03/t/refloop.t 0000644 0001750 0001750 00000004063 12027460670 013313 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
use Test::More;
BEGIN {
plan skip_all => "Weakref support required"
unless eval "use Scalar::Util qw(weaken); 1";
plan tests => 8;
}
#Test that we do not need to call ->delete to free memory
BEGIN {
our @OBJECTS;
no strict 'refs';
*{'CORE::GLOBAL::bless'} = sub {
my $reference = shift;
my $class = @_ ? shift : scalar caller;
my $object = CORE::bless($reference, $class);
our $in_core_bless;
if ($object->isa('HTML::Element') && !$in_core_bless) {
local $in_core_bless = 1;
push @OBJECTS, $object;
weaken($OBJECTS[-1]);
}
return $object;
};
sub object_count { return 0 + grep { defined($_) } @OBJECTS; }
sub clear_objects { @OBJECTS = () }
use_ok("HTML::TreeBuilder", '-weak');
}
{
# By default HTML::Parser will convert the & to &
my $tree = HTML::TreeBuilder->new_from_content('&foo; &bar;');
ok(object_count() > 0);
$tree = undef;
is(object_count(), 0);
clear_objects();
}
{
# ignoring entities when parsing source makes it work like you expect XML to
my $tree = HTML::TreeBuilder->new(no_expand_entities => 1);
$tree->parse("&foo; &bar; ' &l
");
ok(object_count() > 0);
$tree = undef;
is(object_count(), 0);
clear_objects();
}
{
my $lol = [
'html',
['head', ['title', 'I like stuff!'],],
[ 'body', {'lang', 'en-JP'},
'stuff',
['p', 'um, p < 4!', {'class' => 'par123'}],
['div', {foo => 'bar'}, ' 1 2 3 '], # at 0.1.2
['div', {fu => 'baa'}, " 1 2 \xA0 3 "], # RT #26436 test
['hr'],
]
];
my $tree = HTML::Element->new_from_lol($lol);
my $start_count = object_count();
ok($start_count > 0);
my ($body) = $tree->look_down(_tag => 'body');
$tree = undef;
ok(object_count() < $start_count);
$body = undef;
is(object_count(), 0);
clear_objects();
}
HTML-Tree-5.03/t/unicode.t 0000644 0001750 0001750 00000007156 12027460670 013301 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
use Test::More;
my $DEBUG = 2;
BEGIN {
# Make sure we've got Unicode support:
eval "use v5.8.0; utf8::is_utf8('x');";
if ($@) {
plan skip_all => "Perl 5.8.0 or newer required for Unicode tests";
exit;
}
plan tests => 11;
binmode STDOUT, ":utf8";
} # end BEGIN
use Encode;
use HTML::TreeBuilder;
print "#Using Encode version v", $Encode::VERSION || "?", "\n";
print "#Using HTML::TreeBuilder version v$HTML::TreeBuilder::VERSION\n";
print "#Using HTML::Element version v$HTML::Element::VERSION\n";
print "#Using HTML::Parser version v", $HTML::Parser::VERSION || "?", "\n";
print "#Using HTML::Entities version v", $HTML::Entities::VERSION || "?",
"\n";
print "#Using HTML::Tagset version v", $HTML::Tagset::VERSION || "?", "\n";
print "# Running under perl version $] for $^O",
( chr(65) eq 'A' ) ? "\n" : " in a non-ASCII world\n";
print "# Win32::BuildNumber ", &Win32::BuildNumber(), "\n"
if defined(&Win32::BuildNumber)
and defined &Win32::BuildNumber();
print "# MacPerl verison $MacPerl::Version\n"
if defined $MacPerl::Version;
printf
"# Current time local: %s\n# Current time GMT: %s\n",
scalar( localtime($^T) ), scalar( gmtime($^T) );
ok 1;
ok same( '
', decode( 'latin1', "\xA0
" ) );
ok !same( '
', decode( 'latin1', "\xA0
" ), 1 );
ok !same( '
', decode( 'latin1', "\xA0
" ), 1 );
ok same( '
',
decode( 'latin1', "\xA0\xA0\xA0
" ) );
ok same( "\xA0\xA0\xA0
", decode( 'latin1', "\xA0\xA0\xA0
" ) );
ok !same( '
', decode( 'latin1', "\xA0\xA0\xA0
" ), 1 );
ok !same( '
', decode( 'latin1', "\xA0\xA0\xA0
" ), 1 );
ok same(
' —
',
"\xA0\xA0\x{2014}\xA0\xA0
"
);
ok same(
' XXmdashXX
',
"\xA0\xA0\x{2014}\xA0\xA0
",
0, sub { $_[0] =~ s/XXmdashXX/\x{2014}/ }
);
ok same( ' bold
',
decode( 'latin1', "\xA0bold \xA0\xA0
" ) );
sub same {
my ( $code1, $code2, $flip, $fixup ) = @_;
my $t1 = HTML::TreeBuilder->new;
my $t2 = HTML::TreeBuilder->new;
if ( ref $code1 ) { $t1->implicit_tags(0); $code1 = $$code1 }
if ( ref $code2 ) { $t2->implicit_tags(0); $code2 = $$code2 }
$t1->parse($code1);
$t1->eof;
$t2->parse($code2);
$t2->eof;
my $out1 = $t1->as_XML;
my $out2 = $t2->as_XML;
$fixup->( $out1, $out2 ) if $fixup;
my $rv = ( $out1 eq $out2 );
#print $rv? "RV TRUE\n" : "RV FALSE\n";
#print $flip? "FLIP TRUE\n" : "FLIP FALSE\n";
if ( $flip ? ( !$rv ) : $rv ) {
if ( $DEBUG > 2 ) {
print
"In1 $code1\n",
"In2 $code2\n",
"Out1 $out1\n",
"Out2 $out2\n",
"\n\n";
}
}
else {
local $_;
foreach my $line (
'',
"The following failure is at " . join( ' : ', caller ),
"Explanation of failure: "
. ( $flip ? 'same' : 'different' )
. " parse trees!",
sprintf( "Input code 1 (utf8=%d):", utf8::is_utf8($code1) ),
$code1,
sprintf( "Input code 2 (utf8=%d):", utf8::is_utf8($code2) ),
$code2,
"Output tree (as XML) 1:",
$out1,
"Output tree (as XML) 2:",
$out2,
)
{
$_ = $line;
s/\n/\n# /g;
print "# $_\n";
}
}
$t1->delete;
$t2->delete;
return $rv;
} # end same
HTML-Tree-5.03/t/00system.t 0000644 0001750 0001750 00000001757 12027460670 013340 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
use Test::More tests => 2;
BEGIN {
use_ok('HTML::TreeBuilder');
use_ok('HTML::Element');
}
print "#Using HTML::TreeBuilder version v$HTML::TreeBuilder::VERSION\n";
print "#Using HTML::Element version v$HTML::Element::VERSION\n";
print "#Using HTML::Parser version v", $HTML::Parser::VERSION || "?", "\n";
print "#Using HTML::Entities version v", $HTML::Entities::VERSION || "?",
"\n";
print "#Using HTML::Tagset version v", $HTML::Tagset::VERSION || "?", "\n";
print "# Running under perl version $] for $^O",
( chr(65) eq 'A' ) ? "\n" : " in a non-ASCII world\n";
print "# Win32::BuildNumber ", &Win32::BuildNumber(), "\n"
if defined(&Win32::BuildNumber)
and defined &Win32::BuildNumber();
print "# MacPerl verison $MacPerl::Version\n"
if defined $MacPerl::Version;
printf
"# Current time local: %s\n# Current time GMT: %s\n",
scalar( localtime($^T) ), scalar( gmtime($^T) );
print "# byebye from ", __FILE__, "\n";
HTML-Tree-5.03/t/building.t 0000644 0001750 0001750 00000012143 12027460670 013440 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
#Test that we can build and compare trees
use Test::More tests => 46;
use HTML::Element;
FIRST_BLOCK: {
my $lol = [
'html',
[ 'head', [ 'title', 'I like stuff!' ], ],
[ 'body', { 'lang', 'en-JP' },
'stuff',
[ 'p', 'um, p < 4!', { 'class' => 'par123' } ],
[ 'div', { foo => 'bar' }, ' 1 2 3 ' ], # at 0.1.2
[ 'div', { fu => 'baa' }, " 1 and 2 \xA0 3 " ], # RT #26436 test
['hr'],
]
];
my $t1 = HTML::Element->new_from_lol($lol);
isa_ok( $t1, 'HTML::Element' );
### added to test ->is_empty() and ->look_up()
my $hr = $t1->find('hr');
isa_ok( $hr, 'HTML::Element' );
ok( $hr->is_empty(), "testing is_empty method on tag" );
my $lookuptag = $hr->look_up( "_tag", "body" );
is( '',
$lookuptag->starttag(), "verify hr->look_up found body tag" );
my %attrs = $lookuptag->all_attr();
my @attrs1 = sort keys %attrs;
my @attrs2 = sort $lookuptag->all_attr_names();
is_deeply( \@attrs1, \@attrs2, "is_deeply attrs" );
# Test scalar context
my $count = $t1->content_list;
is( $count, 2, "Works in scalar" );
# Test list context
my @list = $t1->content_list;
is( scalar @list, 2, "Should get two items back" );
isa_ok( $list[0], 'HTML::Element' );
isa_ok( $list[1], 'HTML::Element' );
my $div = $t1->find_by_attribute( 'foo', 'bar' );
isa_ok( $div, 'HTML::Element' );
### tests of various output formats
is( $div->as_text(), " 1 2 3 ", "Dump element in text format" );
is( $div->as_trimmed_text(), "1 2 3",
"Dump element in trimmed text format" );
is( $div->as_text_trimmed(), "1 2 3",
"Dump element in trimmed text format" );
is( $div->as_Lisp_form(),
qq{("_tag" "div" "foo" "bar" "_content" (\n " 1 2 3 "))\n},
"Dump element as Lisp form"
);
is( $div->address, '0.1.2' );
is( $div, $t1->address('0.1.2'), 'using address to get the node' );
ok( $div->same_as($div) );
ok( $t1->same_as($t1) );
ok( not( $div->same_as($t1) ) );
my $div2 = $t1->find_by_attribute( 'fu', 'baa' );
isa_ok( $div2, 'HTML::Element' );
### test for RT #26436 user controlled white space
is( $div2->as_text(), " 1 and 2 \xA0 3 ", "Dump element in text format" );
is( $div2->as_trimmed_text(),
"1 and 2 \xA0 3", "Dump element in trimmed text format" );
is( $div2->as_trimmed_text( extra_chars => 'a-z\xA0' ),
"1 2 3", "Dump element in trimmed text format without nbsp or letters");
is( $div2->as_trimmed_text( extra_chars => '[:alpha:]' ),
"1 2 \xA0 3", "Dump element in trimmed text format without letters");
my $t2 = HTML::Element->new_from_lol($lol);
isa_ok( $t2, 'HTML::Element' );
ok( $t2->same_as($t1) );
$t2->address('0.1.2')->attr( 'snap', 123 );
ok( not( $t2->same_as($t1) ) );
my $body = $t1->find_by_tag_name('body');
isa_ok( $body, 'HTML::Element' );
is( $body->tag, 'body' );
my $cl = join '~', $body->content_list;
my @detached = $body->detach_content;
is( $cl, join '~', @detached );
$body->push_content(@detached);
is( $cl, join '~', $body->content_list );
$t2->delete;
$t1->delete;
} # FIRST_BLOCK
TEST2: { # for normalization
my $t1 = HTML::Element->new_from_lol( [ 'p', 'stuff', ['hr'], 'thing' ] );
my @start = $t1->content_list;
is( scalar(@start), 3 );
my $lr = $t1->content;
# $lr is ['stuff', HTML::Element('hr'), 'thing']
is( $lr->[0], 'stuff' );
isa_ok( $lr->[1], 'HTML::Element' );
is( $lr->[2], 'thing' );
# insert some undefs
splice @$lr, 1, 0, undef; # insert an undef between [0] and [1]
push @$lr, undef; # append an undef to the end
unshift @$lr, undef; # prepend an undef to the front
# $lr is [undef, 'stuff', undef, H::E('hr'), 'thing', undef]
UNNORMALIZED: {
my $cl_count = $t1->content_list;
my @cl = $t1->content_list;
is( $cl_count, 6 );
is( scalar(@cl), $cl_count ); # also == 6
{
no warnings; # content_list contains undefs
isnt( join( '~', @start ), join( '~', $t1->content_list ) );
}
}
NORMALIZED: {
$t1->normalize_content;
my @cl = $t1->content_list;
eq_array( \@start, \@cl );
}
ok( not defined( $t1->attr('foo') ) );
$t1->attr( 'foo', 'bar' );
is( $t1->attr('foo'), 'bar' );
ok( scalar( grep( 'bar', $t1->all_external_attr() ) ) );
$t1->attr( 'foo', '' );
ok( scalar( grep( 'bar', $t1->all_external_attr() ) ) );
$t1->attr( 'foo', undef ); # should delete it
ok( not grep( 'bar', $t1->all_external_attr() ) );
$t1->delete;
} # TEST2
EXTRA_CHARS_IS_FALSE: {
my $h = HTML::Element->new_from_lol([p => '1 2 0 4']);
is( $h->as_text, '1 2 0 4', "Dump p in text format" );
is( $h->as_trimmed_text, '1 2 0 4', "Dump p in trimmed format" );
is( $h->as_trimmed_text(extra_chars => '0'), '1 2 4',
"Dump p in trimmed format without 0" );
}
HTML-Tree-5.03/t/children.t 0000644 0001750 0001750 00000001551 12027460670 013434 0 ustar cjm cjm #!/usr/bin/perl -T
# RT 21114 test case. Thanks Andrew Suhachov for finding it.
use warnings;
use strict;
use Test::More tests => 3;
use HTML::TreeBuilder;
my $root = HTML::TreeBuilder->new();
my $escape
= '';
my $html = $root->parse($escape)->eof;
my $child = $root->look_down(
_tag => 'tr',
sub {
my $tr = shift;
$tr->look_down( _tag => 'td', _parent => $tr ) ? 1 : 0;
}
);
isa_ok( $child, 'HTML::Element', "Child found" );
my @children = $root->look_down(
_tag => 'tr',
sub {
my $tr = shift;
$tr->look_down( _tag => 'td', _parent => $tr ) ? 1 : 0;
}
);
cmp_ok( scalar(@children), '==', '2', "2 total children found" );
my $none = $root->look_down( _tag => 'tr', sub {0} );
ok( !defined($none), 'No children found' );
HTML-Tree-5.03/t/leaktest.t 0000644 0001750 0001750 00000013240 12027460670 013456 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
#Test that we don't leak memory
use Test::More;
my $leak_trace_loaded;
# RECOMMEND PREREQ: Test::LeakTrace
BEGIN { $leak_trace_loaded = eval "use Test::LeakTrace; 1" }
plan skip_all => "Test::LeakTrace required for testing memory leaks"
unless $leak_trace_loaded;
plan tests => 20;
use HTML::TreeBuilder;
my $lacks_weak;
sub first_block {
my $lol = [
'html',
[ 'head', [ 'title', 'I like stuff!' ], ],
[ 'body', { 'lang', 'en-JP' },
'stuff',
[ 'p', 'um, p < 4!', { 'class' => 'par123' } ],
[ 'div', { foo => 'bar' }, ' 1 2 3 ' ], # at 0.1.2
[ 'div', { fu => 'baa' }, " 1 2 \xA0 3 " ], # RT #26436 test
['hr'],
]
];
my $t1 = HTML::Element->new_from_lol($lol);
### added to test ->is_empty() and ->look_up()
my $hr = $t1->find('hr');
my $lookuptag = $hr->look_up( "_tag", "body" );
my %attrs = $lookuptag->all_attr();
my @attrs1 = sort keys %attrs;
my @attrs2 = sort $lookuptag->all_attr_names();
# Test scalar context
my $count = $t1->content_list;
# Test list context
my @list = $t1->content_list;
my $div = $t1->find_by_attribute( 'foo', 'bar' );
my $div2 = $t1->find_by_attribute( 'fu', 'baa' );
my $t2 = HTML::Element->new_from_lol($lol);
$t2->address('0.1.2')->attr( 'snap', 123 );
my $body = $t1->find_by_tag_name('body');
my $cl = join '~', $body->content_list;
my @detached = $body->detach_content;
$body->push_content(@detached);
$t2->delete if $lacks_weak;
$t1->delete if $lacks_weak;
} # end first_block
sub second_block {
# for normalization
my $t1 = HTML::Element->new_from_lol( [ 'p', 'stuff', ['hr'], 'thing' ] );
my @start = $t1->content_list;
my $lr = $t1->content;
# insert some undefs
splice @$lr, 1, 0, undef; # insert an undef between [0] and [1]
push @$lr, undef; # append an undef to the end
unshift @$lr, undef; # prepend an undef to the front
# $lr is [undef, 'stuff', undef, H::E('hr'), 'thing', undef]
{
my $cl_count = $t1->content_list;
my @cl = $t1->content_list;
}
{
$t1->normalize_content;
my @cl = $t1->content_list;
}
$t1->attr( 'foo', 'bar' );
$t1->attr( 'foo', '' );
$t1->attr( 'foo', undef ); # should delete it
$t1->delete if $lacks_weak;
} # end second_block
sub empty_tree {
my $root = HTML::TreeBuilder->new();
$root->implicit_body_p_tag(1);
$root->xml_mode(1);
$root->parse('');
$root->eof();
$root->delete if $lacks_weak;
}
sub br_only {
my $root = HTML::TreeBuilder->new();
$root->implicit_body_p_tag(1);
$root->xml_mode(1);
$root->parse(' ');
$root->eof();
$root->delete if $lacks_weak;
}
sub text_only {
my $root = HTML::TreeBuilder->new();
$root->implicit_body_p_tag(1);
$root->xml_mode(1);
$root->parse('text');
$root->eof();
$root->delete if $lacks_weak;
}
sub empty_table {
my $root = HTML::TreeBuilder->new();
$root->implicit_body_p_tag(1);
$root->xml_mode(1);
$root->parse('');
$root->eof();
$root->delete if $lacks_weak;
}
sub escapes {
my $root = HTML::TreeBuilder->new();
my $escape = 'This ſoftware has ſome bugs';
my $html = $root->parse($escape)->eof->elementify();
$html->delete if $lacks_weak;
}
sub other_languages {
my $root = HTML::TreeBuilder->new();
my $escape = 'Gebühr vor Ort von € 30,- pro Woche'; # RT 14212
my $html = $root->parse($escape)->eof;
$html->delete if $lacks_weak;
}
sub rt_18570 {
my $root = HTML::TreeBuilder->new();
my $escape = 'This ∼ is a twiddle';
my $html = $root->parse($escape)->eof->elementify();
$html->delete if $lacks_weak;
}
sub rt_18571 {
my $root = HTML::TreeBuilder->new();
my $html = $root->parse('$self->escape ')->eof->elementify();
$html->delete if $lacks_weak;
}
# Try with weak refs, if available:
SKIP: {
skip('Scalar::Util lacks support for weak references', 10)
unless HTML::Element->Use_Weak_Refs;
no_leaks_ok(\&first_block, 'first block has no leaks with weak refs');
no_leaks_ok(\&second_block, 'second block has no leaks with weak refs');
no_leaks_ok(\&empty_tree, 'empty_tree has no leaks with weak refs');
no_leaks_ok(\&br_only, 'br_only has no leaks with weak refs');
no_leaks_ok(\&text_only, 'text_only has no leaks with weak refs');
no_leaks_ok(\&empty_table, 'empty_table has no leaks with weak refs');
no_leaks_ok(\&escapes, 'escapes has no leaks with weak refs');
no_leaks_ok(\&other_languages, 'other_languages has no leaks with weak refs');
no_leaks_ok(\&rt_18570, 'rt_18570 has no leaks with weak refs');
no_leaks_ok(\&rt_18571, 'rt_18571 has no leaks with weak refs');
}
# Try again without weak refs:
$lacks_weak = 1;
HTML::Element->Use_Weak_Refs(0);
no_leaks_ok(\&first_block, 'first block has no leaks without weak refs');
no_leaks_ok(\&second_block, 'second block has no leaks without weak refs');
no_leaks_ok(\&empty_tree, 'empty_tree has no leaks without weak refs');
no_leaks_ok(\&br_only, 'br_only has no leaks without weak refs');
no_leaks_ok(\&text_only, 'text_only has no leaks without weak refs');
no_leaks_ok(\&empty_table, 'empty_table has no leaks without weak refs');
no_leaks_ok(\&escapes, 'escapes has no leaks without weak refs');
no_leaks_ok(\&other_languages, 'other_languages has no leaks without weak refs');
no_leaks_ok(\&rt_18570, 'rt_18570 has no leaks without weak refs');
no_leaks_ok(\&rt_18571, 'rt_18571 has no leaks without weak refs');
HTML-Tree-5.03/t/oldparse.t 0000644 0001750 0001750 00000003523 12027460670 013456 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
use Test::More tests => 16;
use HTML::Parse;
# This is a very simple test. It basically just ensures that the
# HTML::Parse module is parsed ok by perl and that it will interact
# nicely with the rest of our modules
our $TestInput = "t/oldparse.html";
my $HTML;
{
local $/ = undef;
open( "INFILE", "$TestInput" ) || die "$!";
binmode INFILE;
$HTML = ;
close(INFILE);
}
my $own_builder = new HTML::TreeBuilder;
isa_ok( $own_builder, 'HTML::TreeBuilder' );
my $obj_h = parse_html $HTML, $own_builder;
isa_ok( $obj_h, "HTML::TreeBuilder", "existing TreeBuilder handled OK." );
my $h = parse_html $HTML;
isa_ok( $h, "HTML::TreeBuilder" );
# This ensures that the output from $h->dump goes to STDOUT
my $html;
ok( $html = $h->as_HTML( undef, ' ' ), "Get html as string." );
# This is a very simple test just to ensure that we get something
# sensible back.
like( $html, qr//i, " found OK." );
like( $html, qr/www\.sn\.no/, "found www.sn.no link" );
unlike( $html, qr/comment/, "Didn't find comment" );
like( $html, qr/Gisle/, "found Gisle" );
my $bad_file = parse_htmlfile("non-existent-file.html");
ok( !$bad_file, "Properly returned undef on missing file." );
my $own_obj_parser2 = parse_htmlfile( "t/oldparse.html", $own_builder );
isa_ok( $own_obj_parser2, "HTML::TreeBuilder" );
my $h2 = parse_htmlfile("t/oldparse.html");
isa_ok( $h2, "HTML::TreeBuilder" );
ok( $html = $h2->as_HTML( undef, ' ' ), "Get html as string." );
# This is a very simple test just to ensure that we get something
# sensible back.
like( $html, qr//i, "parse_htmlfile: found OK." );
like( $html, qr/www\.sn\.no/, "parse_htmlfile: found www.sn.no link" );
unlike( $html, qr/comment/, "parse_htmlfile: found comment" );
like( $html, qr/Gisle/, "parse_htmlfile: found Gisle" );
HTML-Tree-5.03/t/sample.txt 0000644 0001750 0001750 00000000045 12027460670 013476 0 ustar cjm cjm This is a plain text file, not HTML.
HTML-Tree-5.03/t/subclass.t 0000644 0001750 0001750 00000001140 12027460670 013455 0 ustar cjm cjm #!/usr/bin/perl -T
use strict;
use warnings;
use Test::More tests => 2;
use HTML::Element;
my $div = new HTML::Element('div')->push_content('super class content');
like(
$div->as_HTML,
qr{super class content
},
'HTML::Element output'
);
my $mydiv = new MyElement('div')->push_content( [ 'div', $div ] );
like(
$mydiv->as_HTML,
qr{},
'MyElement output'
);
package MyElement;
use base 'HTML::Element';
sub new {
my $invoker = shift;
my $class = ref $invoker || $invoker;
return $class->SUPER::new(@_);
}
HTML-Tree-5.03/t/parsefile.t 0000644 0001750 0001750 00000003576 12027460670 013627 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
use Test::More tests => 4;
use HTML::TreeBuilder;
print "#Using HTML::TreeBuilder version v$HTML::TreeBuilder::VERSION\n";
print "#Using HTML::Element version v$HTML::Element::VERSION\n";
print "#Using HTML::Parser version v", $HTML::Parser::VERSION || "?", "\n";
print "#Using HTML::Entities version v", $HTML::Entities::VERSION || "?",
"\n";
print "#Using HTML::Tagset version v", $HTML::Tagset::VERSION || "?", "\n";
print "# Running under perl version $] for $^O",
( chr(65) eq 'A' ) ? "\n" : " in a non-ASCII world\n";
print "# Win32::BuildNumber ", &Win32::BuildNumber(), "\n"
if defined(&Win32::BuildNumber)
and defined &Win32::BuildNumber();
print "# MacPerl verison $MacPerl::Version\n"
if defined $MacPerl::Version;
printf
"# Current time local: %s\n# Current time GMT: %s\n",
scalar( localtime($^T) ), scalar( gmtime($^T) );
my $tempfile = "lwp-test-$$";
open( F, ">$tempfile" ) or die "Can't open $tempfile: $!";
print F <
Libwww-perl test
This is some text and this is a simple link back to the
libwww-perl site.
new;
$h->parse_file($tempfile);
unlink($tempfile);
{
my $x = $_ = $h->as_HTML;
$x =~ s/^/# /mg;
print "# As HTML: $x#\n";
}
# Just make a few samples to check that we got what we expected
like( $_, qr//i, "Matches Head" );
like( $_, qr/ /i, "Matches isindex" );
like(
$_,
qr/ /,
"Found the img tag"
);
like( $_, qr/this is a simple/, "Matches simple text" );
# /foo\s*a=b/ || $bad++; # too version-dependent
HTML-Tree-5.03/t/attributes.t 0000644 0001750 0001750 00000002167 12027460670 014036 0 ustar cjm cjm #!/usr/bin/perl -T
# HTML::TreeBuilder invokes HTML::Entities::decode on the contents of
# HREF attributes. Some CGI-based sites use lang=en or such for
# internationalization. When this parameter is after an ampersand,
# the resulting &lang is decoded, breaking the link. "sub" is another
# popular one.
# Test provided by Rocco Caputo
use warnings;
use strict;
use Test::More tests => 3;
use HTML::TreeBuilder;
my $tb = HTML::TreeBuilder->new();
$tb->parse("Test ");
my @links = $tb->look_down( sub { $_[0]->tag eq "a" } );
my $href = $links[0]->attr("href");
ok( $href =~ /lang/, "href should contain 'lang' (is: $href)" );
# invalid attribute names (RT 23439)
my $html = HTML::TreeBuilder->new_from_content(' ');
eval { $html->as_XML(); };
like(
$@,
qr|img has an invalid attribute name 'inval!d'|,
'catch invalid atribute names'
);
# xhtml
my $xhtml = HTML::TreeBuilder->new_from_content(q{ });
my $img = $xhtml->find_by_tag_name('img');
like($img->as_XML(), qr{ });
$xhtml = $xhtml->delete;
exit;
HTML-Tree-5.03/t/whitespace.t 0000644 0001750 0001750 00000001727 12027460670 014005 0 ustar cjm cjm #! /usr/bin/perl
#---------------------------------------------------------------------
# Test whether parsing can preserve whitespace
use strict;
use warnings;
use Test::More;
use HTML::TreeBuilder;
my @tests = (
'I Like
!',
'I Like
!',
"This has a newline\nhere.
",
"This has two newlines\n\nhere.
",
"This\xA0has nbsp: \xA0
",
);
plan tests => 1 + scalar @tests;
for my $test (@tests) {
my $tree = HTML::TreeBuilder->new;
$tree->ignore_ignorable_whitespace(0);
$tree->no_space_compacting(1);
$tree->parse_content($test);
my ($name) = ($test =~ /^(.*)/);
is($tree->look_down(qw(_tag body))->as_HTML('<>&', undef, {}),
"$test", $name);
} # end for each $test in @tests
RT_66498: {
is( HTML::TreeBuilder->new_from_content("a
b
")
->as_text,
"ab",
"parsing does not add whitespace"
);
}
HTML-Tree-5.03/t/oldparse.html 0000644 0001750 0001750 00000001327 12027460670 014157 0 ustar cjm cjm
Test page
Header
This is a link to
Schibsted Nett in Norway.
Sofie Amundsen var p vei hjem fra skolen. Det frste stykket
hadde hun gtt sammen med Jorunn. De hadde snakket om roboter.
Jorunn hadde ment at menneskets hjerne var som en komplisert
datamaskin. Sofie var ikke helt sikker p om hun var enig. Et
menneske måtte da vre noe mer enn en maskin?
<-- this one did not terminate the nested-comment
because "--" on the previous line
more comment
-->
Name
Aas Gisle
Koster Martijn
HTML-Tree-5.03/t/tag-rendering.t 0000644 0001750 0001750 00000003520 12027460670 014370 0 ustar cjm cjm #!/usr/bin/perl -T
use warnings;
use strict;
use Test::More tests => 11;
use HTML::Element;
my $img = HTML::Element->new(
'img',
( src => 'damian-conway-in-a-dress.jpg',
height => 540,
width => 100,
border => 0,
alt => "A few bottles of Chech'tluth later...",
)
);
my $href = '/report/fullcsv';
my $literal_href = HTML::Element->new( '~literal',
'text' => "window.location.href='$href'" );
$img->attr( onClick => $literal_href );
isa_ok( $img, 'HTML::Element' );
my $html = $img->as_HTML;
print $html, "\n";
like( $html, qr/ /, "Tag is self-closed" );
like( $html, qr/ height="540" /, "Height is quoted" );
like( $html, qr/ border="0" /, "Border is quoted" );
like( $html, qr/ width="100" /, "Width is quoted" );
like(
$html,
qr! onclick="window.location.href='$href'!,
"Literal text is preserved"
);
like(
$html,
qr/ alt="A few bottles of Chech'tluth later..." /,
"Alt tag is quoted and escaped"
);
# _empty_element_map anchor test (RT 49932)
my $a = HTML::Element->new( 'a', href => 'example.com' );
my $xml = $a->as_XML();
like(
$xml,
qr{ },
"A tag not in _empty_element_map"
);
my $empty_element_map = $a->_empty_element_map;
$empty_element_map->{'a'} = 1;
$xml = $a->as_XML();
like(
$xml,
qr{ },
"A tag in _empty_element_map, no content"
);
$a->push_content("Extra content");
$xml = $a->as_XML();
like(
$xml,
qr{Extra content },
"A tag in _empty_element_map, with content"
);
my $text = undef;
my $input = HTML::Element->new( 'input', type => 'text', value => $text );
$html = $input->as_HTML;
like(
$html,
qr{ },
"Setting an attribute to undef defaults the value to the attribute name"
);
HTML-Tree-5.03/t/construct_tree.t 0000644 0001750 0001750 00000011003 12027460670 014700 0 ustar cjm cjm #!/usr/bin/perl
use warnings;
use strict;
use constant tests_per_object => 7;
use Test::More tests => ( 5 + 10 * tests_per_object );
use Test::Fatal qw(exception);
#initial tests + number of tests in test_new_obj() * number of times called
use HTML::Tree;
my $obj = new HTML::Tree;
isa_ok( $obj, "HTML::TreeBuilder" );
my $TestInput = "t/oldparse.html";
my $HTML;
{
local $/ = undef;
open( INFILE, $TestInput ) || die "Can't open $TestInput: $!";
binmode INFILE;
$HTML = ;
close(INFILE);
}
# setup some parts of the HTML for the list tests.
# die "$TestInput does not have at least 2 characters!"
# if length($HTML) <= 2;
# my $HTMLPart1 = substr( $HTML, 0, int( length($HTML) / 2 ) );
# my $HTMLPart2 = substr( $HTML, int( length($HTML) / 2 ) );
# The logic here is to try to split the HTML in the middle of a tag.
# The above commented-out code is also an option.
my $split_at = 4;
die "$TestInput does not have at least " . ( $split_at + 1 ) . " characters!"
if length($HTML) <= $split_at;
my $HTMLPart1 = substr( $HTML, 0, 4 );
my $HTMLPart2 = substr( $HTML, 4 );
is( $HTMLPart1 . $HTMLPart2, $HTML, "split \$HTML correctly" );
# Filehandle Test
{
open( INFILE, $TestInput ) || die "Can't open $TestInput: $!";
binmode INFILE;
my $file_obj = HTML::Tree->new_from_file(*INFILE);
test_new_obj( $file_obj, "new_from_file Filehandle" );
close(INFILE);
}
# Scalar Tests
{
my $content_obj = HTML::Tree->new_from_content($HTML);
test_new_obj( $content_obj, "new_from_content Scalar" );
}
{
my $file_obj = HTML::Tree->new_from_file($TestInput);
test_new_obj( $file_obj, "new_from_file Scalar" );
}
{
my $parse_content_obj = HTML::Tree->new;
$parse_content_obj->parse_content($HTML);
test_new_obj( $parse_content_obj, "new(); parse_content Scalar" );
}
# URL tests
{
SKIP: {
eval {
# RECOMMEND PREREQ: URI::file
require URI::file;
require LWP::UserAgent;
1;
} or skip("URI::file or LWP::UserAgent not installed",
2 + 2 * tests_per_object);
my $file_url = URI->new( "file:" . $TestInput );
{
my $file_obj = HTML::Tree->new_from_url( $file_url->as_string );
test_new_obj( $file_obj, "new_from_url Scalar" );
}
{
my $file_obj = HTML::Tree->new_from_url($file_url);
test_new_obj( $file_obj, "new_from_url Object" );
}
like(
exception { HTML::Tree->new_from_url( "file:t/sample.txt" ) },
qr!^file:t/sample\.txt returned text/plain not HTML\b!,
"opening text/plain URL failed"
);
like(
exception { HTML::Tree->new_from_url( "file:t/non_existent.html" ) },
qr!^GET failed on file:t/non_existent\.html: 404 !,
"opening 404 URL failed"
);
}
}
# Scalar REF Tests
{
my $content_obj = HTML::Tree->new_from_content($HTML);
test_new_obj( $content_obj, "new_from_content Scalar REF" );
}
# None for new_from_file
# Filehandle test instead. (see above)
{
my $parse_content_obj = HTML::Tree->new;
$parse_content_obj->parse_content($HTML);
test_new_obj( $parse_content_obj, "new(); parse_content Scalar REF" );
}
# List Tests (Scalar and Scalar REF)
{
my $content_obj = HTML::Tree->new_from_content( \$HTMLPart1, $HTMLPart2 );
test_new_obj( $content_obj, "new_from_content List" );
}
# None for new_from_file.
# Does not support lists.
{
my $parse_content_obj = HTML::Tree->new;
$parse_content_obj->parse_content( \$HTMLPart1, $HTMLPart2 );
test_new_obj( $parse_content_obj, "new(); parse_content List" );
}
# Nonexistent file test:
like(
exception { HTML::Tree->new_from_file( "t/non_existent.html" ) },
qr!^unable to parse file: !,
"opening missing file failed"
);
sub test_new_obj {
my $obj = shift;
my $test_description = shift;
isa_ok( $obj, "HTML::TreeBuilder", $test_description );
my $html = $obj->as_HTML( undef, ' ' );
ok( $html, "Get HTML as string." );
# This is a very simple test just to ensure that we get something
# sensible back.
like( $html, qr//i, " found OK." );
like( $html, qr/www\.sn\.no/, "found www.sn.no link" );
TODO: {
local $TODO = <