--- trunk/lib/WebPAC/Lookup.pm 2005/07/24 14:20:59 30 +++ trunk/lib/WebPAC/Lookup.pm 2005/12/06 19:41:17 234 @@ -5,6 +5,7 @@ use base qw/WebPAC::Common WebPAC::Normalize/; use File::Slurp; +use YAML qw/LoadFile/; use Data::Dumper; =head1 NAME @@ -13,11 +14,11 @@ =head1 VERSION -Version 0.01 +Version 0.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; =head1 SYNOPSIS @@ -68,13 +69,18 @@ my $lookup_code = read_file($lookup_file) || $log->logconfess("can't read lookup file $lookup_file: $!"); - { + if ($lookup_file =~ m#\.pm$#) { no strict 'vars'; do $lookup_file or $log->logdie("Failed to read configuration parameters '$lookup_file' $! $@"); $self->{'lookup_def'} = \@lookup || $log->logdie("lookup config $lookup_file doesn't produce \@lookup array"); + } elsif ($lookup_file =~ m#\.(:?yml|yaml)$#) { + my $yaml = LoadFile( $lookup_file ) || $log->logdie("lookup YAML file $lookup_file error: $!"); + $self->{'lookup_def'} = $yaml->{lookup} || $log->logdie("lookup YAML file $lookup_file should begin with 'lookup:'"); + } else { + $log->logide("unsupported lookup file $lookup_file"); } - $log->logconfess("lookup config file isn't ARRAY", sub { Dumper( $self->{'lookup_def'} ) }) if ($self->{'lookup_def'} !~ /ARRAY/o); + $log->logconfess("lookup config file isn't ARRAY but ", sub { Dumper( $self->{'lookup_def'} ) }) if ($self->{'lookup_def'} !~ /ARRAY/o); $self->{'is_lookup_regex'} ||= 'lookup{[^\{\}]+}'; $self->{'save_lookup_regex'} ||= 'lookup{([^\{\}]+)}';