This file is indexed.

/usr/share/perl5/Test/XML/SAX.pm is in libtest-xml-perl 0.08-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package Test::XML::SAX;
# @(#) $Id$

use strict;
use warnings;

use Carp;
use Test::More;
use Test::XML;
use Test::Builder;
use XML::SAX;
use XML::SAX::ParserFactory;
use XML::SAX::Writer;

our $VERSION = '0.01';

sub import {
    my $self   = shift;
    my $caller = caller;

    no strict 'refs';
    *{ $caller . '::test_sax' }             = \&test_sax;
    *{ $caller . '::test_all_sax_parsers' } = \&test_all_sax_parsers;

    my $Test = Test::Builder->new;
    $Test->exported_to( $caller );
    $Test->plan( @_ );
}

sub test_sax {
    my ( $handler, $input, $expected, $test_name ) = @_;
    croak "usage: test_sax(handler,input,expected,[test_name])"
        unless $handler && ref $handler && $input && $expected;

    my $Test = Test::Builder->new;
    my $result = '';
    eval {
        my $w = XML::SAX::Writer->new( Output => \$result );
        $handler->set_handler( $w );
        my $p = XML::SAX::ParserFactory->parser( Handler => $handler );
        $p->parse_string( $input );
    };
    if ( $@ ) {
        $Test->ok( 0, $test_name );
        $Test->diag( "Error during parse: $@" );
    }

    return is_xml( $result, $expected, $test_name );
}

sub test_all_sax_parsers {
    my ( $sub, $numtests ) = @_;
    croak "usage: test_all_sax_parsers(sub,[numtests])"
        unless $sub && ref($sub) eq 'CODE';

    my @parsers = map { $_->{Name} } @{ XML::SAX->parsers };
    plan tests => ($numtests * scalar( @parsers ) )
        if $numtests;

    # NB: Have to sort by shortest parser first so that
    # XML::SAX::ParserFactory
    # loads them all in correctly.
    foreach my $parser ( sort { length $a <=> length $b } @parsers ) {
        local $XML::SAX::ParserPackage = $parser;
        $sub->( $parser, $numtests );
    }
}

1;
__END__

=head1 NAME

Test::XML::SAX - Test XML::SAX handlers

=head1 SYNOPSIS

  use Test::XML::SAX tests => 1;
  use My::XML::Filter;

  my $handler = My::XML::Filter->new;
  test_sax( $handler, '<foo />', '<bar/>', 'translates foo to bar' );

  # ... In Another File ...

  use Test::XML::SAX; use My::XML::Filter;
  
  sub do_tests {
      my $handler = My::XML::Filter->new;
      test_sax( $handler, '<foo />', '<bar/>', 'translates foo to bar' );
  }

  test_all_sax_parsers( \&do_tests, 1 );

=head1 DESCRIPTION

This module is for testing XML::SAX handlers.

=head1 FUNCTIONS

All functions are exported.

=over 4

=item test_sax ( HANDLER, INPUT, EXPECTED [, TESTNAME ] )

This function will process INPUT using HANDLER, and compare the result
with EXPECTED.  TESTNAME can optionally be used to name the test in the
output (a good idea).

=item test_all_sax_parsers ( SUB [, NUMTESTS ] )

This function will repeat a set of tests for all installed SAX parsers.
SUB must be a coderef to run a series of tests.  NUMTESTS is the number
of tests inside SUB.

B<NB>: You must not issue a plan to Test::More if you call this
function!  The plan will be set for you, according to the number of
parsers installed and NUMTESTS.  This also means that you must not have
any tests outside of SUB or you will get an error.

When SUB is called, it will be passed two arguments.  The name of the
parser being used and the number of tests.  It can use this information
to decide whether or not to skip this set of tests.

=back

=head1 SEE ALSO

L<Test::More>, L<Test::XML>, L<XML::SAX>.

=head1 AUTHOR

Dominic Mitchell, E<lt>cpan2 (at) semantico.comE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright 2002 by semantico

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself. 

=cut

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# indent-tabs-mode: nil
# End:
# vim: set ai et sw=4 :