/usr/share/perl5/XML/SAX/Machines.pm is in libxml-sax-machines-perl 0.46-1.
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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | package XML::SAX::Machines;
{
$XML::SAX::Machines::VERSION = '0.46';
}
# ABSTRACT: manage collections of SAX processors
use strict;
use Carp;
use Exporter;
use vars qw( $debug @ISA @EXPORT_OK %EXPORT_TAGS );
## TODO: Load this mapping from the config file, or generalize
## this.
my %machines = (
ByRecord => "XML::SAX::ByRecord",
Machine => "XML::SAX::Machine",
Manifold => "XML::SAX::Manifold",
Pipeline => "XML::SAX::Pipeline",
Tap => "XML::SAX::Tap",
);
@ISA = qw( Exporter );
@EXPORT_OK = keys %machines;
%EXPORT_TAGS = ( "all" => \@EXPORT_OK );
## Note: we don't put a constructor function in each package for two reasons.
## The first is that I want to generalize this mechanism in to a
## Class::CtorShortcut. The second, more marginal reason is that the
## easiest way to do that
## would be to make each of the machines be @ISA( Exporter ) and I don't
## want to add to to machines' @ISA lists for speed reasons, since
## below we manually search @ISA hierarchies for config settings.
sub import {
my $self = $_[0];
for ( @_[1..$#_] ) {
for ( substr( $_, 0, 1 ) eq ":" ? @{$EXPORT_TAGS{substr $_, 1}} : $_ ) {
croak "Unknown SAX machine: '$_'" unless exists $machines{$_};
carp "Loading SAX machine '$_'" if $debug;
eval "use $machines{$_}; sub $_ { $machines{$_}->new( \@_ ) }; 1;"
or die $@;
}
}
goto &Exporter::import;
}
sub _read_config {
delete $INC{"XML/SAX/Machines/ConfigDefaults.pm"};
delete $INC{"XML/SAX/Machines/SiteConfig.pm"};
eval "require XML::SAX::Machines::ConfigDefaults;";
eval "require XML::SAX::Machines::SiteConfig;";
my $xsm = "XML::SAX::Machines";
for ( qw(
LegalProcessorClassOptions
ProcessorClassOptions
) ) {
no strict "refs";
## I don't like creating these just to default them, but perls
## 5.005003 and older (at least) emit a "used only once, possible
## type" warngings that local $^W = 0 doesn't silence.
${__PACKAGE__."::ConfigDefaults::$_"} ||= {};
${__PACKAGE__."::SiteConfig::$_"} ||= {};
${__PACKAGE__."::Config::$_"} = {
%{ ${__PACKAGE__."::ConfigDefaults::$_"} },
%{ ${__PACKAGE__."::SiteConfig::$_" } },
};
}
## Now check the config.
my @errors;
for my $class ( keys %$XML::SAX::Machines::Config::ProcessorClassOptions ) {
push(
@errors,
"Illegal ProcessorClassOptions option name in $class: '$_'\n"
) for grep(
! exists $XML::SAX::Machines::Config::LegalProcessorClassOptions->{$_},
keys %{$XML::SAX::Machines::Config::ProcessorClassOptions->{$class}}
) ;
}
die @errors,
" check XML::SAX::Machines::SiteConfig",
" (or perhaps XML::SAX::Machines::ConfigDefaults)\n",
" Legal names are: ",
join(
", ",
map
"'$_'",
keys %$XML::SAX::Machines::Config::LegalProcessorClassOptions
)
if @errors;
}
_read_config;
sub _config_as_string {
require Data::Dumper;
local $Data::Dumper::Indent = 1;
local $Data::Dumper::QuoteKeys = 1;
Data::Dumper->Dump(
[ $XML::SAX::Machines::Config::ProcessorClassOptions ],
[ 'Processors' ]
);
}
## TODO: Move the config file accessors to a Config package.
#=head2 Config File accessors
#
#Right now config files are read only.
#
#=cut
#
#=over
#
#=item processor_class_option
#
# if ( XML::SAX::Machines->processor_class_option
# $class, "ConstructWithHashedOptions"
# ) {
# ....
# }
##
#Sees if an option is set for a processor class or the first class in it's
#ISA hierarchy for which the option is defined. Caches results for speed.
#The cache is cleared if the config file is re-read.
#
#$class may also be an object.
#
#Yes this is a wordy API; it shouldn't be needed too often :).
#
#=cut
#
sub processor_class_option {
my $self = shift;
my ( $class, $option ) = @_;
croak "Can't set processor class options yet"
if @_ > 2;
Carp::cluck
"Unknown ProcessorClassOptions option '$option'.\n",
" Expected options are: ",
join(
", ",
map "'$_'",
sort keys
%$XML::SAX::Machines::Config::ExpectedProcessorClassOptions
),
"\n",
" Perhaps a call to XML::SAX::Machine->expected_processor_class_options( '$option' ) would help?"
unless
$XML::SAX::Machines::Config::ExpectedProcessorClassOptions->{$option};
$class = ref $class || $class;
return $XML::SAX::Machines::Config::ProcessorClassOptions->{$class}->{$option}
if exists $XML::SAX::Machines::Config::ProcessorClassOptions->{$class}
&& exists $XML::SAX::Machines::Config::ProcessorClassOptions->{$class}->{$option}
&& defined $XML::SAX::Machines::Config::ProcessorClassOptions->{$class}->{$option};
## Hmm, gotta traipse through @ISA.
my $isa = do {
no strict "refs";
eval "require $class;" unless @{"${class}::ISA"};
\@{"${class}::ISA"};
};
my $value;
for ( @$isa ) {
next if $_ eq "Exporter" || $_ eq "DynaLoader" ;
$value = $self->processor_class_option( $_, $option );
last if defined $value;
}
return undef unless $value;
## Cache the result.
$XML::SAX::Machines::Config::ProcessorClassOptions->{$class}->{$option}
= $value;
return $value;
}
#=item expected_processor_class_options
#
# XML::SAX::Machine->expected_processor_class_options( MyOption );
#
#This is used to inform XML::SAX::Machines that there's an option your
#module expects to be able to retrieve. It does *not* check the options
#in the config file, it checks options requests so as to catch typoes in
#code.
#
#Yes this is a wordy API; it shouldn't be needed too often :).
#
#=cut
sub expected_processor_class_options {
my $self = shift;
$XML::SAX::Machines::Config::ExpectedProcessorClassOptions->{$_} = 1
for @_;
}
#=back
#
#=cut
1;
__END__
=pod
=head1 NAME
XML::SAX::Machines - manage collections of SAX processors
=head1 VERSION
version 0.46
=head1 SYNOPSIS
use XML::SAX::Machines qw( :all );
my $m = Pipeline(
"My::Filter1", ## My::Filter1 autoloaded in Pipeline()
"My::Filter2", ## My::Filter2 " " "
\*STDOUT, ## XML::SAX::Writer also loaded
);
$m->parse_uri( $uri ); ## A parser is autoloaded via
## XML::SAX::ParserFactory if
## My::Filter1 isn't a parser.
## To import only individual machines:
use XML::SAX::Machines qw( Manifold );
## Here's a multi-pass machine that reads one document, runs
## it through 5 filtering channels (one channel at a time) and
## reassembles it in to a single document.
my $m = Manifold(
"My::TableOfContentsExtractor",
"My::AbstractExtractor",
"My::BodyFitler",
"My::EndNotesFilter",
"My::IndexFilter",
);
$m->parse_string( $doc );
=head1 DESCRIPTION
SAX machines are a way to gather and manage SAX processors without going
nuts. Or at least without going completely nuts. Individual machines
can also be like SAX processors; they don't need to parse or write
anything:
my $w = XML::SAX::Writer->new( Output => \*STDOUT );
my $m = Pipeline( "My::Filter1", "My::Filter2", { Handler => $w } );
my $p = XML::SAX::ParserFactory->new( handler => $p );
More documentation to come; see L<XML::SAX::Pipeline>,
L<XML::SAX::Manifold>, and L<XML::SAX::Machine> for now.
Here are the machines this module knows about:
ByRecord Record oriented processing of documents.
L<XML::SAX::ByRecord>
Machine Generic "directed graph of SAX processors" machines.
L<XML::SAX::Machine>
Manifold Multipass document processing
L<XML::SAX::Manifold>
Pipeline A linear sequence of SAX processors
L<XML::SAX::Pipeline>
Tap An insertable pass through that examines the
events without altering them using SAX processors.
L<XML::SAX::Tap>
=head2 Config file
As mentioned in L</LIMITATIONS>, you might occasionally need to edit the config
file to tell XML::SAX::Machine how to handle a particular SAX processor (SAX
processors use a wide variety of API conventions).
The config file is a the Perl module XML::SAX::Machines::SiteConfig, which
contains a Perl data structure like:
package XML::SAX::Machines::SiteConfig;
$ProcessorClassOptions = {
"XML::Filter::Tee" => {
ConstructWithHashedOptions => 1,
},
};
So far $Processors is the only available configuration structure. It contains
a list of SAX processors with known special needs.
Also, so far the only special need is the ConstructWithHashes option which
tells XML::SAX::Machine to construct such classes like:
XML::Filter::Tee->new(
{ Handler => $h }
);
instead of
XML::Filter::Tee->new( Handler => $h );
B<WARNING> If you modify anything, apply your changes in a new file created
from XML::SAX::Machines::SiteConfig.pm. On Debian systems, this should be placed
in /etc/perl so that it is not overwritten during upgrade. Do not alter
XML::SAX::Machines::ConfigDefaults.pm or you will lose your changes when you
upgrade.
TODO: Allow per-app and per-machine overrides of options. When needed.
=head1 NAME
XML::SAX::Machines - manage collections of SAX processors
=head1 AUTHORS
Barrie Slaymaker
=head1 LICENCE
Copyright 2002-2009 by Barrie Slaymaker.
This software is free. It is licensed under the same terms as Perl itself.
=head1 AUTHORS
=over 4
=item *
Barry Slaymaker
=item *
Chris Prather <chris@prather.org>
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Barry Slaymaker.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|