package Zen::Config::Interpreter; use strict; use base qw/II720d6e18aa34327713eb014408fc9144/; use Zen::Config::Hash; sub new { shift()->SUPER::new(); } sub interpret { my ($this, $file, $mainsec) = @_; return unless -f $file; my $fh; open $fh, $file or die "failed to open file [$file]: $!"; my $h = Zen::Config::Hash->create; my $sec_n = $mainsec || 'main'; my $sec_h = Zen::Config::Hash->create; my ($key, $val, $str); while (my $line = <$fh>) { $line =~ s/[\r\n]//g; if ($line =~ /^#include\s+/i) { die "include directive is not allowed in interpreter mode\n"; } elsif ($line =~ /^[#;]/) { } elsif ($line =~ /^\[(.+?)\]/) { $h->{$sec_n} = $sec_h; $sec_n = $1; $sec_h = Zen::Config::Hash->create; } elsif (($key, $val) = $line =~ /^([^=]*?)=(.*)$/) { if ($val =~ /^\s*<<(\w+)/) { my $ender = $1; $val = ''; while (my $subline = <$fh>) { last if $subline =~ /^$ender/; $val .= $subline; } } $sec_h->{$key} = $val; } } $h->{$sec_n} = $sec_h; close $fh; $h; } 1; 