/usr/share/perl5/Lire/Config/SpecParser.pm is in lire 2:2.1.1-2.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 | package Lire::Config::SpecParser;
use strict;
use Lire::Config::TypeSpec;
use Lire::Utils qw/ check_param /;
use Lire::Error qw/directory_not_readable/;
use base qw/Lire::DocBookParser Lire::Config::Parser/;
use Carp;
=pod
=head1 NAME
Lire::Config::SpecParser - Create configuration specification from XML files
=head1 SYNOPSIS
use Lire::Config::SpecParser;
my $parser = new Lire::Config::SpecParser;
my $spec = $parser->parsefile( 'spec.xml' );
$parser->merge_specifications_dir( '/etc/lire/config' );
my $spec = $parser->configspec();
=head1 DESCRIPTION
This is an Lire::XMLParser which can build Lire::Config::ConfigSpec
objects from an XML file.
=cut
sub namespaces {
my $self = $_[0];
return { %{$self->Lire::Config::Parser::namespaces()},
'http://www.logreport.org/LRCSML/' => 'lrcsml'
};
}
my %elements2class =
( 'lrcsml:boolean' => 'Lire::Config::BooleanSpec',
'lrcsml:command' => 'Lire::Config::CommandSpec',
'lrcsml:dlf-converter' => 'Lire::Config::DlfConverterSpec',
'lrcsml:dlf-schema' => 'Lire::Config::DlfSchemaSpec',
'lrcsml:dlf-streams' => 'Lire::Config::DlfStreamsSpec',
'lrcsml:directory' => 'Lire::Config::DirectorySpec',
'lrcsml:executable' => 'Lire::Config::ExecutableSpec',
'lrcsml:file' => 'Lire::Config::FileSpec',
'lrcsml:integer' => 'Lire::Config::IntegerSpec',
'lrcsml:list' => 'Lire::Config::ListSpec',
'lrcsml:object' => 'Lire::Config::ObjectSpec',
'lrcsml:option' => 'Lire::Config::OptionSpec',
'lrcsml:output-format' => 'Lire::Config::OutputFormatSpec',
'lrcsml:plugin' => 'Lire::Config::PluginSpec',
'lrcsml:record' => 'Lire::Config::RecordSpec',
'lrcsml:reference' => 'Lire::Config::ReferenceSpec',
'lrcsml:report-config' => 'Lire::Config::ReportSpec',
'lrcsml:select' => 'Lire::Config::SelectSpec',
'lrcsml:string' => 'Lire::Config::StringSpec',
);
my @scalar_mix = qw/ lrcsml:boolean lrcsml:command lrcsml:directory
lrcsml:dlf-converter lrcsml:dlf-schema lrcsml:dlf-streams
lrcsml:executable lrcsml:output-format
lrcsml:report-config lrcsml:reference
lrcsml:file lrcsml:integer lrcsml:string /;
my @compound_mix = qw/ lrcsml:list lrcsml:record lrcsml:object /;
my @specs_mix = ( qw/ lrcsml:select lrcsml:plugin/, @scalar_mix,
@compound_mix ),
my @infos_mix = qw/lrcsml:summary lrcsml:description/;
my %spec =
(
'lrcsml:config-spec' => [ @specs_mix ],
'lrcsml:summary' => { 'start' => 'collector_start',
'char' => 'collector_char',
'end' => 'summary_end',
'content' => [ 'PCDATA' ], },
'lrcsml:description' => { 'start' => 'dbk_init',
'char' => 'dbk_element_char',
'end' => 'description_end',
'content' => [ @Lire::DocBookParser::top_levels ],
},
'lrcsml:select' => { 'start' => 'spec_start',
'end' => 'spec_end',
'content' => [ @infos_mix, 'lrcsml:option',
'lrcml:param' ] },
'lrcsml:plugin' => { 'start' => 'spec_start',
'end' => 'spec_end',
'content' => [ @infos_mix, 'lrcsml:option',
'lrcml:param' ] },
'lrcsml:option' => { 'start' => 'spec_start',
'end' => 'spec_end',
'content' => [ @infos_mix ] },
);
foreach my $name ( @scalar_mix ) {
$spec{$name} = { 'start' => 'spec_start',
'end' => 'spec_end',
'content' => [ @infos_mix, 'lrcml:param' ] };
}
foreach my $name ( @compound_mix ) {
$spec{$name} = { 'start' => 'spec_start',
'end' => 'spec_end',
'content' => [ @infos_mix, @specs_mix, 'lrcml:param' ] };
}
sub elements_spec {
my $self = $_[0];
return {
%{$self->Lire::Config::Parser::elements_spec()},
%{$self->Lire::DocBookParser::elements_spec()},
%spec,
};
}
=pod
=head2 new()
Creates a new parser object.
=cut
sub new {
my $self = shift->SUPER::new( @_ );
$self->{'_spec'} = new Lire::Config::ConfigSpec();
return $self;
}
=pod
=head2 configspec()
Returns the Lire::Config::ConfigSpec object parsed.
=cut
sub configspec {
return $_[0]->{'_spec'};
}
=pod
=head2 merge_specifications_dir( $dir )
Parses all the files ending in '.xml' in the $directory. The types
defined in these files will be merged to the ConfigSpec object of this
parser.
=cut
sub merge_specifications_dir {
my ( $self, $dir ) = @_;
check_param( $dir, 'dir' );
opendir(my $dh, $dir)
or die directory_not_readable( $dir ), "\n";
foreach my $file (readdir($dh)) {
next unless $file =~ /\.xml$/;
$self->merge_specification("$dir/$file");
}
close($dh);
return;
}
=pod
=head2 merge_specification_dir( $file )
Parses the $file XML file and merges the types it defines in the
ConfigSpec defined by this parser.
=cut
sub merge_specification {
my ( $self, $file ) = @_;
check_param( $file, 'file' );
eval { $self->parsefile( $file ) };
croak "error while parsing XML Config spec $file: $@"
if $@;
return;
}
sub parse_start {
my $self = $_[0];
$self->init_stack( 'config_spec' );
$self->init_stack( 'config_value' );
return;
}
sub parse_end {
my $self = $_[0];
return $self->{'_spec'};
}
sub ignorable_ws {
my $self = $_[0];
$self->SUPER::dbk_element_char()
if $self->within_element( 'lrcsml:description' );
return;
}
sub config_spec_start {
my ( $self, $name, $attributes ) = @_;
$self->stack_push( 'config_spec', $self->{'_spec'} );
return;
}
sub spec_start {
my ( $self, $name, $attributes ) = @_;
$self->error( "No Lire::Config:: class defined for element '$name'" )
unless exists $elements2class{$name};
my $spec = eval {
no strict 'refs';
$elements2class{$name}->new( %$attributes );
};
$self->error( $@ ) if $@;
my $parent = $self->stack_peek( 'config_spec' );
$parent->add( $spec )
if defined $parent;
$self->stack_push( 'config_spec', $spec );
return;
}
sub spec_end {
my ( $self, $name ) = @_;
$self->stack_pop( 'config_spec' );
return;
}
sub current_param_spec {
my ( $self, $name ) = @_;
my $spec = $self->stack_peek( 'config_spec' );
return $spec->name() eq $name ? $spec : $spec->get( $name );
}
sub summary_end {
my ( $self, $name ) = @_;
my $spec = $self->stack_peek( 'config_spec' );
$spec->summary( $self->get_collector( 'lrcsml:summary' ) );
return;
}
sub description_end {
my ( $self, $name ) = @_;
my $spec = $self->stack_peek( 'config_spec' );
$spec->description( $self->dbk_string() );
return;
}
sub param_end {
my $self = $_[0];
my $spec = $self->stack_peek( 'config_spec' );
my $value = $self->stack_peek( 'config_value' );
$spec->default( $value )
if $self->stack_depth( 'config_value' ) == 1;
$self->SUPER::param_end();
return;
}
# keep perl happy
1;
__END__
=pod
=head1 SEE ALSO
Lire::Config::Parser(3pm), Lire::Config::TypeSpec(3pm),
Lire::Config::ConfigSpec(3pm)
=head1 AUTHORS
Wessel Dankers <wsl@logreport.org>
Francis J. Lacoste <flacoste@logreport.org>
=head1 VERSION
$Id: SpecParser.pm,v 1.44 2006/07/23 13:16:30 vanbaal Exp $
=head1 COPYRIGHT
Copyright (C) 2002,2004 Stichting LogReport Foundation LogReport@LogReport.org
This file is part of Lire.
Lire is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program (see COPYING); if not, check with
http://www.gnu.org/copyleft/gpl.html.
=cut
|