| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Test::XML::Valid; |
|
3
|
1
|
|
|
1
|
|
70148
|
use XML::LibXML; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use strict; |
|
5
|
|
|
|
|
|
|
use Test::Builder; |
|
6
|
|
|
|
|
|
|
use vars qw/$VERSION/; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION = "0.04"; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import { |
|
13
|
|
|
|
|
|
|
my $self = shift; |
|
14
|
|
|
|
|
|
|
my $caller = caller; |
|
15
|
|
|
|
|
|
|
no strict 'refs'; |
|
16
|
|
|
|
|
|
|
*{$caller.'::xml_file_ok'} = \&xml_file_ok; |
|
17
|
|
|
|
|
|
|
*{$caller.'::xml_string_ok'} = \&xml_string_ok; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# *{$caller.'::xml_fh_ok'} = \&xml_fh_ok; |
|
20
|
|
|
|
|
|
|
# *{$caller.'::xml_html_file_ok'} = \&xml_html_file_ok; |
|
21
|
|
|
|
|
|
|
# *{$caller.'::xml_html_fh_ok'} = \&xml_html_fh_ok; |
|
22
|
|
|
|
|
|
|
# *{$caller.'::xml_html_string_ok'} = \&xml_html_string_ok; |
|
23
|
|
|
|
|
|
|
# *{$caller.'::xml_sgml_file_ok'} = \&xml_sgml_file_ok; |
|
24
|
|
|
|
|
|
|
# *{$caller.'::xml_sgml_fh_ok'} = \&xml_sgml_fh_ok; |
|
25
|
|
|
|
|
|
|
# *{$caller.'::xml_sgml_string_ok'} = \&xml_sgml_string_ok; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$Test->exported_to($caller); |
|
28
|
|
|
|
|
|
|
$Test->plan(@_); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 NAME |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Test::XML::Valid - Validate XML and XHTML |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
use Test::XML::Valid; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
xml_file_ok($xmlfilename); |
|
41
|
|
|
|
|
|
|
xml_string_ok($xml_string); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Tests for Valid XHTML (using XML::LibXML). If the XML is not valid, a message |
|
46
|
|
|
|
|
|
|
will be generated with specific details about where the parser failed. |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 xml_file_ok( I<$xmlfilename>, I<$msg> ); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Checks that I<$xmlfilename> validates. I<$msg> is optional. |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 xml_string_ok( I<$xmlstring>, I<$msg> ); |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Checks that I<$xml_string> validates. I<$msg> is optional. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 AUTHOR |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Mark Stosberg |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This program is free software; you can redistribute |
|
68
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
The full text of the license can be found in the |
|
71
|
|
|
|
|
|
|
LICENSE file included with this module. |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
perl(1). |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub xml_file_ok { |
|
81
|
|
|
|
|
|
|
my $xmlfilename = shift; |
|
82
|
|
|
|
|
|
|
my $msg = shift || "$xmlfilename is valid XHTML"; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
eval { |
|
85
|
|
|
|
|
|
|
my $parser = XML::LibXML->new; |
|
86
|
|
|
|
|
|
|
$parser->validation(1); |
|
87
|
|
|
|
|
|
|
$parser->parse_file($xmlfilename); |
|
88
|
|
|
|
|
|
|
}; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $ok = !$@; |
|
91
|
|
|
|
|
|
|
$Test->ok($ok,$msg); |
|
92
|
|
|
|
|
|
|
$Test->diag($@) unless $ok; |
|
93
|
|
|
|
|
|
|
return $ok; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub xml_string_ok { |
|
98
|
|
|
|
|
|
|
my $xml_string = shift; |
|
99
|
|
|
|
|
|
|
my $msg = shift || "valid XHTML"; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
eval { |
|
102
|
|
|
|
|
|
|
my $parser = XML::LibXML->new; |
|
103
|
|
|
|
|
|
|
$parser->validation(1); |
|
104
|
|
|
|
|
|
|
$parser->parse_string($xml_string); |
|
105
|
|
|
|
|
|
|
}; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $ok = !$@; |
|
108
|
|
|
|
|
|
|
$Test->ok($ok,$msg); |
|
109
|
|
|
|
|
|
|
$Test->diag($@) unless $ok; |
|
110
|
|
|
|
|
|
|
return $ok; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; #this line is important and will help the module return a true value |
|
116
|
|
|
|
|
|
|
__END__ |