diff options
Diffstat (limited to 'lib/App/DocKnot/Config.pm')
-rw-r--r-- | lib/App/DocKnot/Config.pm | 47 |
1 files changed, 6 insertions, 41 deletions
diff --git a/lib/App/DocKnot/Config.pm b/lib/App/DocKnot/Config.pm index f67b489..2eebe32 100644 --- a/lib/App/DocKnot/Config.pm +++ b/lib/App/DocKnot/Config.pm @@ -9,7 +9,7 @@ # Modules and declarations ############################################################################## -package App::DocKnot::Config 5.00; +package App::DocKnot::Config 6.00; use 5.024; use autodie; @@ -18,44 +18,9 @@ use warnings; use Carp qw(croak); use File::BaseDir qw(config_files); -use Kwalify qw(validate); use YAML::XS (); ############################################################################## -# Helper methods -############################################################################## - -# Load a YAML file with schema checking. -# -# $path - Path to the YAML file to load -# $schema - Name of the schema file against which to check it -# -# Returns: Contents of the file as a hash -# Throws: YAML::XS exception on invalid file -# Text exception on schema mismatch -sub _load_yaml_file { - my ($self, $path, $schema) = @_; - - # Tell YAML::XS to use real booleans. Otherwise, Kwalify is unhappy with - # data elements set to false. - local $YAML::XS::Boolean = 'JSON::PP'; - - # Load the metadata and check it against the schema. - my $data_ref = YAML::XS::LoadFile($path); - my $schema_path = $self->appdata_path('schema', $schema); - my $schema_ref = YAML::XS::LoadFile($schema_path); - eval { validate($schema_ref, $data_ref) }; - if ($@) { - my $errors = $@; - chomp($errors); - die "schema validation for $path failed:\n$errors\n"; - } - - # Return the verified contents. - return $data_ref; -} - -############################################################################## # Public Interface ############################################################################## @@ -92,7 +57,7 @@ sub config { my ($self) = @_; # Load the package metadata. - my $data_ref = $self->_load_yaml_file($self->{metadata}, 'docknot.yaml'); + my $data_ref = $self->load_yaml_file($self->{metadata}, 'docknot'); # build.install defaults to true. if (!exists($data_ref->{build}{install})) { @@ -109,14 +74,14 @@ sub config { } # Expand the package license into license text. - my $license = $data_ref->{license}{name}; + my $license = $data_ref->{license}{name}; my $licenses_path = $self->appdata_path('licenses.yaml'); - my $licenses_ref = YAML::XS::LoadFile($licenses_path); + my $licenses_ref = YAML::XS::LoadFile($licenses_path); if (!exists($licenses_ref->{$license})) { die "unknown license $license\n"; } $data_ref->{license}{summary} = $licenses_ref->{$license}{summary}; - $data_ref->{license}{text} = $licenses_ref->{$license}{text}; + $data_ref->{license}{text} = $licenses_ref->{$license}{text}; # Return the resulting configuration. return $data_ref; @@ -136,7 +101,7 @@ sub global_config { if (!defined($config_path)) { return {}; } - my $data_ref = $self->_load_yaml_file($config_path, 'config.yaml'); + my $data_ref = $self->load_yaml_file($config_path, 'config'); # Return the resulting configuration. return $data_ref; |