Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

XPath test

  • Loading branch information...
commit 33114d4264629deb626b195eed441be7994b7b8f 1 parent 858405d
@creaktive authored
Showing with 281 additions and 0 deletions.
  1. +50 −0 t/20-xpath.t
  2. +231 −0 t/cpan.html
View
50 t/20-xpath.t
@@ -0,0 +1,50 @@
+use common::sense;
+
+use FindBin qw($Bin);
+use HTML::TreeBuilder::XPath;
+use Path::Class;
+use Test::More;
+
+use_ok(q(HTML::Linear));
+
+my $file = q...file($Bin, q(cpan.html));
+
+my $xpath = HTML::TreeBuilder::XPath->new;
+isa_ok($xpath, q(HTML::TreeBuilder::XPath));
+can_ok($xpath, qw(parse_file findvalue));
+ok($xpath->parse_file($file), q(HTML::TreeBuilder::XPath::parse_file));
+
+my $hl = HTML::Linear->new;
+$hl->set_strict;
+
+ok($hl->parse_file($file), q(HTML::Linear::parse_file));
+
+my %hash;
+for my $el ($hl->as_list) {
+ my $hash = $el->as_hash;
+ for (keys %{$hash}) {
+ if (m{/text\(\)$}sx) {
+ $hash{$_} .= $hash->{$_};
+ } else {
+ $hash{$_} = $hash->{$_};
+ }
+ }
+}
+
+my $n = 0;
+for my $expr (keys %hash) {
+ my $content = $hash{$expr};
+ $content =~ s/^\s+|\s+$//gsx;
+
+ my $value = $xpath->findvalue($expr);
+ $value =~ s/^\s+|\s+$//gsx;
+
+ ok(
+ $value eq $content,
+ qq($expr\t"$value"\t"$content"),
+ );
+
+ ++$n;
+}
+
+done_testing(5 + $n);
View
231 t/cpan.html
@@ -0,0 +1,231 @@
+
+
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>The Comprehensive Perl Archive Network - www.cpan.org</title>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <link rel="author" href="mailto:cpan+linkrelauthor@perl.org" />
+ <link rel="canonical" href="http://www.cpan.org/index.html" />
+ <link type="text/css" rel="stylesheet" href="misc/css/cpan.css" />
+
+<!-- Copyright Jarkko Hietaniemi <jhi@iki.fi>
+ 1998,1999,2000,2001,2003,2003,2004,2005,2008
+ Copyright 2010-2011 Ask Bjørn Hansen <ask@perl.org>
+ All Rights Reserved.
+ The CPAN Logo provided by J.C. Thorpe.
+ You may distribute this document either under the Artistic License
+ (comes with Perl) or the GNU Public License, whichever suits you.
+
+ LEGALESE
+
+ You are not allowed to remove or alter these comments.
+
+ You are not allowed to rename, remove, or add any files
+ in your public mirror of CPAN.
+
+ "Public mirror of CPAN" means a site listed in
+ the SITES.html and SITES files at the top level of CPAN
+ and also listed at the site http://mirrors.cpan.org/.
+
+ You are not allowed to alter any file
+ in you public mirror of CPAN
+ EXCEPT
+ that you can add a short acknowledgement for example
+ for your hosting company, company, university, or sponsor,
+ into this CPAN top-level index.html by adding a small
+ non-animated image and a hyperlink pointing to your organization
+ with text like "hosted by", "powered by", or "sponsored by",
+ by placing it visually next to the "CPAN master site hosted by YellowBot"
+ acknowledgement at the bottom of the page.
+ The image used may not be larger than the one used for the YellowBot logo.
+ (Technical sidenote: if you do add an acknowledgement link,
+ please do think of the consequences to your possible downstream
+ CPAN mirrors.)
+ Altering this index.html in any other way is not allowed.
+ Altering any other files is not allowed.
+
+ Adding any advertisements or any revenue-generating material
+ is strictly forbidden.
+
+ Similarly, for your public CPAN mirrors "framing" or "wrapping"
+ the CPAN web pages into other sites by using e.g. HTML tables
+ or frames is not allowed.
+
+ You are allowed to use the files of CPAN to create your own
+ web sites and services since we are just a distributor of the files,
+ we do not own most of them. However, you may not call your creations
+ "CPAN" or "CPAN mirrors". You may say that the files are "mirrored
+ from CPAN".
+
+-->
+<script type="text/javascript" charset="utf-8">
+ function focusField() {
+ document.getElementById("searchfield").focus();
+ }
+ onload = focusField;
+</script>
+
+
+</head>
+<body class="section_home">
+
+<table id="wrapper" border="0" width="95%" cellspacing="0" cellpadding="2" align="center">
+ <tr>
+ <td id="header">
+
+ <div id="header_left">
+ <a href="index.html"><img src="misc/images/cpan.png" id="logo" alt="CPAN" /></a>
+ </div>
+
+ <div id="header_right">
+ <h1>Comprehensive Perl Archive Network</h1>
+ <p id="strapline">Over 15 years of Perl libraries at your fingertips
+
+
+</p>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td id="menubar_holder">
+
+ <ul class="menubar">
+ <li><a href="index.html">Home</a></li>
+ <li><a href="modules/index.html">Modules</a></li>
+ <li><a href="ports/index.html">Ports</a></li>
+ <li><a href="src/README.html">Perl Source</a></li>
+ <li><a href="misc/cpan-faq.html">FAQ</a></li>
+ <li><a href="SITES.html">Mirrors</a></li>
+ </ul>
+
+ <div id="searchbar">
+ <form method="get" action="http://search.cpan.org/search" name="f" class="searchbox menubar" id="f">
+ <input type="hidden" name="mode" value="all" />
+ <a href="http://search.cpan.org">Search</a>:
+ <input id="searchfield" type="text" name="query" value="" placeholder="Module name" />
+ <input type="submit" value="Search" />
+ </form>
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <div id="content">
+
+
+
+ <table border="0" cellspacing="0" cellpadding="0">
+ <tr>
+ <td class="third">
+ <h2>Welcome to CPAN</h2>
+ <p>
+ The Comprehensive Perl Archive Network (CPAN) currently
+ has <a href="modules/index.html">106,461
+ Perl modules</a> in 24,809 distributions,
+ written by 9,672 authors,
+ <a href="SITES.html">mirrored</a> on 277 servers.
+ </p>
+ <p>The archive has been online since October 1995 and is constantly growing.</p>
+
+ <h2>Search CPAN via</h2>
+
+ <ul>
+ <li><a href="http://metacpan.org/">metacpan.org</a></li>
+ <li><a href="http://search.cpan.org/">search.cpan.org</a></li>
+ </ul>
+
+ </td>
+
+ <td class="third">
+ <div style="margin-left: 20px">
+ <h2>Recent Uploads</h2>
+
+
+
+
+ <ul>
+
+ <li><a href="http://search.cpan.org/~jberger/PerlGSL-Integration-SingleDim-0.001/">PerlGSL-Integration-SingleDim-0.001</a></li>
+
+
+ <li><a href="http://search.cpan.org/~canid/Yote-0.088/">Yote-0.088</a></li>
+
+
+ <li><a href="http://search.cpan.org/~khw/Unicode-Casing-10_01/">Unicode-Casing-10_01</a></li>
+
+
+ <li><a href="http://search.cpan.org/~caio/Data-FlexSerializer-1.05/">Data-FlexSerializer-1.05</a></li>
+
+
+ <li><a href="http://search.cpan.org/~bduggan/Mojolicious-Plugin-Toto-0.09/">Mojolicious-Plugin-Toto-0.09</a></li>
+
+
+ <li><a href="http://search.cpan.org/~adamba/Juno-0.001/">Juno-0.001</a></li>
+
+
+ <li><a href="http://search.cpan.org/~tobyink/Web-ID-1.910_04/">Web-ID-1.910_04</a></li>
+
+
+ <li><a href="http://search.cpan.org/~nics/Catmandu-LDAP-0.0101/">Catmandu-LDAP-0.0101</a></li>
+
+
+ <li><a href="http://search.cpan.org/~rpettett/Module-PortablePath-0.17/">Module-PortablePath-0.17</a></li>
+
+
+ <li><a href="http://search.cpan.org/~salva/Pg-PQ-0.07/">Pg-PQ-0.07</a></li>
+
+ <li><a href="http://search.cpan.org/recent"><strong>more...</strong></a></li>
+ </ul>
+
+
+ </div>
+ </td>
+
+ <td class="third">
+ <h2>Getting Started</h2>
+ <ul>
+ <li><a href="modules/INSTALL.html">Installing Perl Modules</a></li>
+ <li><a href="http://learn.perl.org/">Learn Perl</a></li>
+ </ul>
+
+ <h2>Perl Resources</h2>
+ <ul>
+ <li><a href="http://www.perl.org/">The Perl Programming language</a></li>
+ <li><a href="http://perldoc.perl.org/">Perl Documentation</a></li>
+ <li><a href="http://lists.perl.org/">Mailing Lists</a></li>
+ <li><a href="http://learn.perl.org/faq/">Perl FAQ</a></li>
+ <li><a href="scripts/index.html">Scripts Repository</a></li>
+ </ul>
+ </td>
+ </tr>
+ </table>
+
+ </div>
+ </td>
+ </tr>
+ <tr>
+ <td id="footer">
+ <div id="footer_copyright">
+ <p>Yours Eclectically, The Self-Appointed Master Librarians (<i>OOK!</i>) of the CPAN.<br/>
+ &copy; 1995-2010 Jarkko Hietaniemi.
+ &copy; 2011 <a href="http://www.perl.org">Perl.org</a>.
+ All rights reserved.
+ <a href="disclaimer.html">Disclaimer</a>.
+ </p>
+ </div>
+
+
+ <div id="footer_mirror">
+ <p>Master mirror hosted by <a href="http://www.yellowbot.com/"><img alt="YellowBot" src="misc/images/yellowbot.png" /></a></p>
+ </div>
+
+
+
+ </td>
+ </tr>
+</table>
+
+
+</body>
+</html>
+
Please sign in to comment.
Something went wrong with that request. Please try again.