diff options
author | Russ Allbery <rra@cpan.org> | 2021-12-25 17:14:57 -0800 |
---|---|---|
committer | Russ Allbery <rra@cpan.org> | 2021-12-25 17:14:57 -0800 |
commit | fd9d6faec1031d82b79897b3b34522ff8a7b5823 (patch) | |
tree | 265b370977da6e400a9fe573736e5ba6f005c50f /lib/App/DocKnot/Config.pm | |
parent | 969f989f3ddd917bde20a45f860dae40e1fe5990 (diff) | |
parent | d49f4587924e350998178e517b800b7268fa6345 (diff) |
Update upstream source from tag 'upstream/6.00'
Update to upstream version '6.00'
with Debian dir efcd266393ed20522604d3cb0ad24be3e03322ec
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; |