blib/lib/Test/XML/Valid.pm

filter: Statementstmt 100% 46 / 46 Branchbran 50.0% 2 / 4 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 96.9% 64 / 66 CC 5 SCAR 6.9
CC
5
Cov
96%
xml_file_ok
3.0
xml_string_ok
3.0
BEGIN
1.0
CRAP 2.0
↑ Summary
1  
2 package Test::XML::Valid;
3 1 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use vars qw/$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 $VERSION = "0.04";
9  
10 1 my $Test = Test::Builder->new;
11  
12 1 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
13 1 my $self = shift;
14 1 my $caller = caller;
15 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 *{$caller.'::xml_file_ok'} = \&xml_file_ok;
17 1 *{$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 1 $Test->exported_to($caller);
28 1 $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 <mark@summersault.com>
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 2 ▶sub xml_file_ok {
Subroutine xml_file_ok: called CC=3 SCAR=11.0
Pod documented
81 2 my $xmlfilename = shift;
82 2 ▶ my $msg = shift || "$xmlfilename is valid XHTML";
Condition100%2/2
shift() || "$xmlfilename is valid XHTML"
l!l
11
MC/DC100%1/1
shift() || "$xmlfilename is valid XHTML"
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
83  
84 2 eval {
85 2 my $parser = XML::LibXML->new;
86 2 $parser->validation(1);
87 2 $parser->parse_file($xmlfilename);
88 };
89
90 2 my $ok = !$@;
91 2 $Test->ok($ok,$msg);
92 2 ▶ $Test->diag($@) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 2 2
93 2 return $ok;
94 }
95  
96  
97 2 ▶sub xml_string_ok {
Subroutine xml_string_ok: called CC=3 SCAR=11.0
Pod documented
98 2 my $xml_string = shift;
99 2 ▶ my $msg = shift || "valid XHTML";
Condition100%2/2
shift() || 'valid XHTML'
l!l
11
MC/DC100%1/1
shift() || 'valid XHTML'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
100  
101 2 eval {
102 2 my $parser = XML::LibXML->new;
103 2 $parser->validation(1);
104 2 $parser->parse_string($xml_string);
105 };
106
107 2 my $ok = !$@;
108 2 $Test->ok($ok,$msg);
109 2 ▶ $Test->diag($@) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 2 2
110 2 return $ok;
111 }
112  
113  
114  
115 1 1; #this line is important and will help the module return a true value
116 __END__
↑ Summary