App-Context

 view release on metacpan or  search on metacpan

lib/App/Conf/File.pm  view on Meta::CPAN

                }
                elsif ($conf_type eq "xml") {
                    $serializer_class = "App::Serializer::Xml";
                }
                elsif ($conf_type eq "ini") {
                    $serializer_class = "App::Serializer::Ini";
                }
                elsif ($conf_type eq "properties") {
                    $serializer_class = "App::Serializer::Properties";
                }
                elsif ($conf_type eq "conf") {
                    $serializer_class = "App::Serializer::Properties";
                }
                elsif ($conf_type eq "yaml") {
                    $serializer_class = "App::Serializer::Yaml";
                }
                elsif ($conf_type) {
                    my $serializer = ucfirst($conf_type);
                    $serializer_class = "App::Serializer::$serializer";
                }
                else {
                    $serializer_class = "App::Serializer";
                }
            }

            if ($serializer_class) {
                eval "use $serializer_class;";
                if ($@) {
                    App::Exception::Conf->throw(
                        error => "create(): error loading $serializer_class serializer class: $@\n"
                    );
                }
                $conf = $serializer_class->deserialize($text);
                if (! %$conf) {
                    App::Exception::Conf->throw(
                        error => "create(): $serializer_class produced empty config\n"
                    );
                }
            }
            else { # don't bother with a serializer
                $conf = {};
                if ($text =~ /^[ \t\n]*\$[a-zA-Z][a-zA-Z0-9_]* *= *(\{.*\};[ \n]*)$/s) {
                    $text = "\$conf = $1";   # untainted now
                    eval($text);
                    if ($@) {
                        App::Exception::Conf->throw(
                            error => "create(): [$conf_file] error eval'ing config text: $@\n"
                        );
                    }
                }
                else {
                    App::Exception::Conf->throw(
                        error => "create(): [$conf_file] config text doesn't match '\$var = {...};'\n"
                    );
                }
            }
        }
    }
    
    if ($options->{conf} && ref($options->{conf}) eq "HASH") {
        App::Reference->overlay($conf, $options->{conf});
    }

    $conf;
}

1;



( run in 1.994 second using v1.01-cache-2.11-cpan-39bf76dae61 )