0
  0   ˆl–ßi~”Jn-j}@7pA¸È”Å£¿„e°¶/_‹uÐb&=LV[(ÃÂ ?÷     package XML::Parser::Expat;

use strict;

#use warnings; No warnings numeric??

use XSLoader;
use Carp;

our $VERSION = '2.46';

our ( %Encoding_Table, @Encoding_Path, $have_File_Spec );

use File::Spec ();

%Encoding_Table = ();
if ($have_File_Spec) {
    @Encoding_Path = (
        grep( -d $_,
            map( File::Spec->catdir( $_, qw(XML Parser Encodings) ),
                @INC ) ),
        File::Spec->curdir
    );
}
else {
    @Encoding_Path = ( grep( -d $_, map( $_ . '/XML/Parser/Encodings', @INC ) ), '.' );
}

XSLoader::load( 'XML::Parser::Expat', $VERSION );

our %Handler_Setters = (
    Start        => \&SetStartElementHandler,
    End          => \&SetEndElementHandler,
    Char         => \&SetCharacterDataHandler,
    Proc         => \&SetProcessingInstructionHandler,
    Comment      => \&SetCommentHandler,
    CdataStart   => \&SetStartCdataHandler,
    CdataEnd     => \&SetEndCdataHandler,
    Default      => \&SetDefaultHandler,
    Unparsed     => \&SetUnparsedEntityDeclHandler,
    Notation     => \&SetNotationDeclHandler,
    ExternEnt    => \&SetExternalEntityRefHandler,
    ExternEntFin => \&SetExtEntFinishHandler,
    Entity       => \&SetEntityDeclHandler,
    Element      => \&SetElementDeclHandler,
    Attlist      => \&SetAttListDeclHandler,
    Doctype      => \&SetDoctypeHandler,
    DoctypeFin   => \&SetEndDoctypeHandler,
    XMLDecl      => \&SetXMLDeclHandler
);

sub new {
    my ( $class, %args ) = @_;
    my $self = bless \%args, $_[0];
    $args{_State_} = 0;
    $args{Context} = [];
    $args{Namespaces}   ||= 0;
    $args{ErrorMessage} ||= '';
    if ( $args{Namespaces} ) {
        $args{Namespace_Table} = {};
        $args{Namespace_List}  = [undef];
        $args{Prefix_Table}    = {};
        $args{New_Prefixes}    = [];
    }
    $args{_Setters} = \%Handler_Setters;
    $args{Parser}   = ParserCreate(
        $self, $args{ProtocolEncoding},
        $args{Namespaces}
    );
    $self;
}

sub load_encoding {
    my ($file) = @_;

    $file =~ s!([^/]+)$!\L$1\E!;
    $file .= '.enc' unless $file =~ /\.enc$/;
    unless ( $file =~ m!^/! ) {
        foreach (@Encoding_Path) {
            my $tmp = (
                $have_File_Spec
                ? File::Spec->catfile( $_, $file )
                : "$_/$file"
            );
            if ( -e $tmp ) {
                $file = $tmp;
                last;
            }
        }
    }

    open( my $fh, '<', $file ) or croak("Couldn't open encmap $file:\n$!\n");
    binmode($fh);
    my $data;
    my $br = sysread( $fh, $data, -s $file );
    croak("Trouble reading $file:\n$!\n")
      unless defined($br);
    close($fh);

    my $name = LoadEncoding( $data, $br );
    croak("$file isn't an encmap file")
      unless defined($name);

    $name;
}    # End load_encoding

sub setHandlers {
    my ( $self, @handler_pairs ) = @_;

    croak("Uneven number of arguments to setHandlers method")
      if ( int(@handler_pairs) & 1 );

    my @ret;

    while (@handler_pairs) {
        my $type    = shift @handler_pairs;
        my $handler = shift @handler_pairs;
        croak 'Handler for $type not a Code ref'
          unless ( !defined($handler) or !$handler or ref($handler) eq 'CODE' );

        my $hndl = $self->{_Setters}->{$type};

        unless ( defined($hndl) ) {
            my @types = sort keys %{ $self->{_Setters} };
            croak("Unknown Expat handler type: $type\n Valid types: @types");
        }

        my $old = &$hndl( $self->{Parser}, $handler );
        push( @ret, $type, $old );
    }

    return @ret;
}

sub xpcroak {
    my ( $self, $message ) = @_;

    my $eclines = $self->{ErrorContext};
    my $line    = GetCurrentLineNumber( $_[0]->{Parser} );
    $message .= " at line $line";
    $message .= ":\n" . $self->position_in_context($eclines)
      if defined($eclines);
    croak $message;
}

sub xpcarp {
    my ( $self, $message ) = @_;

    my $eclines = $self->{ErrorContext};
    my $line    = GetCurrentLineNumber( $_[0]->{Parser} );
    $message