File: lib.pm

package info (click to toggle)
libhtml-element-library-perl 5.220000-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 332 kB
  • sloc: perl: 857; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 748 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package t::lib;
use strict;
use warnings;

use File::Slurp qw/read_file/;
use HTML::TreeBuilder;
use HTML::Element::Library;
use Test::More ();
use Test::XML;

use parent qw/Exporter/;
our @EXPORT = qw/is is_deeply is_xml slurp mktree isxml/;
our $VERSION = '0.001'; # Exporter needs a $VERSION

sub import {
	my ($self, @args) = @_;
	strict->import;
	warnings->import;
	Test::More->import(@args);

	$self->export_to_level(1, $self);
}

sub slurp { scalar read_file @_ }

sub mktree {
	my ($file) = @_;
	HTML::TreeBuilder->new_from_file($file)->disembowel;
}

sub isxml {
	my ($tree, $file, $name) = @_;
	my $res = ref $tree eq 'SCALAR' ? $$tree : $tree->as_XML;
	my $exp = ref $file eq 'SCALAR' ? $$file : slurp $file;
	is_xml $res, $exp, $name
}