DocKnot/Config.pm

filter: Statementstmt 91.4% 43 / 47 Branchbran 62.5% 5 / 8 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 90.1% 64 / 71 CC 7 SCAR 10.1
CC
7
Cov
88%
config
5.8
new
2.0
global_config
2.0
CRAP 2.8
« DocKnot/Generate.pm ↑ Summary DocKnot/Util.pm »
1 # Read and return DocKnot package configuration.
2 #
3 # Parses the DocKnot package configuration and provides it to other DocKnot
4 # commands.
5 #
6 # SPDX-License-Identifier: MIT
7  
8 ##############################################################################
9 # Modules and declarations
10 ##############################################################################
11  
12 package App::DocKnot::Config v8.0.1;
13  
14 12 ▶use 5.024;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 12 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 12 ▶use parent qw(App::DocKnot);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 12 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 12 ▶use File::BaseDir qw(config_files);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 12 ▶use YAML::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 ##############################################################################
24 # Public Interface
25 ##############################################################################
26  
27 # Create a new App::DocKnot::Config object, which will be used for subsequent
28 # calls.
29 #
30 # $args - Anonymous hash of arguments with the following keys:
31 # metadata - Path to the docknot.yaml file
32 #
33 # Returns: Newly created object
34 21 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
35 21 my ($class, $args_ref) = @_;
36 21 ▶ my $self = { metadata => $args_ref->{metadata} // 'docs/docknot.yaml' };
Condition100%2/2
$args_ref->{"metadata"} // "docs/docknot.yaml"
l!l
156
MC/DC100%1/1
$args_ref->{"metadata"} // "docs/docknot.yaml"
$args_ref->{"metadata"}
Truth table100%2/2
A
A= $args_ref->{"metadata"}
Aresult
11
00
37 21 bless($self, $class);
38 21 return $self;
39 }
40  
41 # Load the DocKnot package configuration.
42 #
43 # Returns: The package configuration as a dict
44 # Throws: YAML::XS exception on invalid package metadata
45 # Text exception on schema mismatch for package metadata
46 # Text exception on inconsistencies in the package data
47 42 ▶sub config {
Subroutine config: called CC=5 SCAR=17.6
Pod documented
48 42 my ($self) = @_;
49  
50 # Load the package metadata.
51 42 my $data_ref = $self->load_yaml_file($self->{metadata}, 'docknot');
52  
53 # build.install defaults to true.
54 42 ▶ if (!exists($data_ref->{build}{install})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $data_ref->{"build"}{"install"}) 27 15 42
55 27 $data_ref->{build}{install} = 1;
56 }
57  
58 # Set a flag indicating whether the testing section was overridden. This
59 # is easier for templates to check.
60 42 for my $section_ref ($data_ref->{readme}{sections}->@*) {
61 0 ▶ if (lc($section_ref->{title}) eq 'testing') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $section_ref->{"title"} eq "testing") 0 0 0
62 0 $data_ref->{readme}{testing} = 1;
63 0 last;
64 }
65 }
66  
67 # Expand the package license into license text.
68 42 my $license = $data_ref->{license}{name};
69 42 my $licenses_path = $self->appdata_path('licenses.yaml');
70 42 my $licenses_ref = YAML::XS::LoadFile($licenses_path);
71 42 ▶ if (!exists($licenses_ref->{$license})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $licenses_ref->{$license}) 0 42 42
72 0 die "unknown license $license\n";
73 }
74 42 $data_ref->{license}{summary} = $licenses_ref->{$license}{summary};
75 42 $data_ref->{license}{text} = $licenses_ref->{$license}{text};
76  
77 # Return the resulting configuration.
78 42 return $data_ref;
79 }
80  
81 # Load the DocKnot global configuration.
82 #
83 # Returns: The global configuration as a dict
84 # Throws: YAML::XS exception on invalid configuration file
85 # Text exception on schema mismatch for the configuration file
86 8 ▶sub global_config {
Subroutine global_config: called CC=2 SCAR=6.9
Pod documented
87 8 my ($self) = @_;
88  
89 # Load the global configuration file and return an empty hash if no config
90 # exists.
91 8 my $config_path = config_files('docknot', 'config.yaml');
92 8 ▶ if (!defined($config_path)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $config_path) 6 2 8
93 6 return {};
94 }
95 2 my $data_ref = $self->load_yaml_file($config_path, 'config');
96  
97 # Return the resulting configuration.
98 2 return $data_ref;
99 }
100  
101 ##############################################################################
102 # Module return value and documentation
103 ##############################################################################
104  
105 12 1;
106 __END__
« DocKnot/Generate.pm ↑ Summary DocKnot/Util.pm »