####################################################################
# And package methods #
####################################################################
####################################################################
# new #
####################################################################
=pod
=over 4
=item B<new>(I<$inputline>, I<$lang>);
Construct a new parser from the pipe-separated line at input
=cut
sub new {
my ($class,$inputline,$lang)=@_;
my $self={};
#
# The hash $self->{fields} is the main stored data structure.
# The key is the field, the value is the number of the field
# in the input lines.
#
my %fieldnames=%{$lang->GetFieldNames()};
chomp $inputline;
$inputline =~ s/^\s+//;
$inputline =~ s/\s+$//;
my @input = split /\s*\|\s*/, $inputline;
for (my $i=0; $i<scalar @input; $i++) {
my $name=$input[$i];
if (exists $fieldnames{$name}) {
my $field=$fieldnames{$name};
$self->{fields}->{$field}=$i;
} else {
print STDERR "Warning: unknown field $name\n";
}
}
if ($main::DEBUG) {
print STDERR "Field names:\n";
foreach my $key (keys %fieldnames) {
my $field=$fieldnames{$key};
my $pos=$self->{fields}->{$field};
print STDERR "\t$key\t$field\t$pos\n";
}
}
#
# The hash $self->{values} contains values for fields
# with closed sets of values.
#
my %values=%{$lang->GetValues()};
$self->{values}=\%values;
if ($main::DEBUG) {
print STDERR "Field values:\n";
foreach my $key (keys %values) {
my $value=$values{$key};
print STDERR "\t$key\t$value\n";
}
}
#
# The hash $self->{special_names} contains special values
# for the 'Name' field
#
my %special=%{$lang->GetSpecialNames()};
$self->{'special_names'}=\%special;
if ($main::DEBUG) {
print STDERR "Special names:\n";
foreach my $key (keys %special) {
my $value=$special{$key};
print STDERR "\t$key\t$value\n";
}
}
if ($main::DEBUG) {
print STDERR "Special fields:\n";
foreach my $key (keys %fields_to_convert) {
my $value=$fields_to_convert{$key};
print STDERR "\t$key\t$value\n";
}
}