#!/usr/bin/perl -w use lib '.'; use strict; use SWIG qw(remove_method skip_to_closing_brace fix_method); use File::Temp qw/tempfile/; use File::Copy; my $INFILE = "Xerces-tmp.pm"; my $OUTFILE = "Xerces.pm"; open(FILE, $INFILE) or die "Couldn't open $INFILE for reading"; my ($temp_fh, $temp_filename) = tempfile(); # # Put the apache license in the output file # my $LICENSE = <) { if (/^package/) { if (m/package\s+XML::Xerces::(\w+);/) { ($CURR_CLASS) = $1; } print $temp_fh $_; next; } # # for some reason (I don't want to figure out) SWIG puts a bunch of # # methods directly in the XML::Xerces namespace that don't belong there # # and are duplicated within their proper classes, so we delete them # if (/FUNCTION WRAPPERS/) { # while ($_ = ) { # next unless /\#\#\#\#\#\#\#\#\#\#\#\#\#/; # last; # } # } # # # we remove all the enums inherited through DOMNode # next if /^\*[_A-Z]+_NODE =/ && !/DOMNode/; # # # now we set these aliases correctly # s/\*XML::Xerces::/*XML::Xercesc::/; ####################################################################### # # MUNGE MODULE for XMLCh support # # CHANGE "$args[0] = tied(%{$args[0]})" # TO "$args[0] = tied(%{$args[0]}) || $args[0]" # then we wrap it in a defined $args[0] to remove the irritating warning # if (m{\$args\[0\]\s+=\s+tied\(\%\{\$args\[0\]\}\)}) { # print $temp_fh <<'EOT'; # if (defined $args[0]) { # $args[0] = tied(%{$args[0]}) || $args[0]; # } # EOT # next; # } # CHANGE "return undef if (!defined($result))" # TO "return $result unless ref($result) =~ m[XML::Xerces]" # split on multiple lines to be readable, using s{}{}x # s{ # return\s*undef\s*if\s*\(\!defined\(\$result\)\) # }{return \$result unless UNIVERSAL::isa(\$result,'XML::Xerces')}x; print $temp_fh $_; } close(FILE); close($temp_fh); copy($temp_filename, $OUTFILE); END {unlink($temp_filename)}