| 1 | # Update package configuration for a DocKnot version upgrade. | ||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||
| 3 | # Adjusts the DocKnot configuration data for changes in format for newer | ||||||||||||||||||||||
| 4 | # versions of DocKnot. | ||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||
| 6 | # SPDX-License-Identifier: MIT | ||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | ############################################################################## | ||||||||||||||||||||||
| 9 | # Modules and declarations | ||||||||||||||||||||||
| 10 | ############################################################################## | ||||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | package App::DocKnot::Update v8.0.1; | ||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | 3 | ▶ | use 5.024; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 15 | 3 | ▶ | use autodie; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 16 | 3 | ▶ | use parent qw(App::DocKnot); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 17 | 3 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | 3 | ▶ | use Carp qw(croak); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 20 | 3 | ▶ | use JSON::MaybeXS qw(JSON); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 21 | 3 | ▶ | use Kwalify qw(validate); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 22 | 3 | ▶ | use Path::Iterator::Rule; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 23 | 3 | ▶ | use Path::Tiny qw(path); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 24 | 3 | ▶ | use YAML::XS (); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | # The older JSON metadata format stored text snippets in separate files in the | ||||||||||||||||||||||
| 27 | # file system. This is the list of additional files to load from the metadata | ||||||||||||||||||||||
| 28 | # directory if they exist. The contents of these files will be added to the | ||||||||||||||||||||||
| 29 | # configuration in a key of the same name. If the key contains a slash, like | ||||||||||||||||||||||
| 30 | # foo/bar, it will be stored as a nested hash, as $data{foo}{bar}. | ||||||||||||||||||||||
| 31 | 3 | our @JSON_METADATA_FILES = qw( | |||||||||||||||||||||
| 32 | bootstrap | ||||||||||||||||||||||
| 33 | build/middle | ||||||||||||||||||||||
| 34 | build/suffix | ||||||||||||||||||||||
| 35 | debian/summary | ||||||||||||||||||||||
| 36 | packaging/extra | ||||||||||||||||||||||
| 37 | support/extra | ||||||||||||||||||||||
| 38 | test/prefix | ||||||||||||||||||||||
| 39 | test/suffix | ||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | ############################################################################## | ||||||||||||||||||||||
| 43 | # JSON helper methods | ||||||||||||||||||||||
| 44 | ############################################################################## | ||||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | # Internal helper routine to return the path of a file or directory from the | ||||||||||||||||||||||
| 47 | # package metadata directory. The resulting file or directory path is not | ||||||||||||||||||||||
| 48 | # checked for existence. | ||||||||||||||||||||||
| 49 | # | ||||||||||||||||||||||
| 50 | # @path - The relative path of the file as a list of components | ||||||||||||||||||||||
| 51 | # | ||||||||||||||||||||||
| 52 | # Returns: Path::Tiny for the metadata file | ||||||||||||||||||||||
| 53 | 112 | ▶ | sub _metadata_path { | ||||||||||||||||||||
|
Subroutine
_metadata_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 54 | 112 | my ($self, @path) = @_; | |||||||||||||||||||||
| 55 | 112 | return path($self->{metadata}, @path); | |||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | # Internal helper routine to read a file from the package metadata directory | ||||||||||||||||||||||
| 59 | # and return the contents. The file is specified as a list of path | ||||||||||||||||||||||
| 60 | # components. | ||||||||||||||||||||||
| 61 | # | ||||||||||||||||||||||
| 62 | # @path - The path of the file to load, as a list of components | ||||||||||||||||||||||
| 63 | # | ||||||||||||||||||||||
| 64 | # Returns: The contents of the file as a string | ||||||||||||||||||||||
| 65 | # Throws: slurp exception on failure to read the file | ||||||||||||||||||||||
| 66 | 112 | ▶ | sub _load_metadata { | ||||||||||||||||||||
|
Subroutine
_load_metadata: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 67 | 112 | my ($self, @path) = @_; | |||||||||||||||||||||
| 68 | 112 | my $path = $self->_metadata_path(@path); | |||||||||||||||||||||
| 69 | 112 | return $path->slurp_utf8(); | |||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | # Like _load_metadata, but interprets the contents of the metadata file as | ||||||||||||||||||||||
| 73 | # JSON and decodes it, returning the resulting object. This uses the relaxed | ||||||||||||||||||||||
| 74 | # parsing mode, so comments and commas after data elements are supported. | ||||||||||||||||||||||
| 75 | # | ||||||||||||||||||||||
| 76 | # @path - The path of the file to load, as a list of components | ||||||||||||||||||||||
| 77 | # | ||||||||||||||||||||||
| 78 | # Returns: Anonymous hash or array resulting from decoding the JSON object | ||||||||||||||||||||||
| 79 | # Throws: slurp or JSON exception on failure to load or decode the object | ||||||||||||||||||||||
| 80 | 7 | ▶ | sub _load_metadata_json { | ||||||||||||||||||||
|
Subroutine
_load_metadata_json: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 81 | 7 | my ($self, @path) = @_; | |||||||||||||||||||||
| 82 | 7 | my $data = $self->_load_metadata(@path); | |||||||||||||||||||||
| 83 | 7 | my $json = JSON->new; | |||||||||||||||||||||
| 84 | 7 | $json->relaxed; | |||||||||||||||||||||
| 85 | 7 | return $json->decode($data); | |||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | # Load the legacy JSON DocKnot package configuration. | ||||||||||||||||||||||
| 89 | # | ||||||||||||||||||||||
| 90 | # Returns: The package configuration as a dict | ||||||||||||||||||||||
| 91 | # Throws: autodie exception on failure to read metadata | ||||||||||||||||||||||
| 92 | # Text exception on inconsistencies in the package data | ||||||||||||||||||||||
| 93 | 7 | ▶ | sub _config_from_json { | ||||||||||||||||||||
|
Subroutine
_config_from_json: called CC=7 SCAR=19.5
| |||||||||||||||||||||||
| 94 | 7 | my ($self) = @_; | |||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | # Localize $@ since we catch and ignore a lot of exceptions and don't want | ||||||||||||||||||||||
| 97 | # to leak changes to $@ to the caller. | ||||||||||||||||||||||
| 98 | 7 | local $@ = q{}; | |||||||||||||||||||||
| 99 | |||||||||||||||||||||||
| 100 | # Load the package metadata from JSON. | ||||||||||||||||||||||
| 101 | 7 | my $data_ref = $self->_load_metadata_json('metadata.json'); | |||||||||||||||||||||
| 102 | |||||||||||||||||||||||
| 103 | # Load supplemental README sections. readme.sections will contain a list | ||||||||||||||||||||||
| 104 | # of sections to add to the README file. | ||||||||||||||||||||||
| 105 | 7 | for my $section_ref ($data_ref->{readme}{sections}->@*) { | |||||||||||||||||||||
| 106 | 15 | my $title = $section_ref->{title}; | |||||||||||||||||||||
| 107 | |||||||||||||||||||||||
| 108 | # The file containing the section data will match the title, converted | ||||||||||||||||||||||
| 109 | # to lowercase and with spaces changed to dashes. | ||||||||||||||||||||||
| 110 | 15 | my $file = lc($title); | |||||||||||||||||||||
| 111 | 15 | $file =~ tr{ }{-}; | |||||||||||||||||||||
| 112 | |||||||||||||||||||||||
| 113 | # Load the section content. | ||||||||||||||||||||||
| 114 | 15 | $section_ref->{body} = $self->_load_metadata('sections', $file); | |||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||
| 116 | |||||||||||||||||||||||
| 117 | # If there are no supplemental README sections, remove that data element. | ||||||||||||||||||||||
| 118 | 7 | ▶ | if (!$data_ref->{readme}{sections}->@*) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 119 | 2 | delete($data_ref->{readme}); | |||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||
| 121 | |||||||||||||||||||||||
| 122 | # If the package is marked orphaned, load the explanation. | ||||||||||||||||||||||
| 123 | 7 | ▶ | if ($data_ref->{orphaned}) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 124 | 1 | $data_ref->{unmaintained} = $self->_load_metadata('orphaned'); | |||||||||||||||||||||
| 125 | 1 | delete($data_ref->{orphaned}); | |||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||
| 127 | |||||||||||||||||||||||
| 128 | # If the package has a quote, load the text of the quote. | ||||||||||||||||||||||
| 129 | 7 | ▶ | if ($data_ref->{quote}) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 130 | 5 | $data_ref->{quote}{text} = $self->_load_metadata('quote'); | |||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||
| 132 | |||||||||||||||||||||||
| 133 | # Move the name of the license to its new metadata key. | ||||||||||||||||||||||
| 134 | 7 | my $license = $data_ref->{license}; | |||||||||||||||||||||
| 135 | 7 | $data_ref->{license} = { name => $license }; | |||||||||||||||||||||
| 136 | |||||||||||||||||||||||
| 137 | # Load additional license notices if they exist. | ||||||||||||||||||||||
| 138 | 7 | eval { $data_ref->{license}{notices} = $self->_load_metadata('notices') }; | |||||||||||||||||||||
| 139 | |||||||||||||||||||||||
| 140 | # Load the standard sections. | ||||||||||||||||||||||
| 141 | 7 | $data_ref->{blurb} = $self->_load_metadata('blurb'); | |||||||||||||||||||||
| 142 | 7 | $data_ref->{description} = $self->_load_metadata('description'); | |||||||||||||||||||||
| 143 | 7 | $data_ref->{requirements} = $self->_load_metadata('requirements'); | |||||||||||||||||||||
| 144 | |||||||||||||||||||||||
| 145 | # Load optional information if it exists. | ||||||||||||||||||||||
| 146 | 7 | for my $file (@JSON_METADATA_FILES) { | |||||||||||||||||||||
| 147 | 56 | my @file = split(m{/}xms, $file); | |||||||||||||||||||||
| 148 | 56 | ▶ | if (scalar(@file) == 1) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 149 | 7 | eval { $data_ref->{$file} = $self->_load_metadata(@file) }; | |||||||||||||||||||||
| 150 | } else { | ||||||||||||||||||||||
| 151 | 49 | eval { | |||||||||||||||||||||
| 152 | 49 | $data_ref->{ $file[0] }{ $file[1] } | |||||||||||||||||||||
| 153 | = $self->_load_metadata(@file); | ||||||||||||||||||||||
| 154 | }; | ||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||
| 157 | |||||||||||||||||||||||
| 158 | # Return the resulting configuration. | ||||||||||||||||||||||
| 159 | 7 | return $data_ref; | |||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||
| 161 | |||||||||||||||||||||||
| 162 | ############################################################################## | ||||||||||||||||||||||
| 163 | # Spin helper methods | ||||||||||||||||||||||
| 164 | ############################################################################## | ||||||||||||||||||||||
| 165 | |||||||||||||||||||||||
| 166 | # Convert a style sheet reference into a style name for *.spin pointer files. | ||||||||||||||||||||||
| 167 | # | ||||||||||||||||||||||
| 168 | # $style - Partial URL for a style sheet | ||||||||||||||||||||||
| 169 | # | ||||||||||||||||||||||
| 170 | # Returns: Corresponding style name | ||||||||||||||||||||||
| 171 | 2 | ▶ | sub _convert_style { | ||||||||||||||||||||
|
Subroutine
_convert_style: called CC=2 SCAR=7.0
| |||||||||||||||||||||||
| 172 | 2 | my ($self, $style) = @_; | |||||||||||||||||||||
| 173 | 2 | chomp($style); | |||||||||||||||||||||
| 174 | 2 | ▶ | if ($style =~ m{ / }xms) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 175 | 2 | $style = (split(m{ / }xms, $style))[-1]; | |||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||
| 177 | 2 | $style =~ s{ [.] css \z }{}xms; | |||||||||||||||||||||
| 178 | 2 | return $style; | |||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||
| 180 | |||||||||||||||||||||||
| 181 | # Given an old-format *.faq pointer file, read the master file name and any | ||||||||||||||||||||||
| 182 | # options. Return them in the structure used for *.spin pointer files. | ||||||||||||||||||||||
| 183 | # | ||||||||||||||||||||||
| 184 | # $path - Path::Tiny for the file to read | ||||||||||||||||||||||
| 185 | # | ||||||||||||||||||||||
| 186 | # Returns: Hash in the format of a *.spin pointer file | ||||||||||||||||||||||
| 187 | # Throws: Text exception if no master file is present in the pointer | ||||||||||||||||||||||
| 188 | # autodie exception if the pointer file could not be read | ||||||||||||||||||||||
| 189 | 3 | ▶ | sub _read_faq_pointer { | ||||||||||||||||||||
|
Subroutine
_read_faq_pointer: called CC=7 SCAR=19.9
| |||||||||||||||||||||||
| 190 | 3 | my ($self, $path) = @_; | |||||||||||||||||||||
| 191 | |||||||||||||||||||||||
| 192 | # Read the pointer file. | ||||||||||||||||||||||
| 193 | 3 | my ($master, $options, $style) = $path->lines_utf8(); | |||||||||||||||||||||
| 194 | 3 | ▶ | if (!$master) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 195 | 0 | die "no master file specified in $path\n"; | |||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||
| 197 | 3 | chomp($master); | |||||||||||||||||||||
| 198 | |||||||||||||||||||||||
| 199 | # Put the results into the correct format. | ||||||||||||||||||||||
| 200 | 3 | my %results = (format => 'text', path => $master); | |||||||||||||||||||||
| 201 | 3 | ▶ | if (defined($style)) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 202 | 1 | $results{style} = $self->_convert_style($style); | |||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||
| 204 | 3 | ▶ | if (defined($options)) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 205 | 3 | ▶ | if ($options =~ m{ -l ( \s | \z ) }xms) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 206 | 1 | $results{options} = { modified => JSON::MaybeXS::true }; | |||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||
| 208 | 3 | ▶ | if ($options =~ m{ -t \s+ (?: '(.*)' | ( [^\'] \S+ ) ) }xms) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 209 | 1 | ▶ | $results{title} = $1 || $2; | ||||||||||||||||||||
|
Condition33%1/3
$1 || $2
MC/DC0%0/2
$1 || $2
$1
$2
Truth table33%1/3
A || B
A= $1B= $2
| |||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||
| 212 | 3 | return \%results; | |||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||
| 214 | |||||||||||||||||||||||
| 215 | # Given an old-format *.rpod pointer file, read the master file name and any | ||||||||||||||||||||||
| 216 | # options. Return them in the structure used for *.spin pointer files. | ||||||||||||||||||||||
| 217 | # | ||||||||||||||||||||||
| 218 | # $path - Path::Tiny for the file to read | ||||||||||||||||||||||
| 219 | # | ||||||||||||||||||||||
| 220 | # Returns: Hash in the format of a *.spin pointer file | ||||||||||||||||||||||
| 221 | # Throws: Text exception if no master file is present in the pointer | ||||||||||||||||||||||
| 222 | # autodie exception if the pointer file could not be read | ||||||||||||||||||||||
| 223 | 3 | ▶ | sub _read_rpod_pointer { | ||||||||||||||||||||
|
Subroutine
_read_rpod_pointer: called CC=7 SCAR=19.7
| |||||||||||||||||||||||
| 224 | 3 | my ($self, $path) = @_; | |||||||||||||||||||||
| 225 | |||||||||||||||||||||||
| 226 | # Read the pointer file. | ||||||||||||||||||||||
| 227 | 3 | my ($master, $options, $style) = $path->lines_utf8(); | |||||||||||||||||||||
| 228 | 3 | ▶ | if (!$master) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 229 | 0 | die "no master file specified in $path\n"; | |||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||
| 231 | 3 | chomp($master); | |||||||||||||||||||||
| 232 | |||||||||||||||||||||||
| 233 | # Put the results into the correct format. | ||||||||||||||||||||||
| 234 | 3 | my %results = (format => 'pod', path => $master); | |||||||||||||||||||||
| 235 | 3 | ▶ | if (defined($style)) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 236 | 1 | chomp($style); | |||||||||||||||||||||
| 237 | 1 | $results{style} = $self->_convert_style($style); | |||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||
| 239 | 3 | ▶ | if (defined($options)) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 240 | 2 | ▶ | if ($options =~ m{ -c ( \s | \z ) }xms) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 241 | $results{options} = { | ||||||||||||||||||||||
| 242 | 1 | contents => JSON::MaybeXS::true, | |||||||||||||||||||||
| 243 | navbar => JSON::MaybeXS::false, | ||||||||||||||||||||||
| 244 | }; | ||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||
| 246 | 2 | ▶ | if ($options =~ m{ -t \s+ (?: '(.*)' | ( [^\'] \S+ ) ) }xms) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 247 | 1 | ▶ | $results{title} = $1 || $2; | ||||||||||||||||||||
|
Condition33%1/3
$1 || $2
MC/DC0%0/2
$1 || $2
$1
$2
Truth table33%1/3
A || B
A= $1B= $2
| |||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||
| 250 | |||||||||||||||||||||||
| 251 | # Return the parsed file. | ||||||||||||||||||||||
| 252 | 3 | return \%results; | |||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||
| 254 | |||||||||||||||||||||||
| 255 | # Given its representation as a hash, write out a new-style *.spin file. | ||||||||||||||||||||||
| 256 | # | ||||||||||||||||||||||
| 257 | # $data_ref - Hash of data for the file | ||||||||||||||||||||||
| 258 | # $path - Path to output file | ||||||||||||||||||||||
| 259 | 6 | ▶ | sub _write_spin_pointer { | ||||||||||||||||||||
|
Subroutine
_write_spin_pointer: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 260 | 6 | my ($self, $data_ref, $path) = @_; | |||||||||||||||||||||
| 261 | |||||||||||||||||||||||
| 262 | # Generate the YAML output and strip off the leading document separator. | ||||||||||||||||||||||
| 263 | 6 | local $YAML::XS::Boolean = 'JSON::PP'; | |||||||||||||||||||||
| 264 | 6 | ▶ | my $yaml = YAML::XS::Dump($data_ref); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 265 | 6 | $yaml =~ s{ \A --- \n }{}xms; | |||||||||||||||||||||
| 266 | |||||||||||||||||||||||
| 267 | # Write the output. | ||||||||||||||||||||||
| 268 | 6 | $path->spew_utf8($yaml); | |||||||||||||||||||||
| 269 | 6 | return; | |||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||
| 271 | |||||||||||||||||||||||
| 272 | # Convert an *.faq file to a *.spin pointer. Intended to be run via | ||||||||||||||||||||||
| 273 | # Path::Iterator::Rule. | ||||||||||||||||||||||
| 274 | # | ||||||||||||||||||||||
| 275 | # $rpod_path - Path to *.rpod file | ||||||||||||||||||||||
| 276 | # $repo - Optional Git::Repository object for input tree | ||||||||||||||||||||||
| 277 | 3 | ▶ | sub _convert_faq_pointer { | ||||||||||||||||||||
|
Subroutine
_convert_faq_pointer: called CC=2 SCAR=6.9
| |||||||||||||||||||||||
| 278 | 3 | my ($self, $faq_path, $repo) = @_; | |||||||||||||||||||||
| 279 | |||||||||||||||||||||||
| 280 | # Convert the file. | ||||||||||||||||||||||
| 281 | 3 | my $data_ref = $self->_read_faq_pointer($faq_path); | |||||||||||||||||||||
| 282 | 3 | my $basename = $faq_path->basename('.faq'); | |||||||||||||||||||||
| 283 | 3 | my $spin_path = $faq_path->sibling($basename . '.spin'); | |||||||||||||||||||||
| 284 | 3 | $self->_write_spin_pointer($data_ref, $spin_path); | |||||||||||||||||||||
| 285 | |||||||||||||||||||||||
| 286 | # If we have a Git repository, update Git. | ||||||||||||||||||||||
| 287 | 3 | ▶ | if (defined($repo)) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 288 | 3 | my $root = path($repo->work_tree()); | |||||||||||||||||||||
| 289 | 3 | $repo->run('add', $spin_path->relative($root)->stringify()); | |||||||||||||||||||||
| 290 | 3 | $repo->run('rm', $faq_path->relative($root)->stringify()); | |||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||
| 292 | 3 | return; | |||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||
| 294 | |||||||||||||||||||||||
| 295 | # Convert an *.rpod file to a *.spin pointer. Intended to be run via | ||||||||||||||||||||||
| 296 | # Path::Iterator::Rule. | ||||||||||||||||||||||
| 297 | # | ||||||||||||||||||||||
| 298 | # $rpod_path - Path to *.rpod file | ||||||||||||||||||||||
| 299 | # $repo - Optional Git::Repository object for input tree | ||||||||||||||||||||||
| 300 | 3 | ▶ | sub _convert_rpod_pointer { | ||||||||||||||||||||
|
Subroutine
_convert_rpod_pointer: called CC=2 SCAR=6.9
| |||||||||||||||||||||||
| 301 | 3 | my ($self, $rpod_path, $repo) = @_; | |||||||||||||||||||||
| 302 | |||||||||||||||||||||||
| 303 | # Convert the file. | ||||||||||||||||||||||
| 304 | 3 | my $data_ref = $self->_read_rpod_pointer($rpod_path); | |||||||||||||||||||||
| 305 | 3 | my $basename = $rpod_path->basename('.rpod'); | |||||||||||||||||||||
| 306 | 3 | my $spin_path = $rpod_path->sibling($basename . '.spin'); | |||||||||||||||||||||
| 307 | 3 | $self->_write_spin_pointer($data_ref, $spin_path); | |||||||||||||||||||||
| 308 | |||||||||||||||||||||||
| 309 | # If we have a Git repository, update Git. | ||||||||||||||||||||||
| 310 | 3 | ▶ | if (defined($repo)) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 311 | 3 | my $root = path($repo->work_tree()); | |||||||||||||||||||||
| 312 | 3 | $repo->run('add', $spin_path->relative($root)->stringify()); | |||||||||||||||||||||
| 313 | 3 | $repo->run('rm', $rpod_path->relative($root)->stringify()); | |||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||
| 315 | 3 | return; | |||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||
| 317 | |||||||||||||||||||||||
| 318 | ############################################################################## | ||||||||||||||||||||||
| 319 | # Public Interface | ||||||||||||||||||||||
| 320 | ############################################################################## | ||||||||||||||||||||||
| 321 | |||||||||||||||||||||||
| 322 | # Create a new App::DocKnot::Update object, which will be used for subsequent | ||||||||||||||||||||||
| 323 | # calls. | ||||||||||||||||||||||
| 324 | # | ||||||||||||||||||||||
| 325 | # $args - Anonymous hash of arguments with the following keys: | ||||||||||||||||||||||
| 326 | # metadata - Path to the directory containing package metadata | ||||||||||||||||||||||
| 327 | # output - Path to the output file with the converted metadata | ||||||||||||||||||||||
| 328 | # | ||||||||||||||||||||||
| 329 | # Returns: Newly created object | ||||||||||||||||||||||
| 330 | # Throws: Text exceptions on invalid metadata directory path | ||||||||||||||||||||||
| 331 | 8 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||
| 332 | 8 | my ($class, $args_ref) = @_; | |||||||||||||||||||||
| 333 | my $self = { | ||||||||||||||||||||||
| 334 | metadata => path($args_ref->{metadata} // 'docs/metadata'), | ||||||||||||||||||||||
| 335 | 8 | ▶ | output => path($args_ref->{output} // 'docs/docknot.yaml'), | ||||||||||||||||||||
|
Condition100%4/4
$args_ref->{"metadata"} // "docs/metadata"
$args_ref->{"output"} // "docs/docknot.yaml"
MC/DC100%1/1
$args_ref->{"metadata"} // "docs/metadata"
$args_ref->{"metadata"}
MC/DC100%1/1
$args_ref->{"output"} // "docs/docknot.yaml"
$args_ref->{"output"}
Truth table100%2/2
A
A= $args_ref->{"metadata"}
Truth table100%2/2
A
A= $args_ref->{"output"}
| |||||||||||||||||||||||
| 336 | }; | ||||||||||||||||||||||
| 337 | 8 | bless($self, $class); | |||||||||||||||||||||
| 338 | 8 | return $self; | |||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||
| 340 | |||||||||||||||||||||||
| 341 | # Update an older version of DocKnot configuration. Currently, this only | ||||||||||||||||||||||
| 342 | # handles the old JSON format. | ||||||||||||||||||||||
| 343 | # | ||||||||||||||||||||||
| 344 | # Raises: autodie exception on failure to read metadata | ||||||||||||||||||||||
| 345 | # Text exception on inconsistencies in the package data | ||||||||||||||||||||||
| 346 | # Text exception if schema checking failed on the converted config | ||||||||||||||||||||||
| 347 | 7 | ▶ | sub update { | ||||||||||||||||||||
|
Subroutine
update: called CC=16 SCAR=28.2
Pod
documented
| |||||||||||||||||||||||
| 348 | 7 | my ($self) = @_; | |||||||||||||||||||||
| 349 | |||||||||||||||||||||||
| 350 | # Ensure we were given a valid metadata argument. | ||||||||||||||||||||||
| 351 | 7 | ▶ | if (!$self->{metadata}->is_dir()) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 352 | 0 | my $metadata = $self->{metadata}; | |||||||||||||||||||||
| 353 | 0 | croak("metadata path $metadata does not exist or is not a directory"); | |||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||
| 355 | |||||||||||||||||||||||
| 356 | # Tell YAML::XS that we'll be feeding it JSON::PP booleans. | ||||||||||||||||||||||
| 357 | 7 | local $YAML::XS::Boolean = 'JSON::PP'; | |||||||||||||||||||||
| 358 | |||||||||||||||||||||||
| 359 | # Load the config. | ||||||||||||||||||||||
| 360 | 7 | my $data_ref = $self->_config_from_json(); | |||||||||||||||||||||
| 361 | |||||||||||||||||||||||
| 362 | # Add the current format version. | ||||||||||||||||||||||
| 363 | 7 | $data_ref->{format} = 'v1'; | |||||||||||||||||||||
| 364 | |||||||||||||||||||||||
| 365 | # Move bootstrap to build.bootstrap. | ||||||||||||||||||||||
| 366 | 7 | ▶ | if (defined($data_ref->{bootstrap})) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 367 | 1 | $data_ref->{build}{bootstrap} = $data_ref->{bootstrap}; | |||||||||||||||||||||
| 368 | 1 | delete $data_ref->{bootstrap}; | |||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||
| 370 | |||||||||||||||||||||||
| 371 | # Move build.lancaster to test.lancaster. | ||||||||||||||||||||||
| 372 | 7 | ▶ | if (defined($data_ref->{build}{lancaster})) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 373 | 4 | $data_ref->{test}{lancaster} = $data_ref->{build}{lancaster}; | |||||||||||||||||||||
| 374 | 4 | delete $data_ref->{build}{lancaster}; | |||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||
| 376 | |||||||||||||||||||||||
| 377 | # Move packaging.debian to packaging.debian.package, move debian to | ||||||||||||||||||||||
| 378 | # packaging.debian, and move packaging to distribution.packaging. | ||||||||||||||||||||||
| 379 | 7 | ▶ | if (defined($data_ref->{packaging})) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 380 | 3 | ▶ | if (defined($data_ref->{packaging}{debian})) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 381 | 3 | my $package = $data_ref->{packaging}{debian}; | |||||||||||||||||||||
| 382 | 3 | $data_ref->{packaging}{debian} = { package => $package }; | |||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||
| 385 | 7 | ▶ | if (defined($data_ref->{debian})) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 386 | 3 | ▶ | $data_ref->{packaging}{debian} //= {}; | ||||||||||||||||||||
|
Condition50%1/2
$data_ref->{"packaging"}{"debian"} //= {}
MC/DC0%0/1
$data_ref->{"packaging"}{"debian"} //= {}
$data_ref->{"packaging"}{"debian"}
Truth table50%1/2
A
A= $data_ref->{"packaging"}{"debian"}
| |||||||||||||||||||||||
| 387 | $data_ref->{packaging}{debian} | ||||||||||||||||||||||
| 388 | 3 | = { $data_ref->{debian}->%*, $data_ref->{packaging}{debian}->%* }; | |||||||||||||||||||||
| 389 | 3 | delete $data_ref->{debian}; | |||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||
| 391 | 7 | ▶ | if ($data_ref->{packaging}) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 392 | 3 | $data_ref->{distribution}{packaging} = $data_ref->{packaging}; | |||||||||||||||||||||
| 393 | 3 | delete $data_ref->{packaging}; | |||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||
| 395 | |||||||||||||||||||||||
| 396 | # Move readme.sections to sections. If there was a testing override, move | ||||||||||||||||||||||
| 397 | # it to test.override and delete it from sections. | ||||||||||||||||||||||
| 398 | 7 | ▶ | if (defined($data_ref->{readme})) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 399 | 5 | $data_ref->{sections} = $data_ref->{readme}{sections}; | |||||||||||||||||||||
| 400 | 5 | delete $data_ref->{readme}; | |||||||||||||||||||||
| 401 | 5 | for my $section_ref ($data_ref->{sections}->@*) { | |||||||||||||||||||||
| 402 | 13 | ▶ | if (lc($section_ref->{title}) eq 'testing') { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 403 | 2 | $data_ref->{test}{override} = $section_ref->{body}; | |||||||||||||||||||||
| 404 | 2 | last; | |||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||
| 407 | $data_ref->{sections} | ||||||||||||||||||||||
| 408 | 5 | = [grep { lc($_->{title}) ne 'testing' } $data_ref->{sections}->@*]; | |||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||
| 410 | |||||||||||||||||||||||
| 411 | # support.cpan is obsolete. If vcs.github is set and support.github is | ||||||||||||||||||||||
| 412 | # not, use it as support.github. | ||||||||||||||||||||||
| 413 | 7 | ▶ | if (defined($data_ref->{support}{cpan})) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 414 | 1 | ▶ | if (!defined($data_ref->{support}{github})) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 415 | 1 | ▶ | if (defined($data_ref->{vcs}{github})) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 416 | 1 | $data_ref->{support}{github} = $data_ref->{vcs}{github}; | |||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||
| 419 | 1 | delete $data_ref->{support}{cpan}; | |||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||
| 421 | |||||||||||||||||||||||
| 422 | # Check the schema of the resulting file. | ||||||||||||||||||||||
| 423 | 7 | my $schema_path = $self->appdata_path('schema/docknot.yaml'); | |||||||||||||||||||||
| 424 | 7 | my $schema_ref = YAML::XS::LoadFile($schema_path); | |||||||||||||||||||||
| 425 | 7 | eval { validate($schema_ref, $data_ref) }; | |||||||||||||||||||||
| 426 | 7 | ▶ | if ($@) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 427 | 0 | my $errors = $@; | |||||||||||||||||||||
| 428 | 0 | chomp($errors); | |||||||||||||||||||||
| 429 | 0 | die "schema validation failed:\n$errors\n"; | |||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||
| 431 | |||||||||||||||||||||||
| 432 | # Write the new YAML package configuration. | ||||||||||||||||||||||
| 433 | 7 | YAML::XS::DumpFile($self->{output}->stringify(), $data_ref); | |||||||||||||||||||||
| 434 | 7 | return; | |||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||
| 436 | |||||||||||||||||||||||
| 437 | # Update an input tree for spin to the current format. | ||||||||||||||||||||||
| 438 | # | ||||||||||||||||||||||
| 439 | # $path - Optional path to the spin input tree, defaults to current directory | ||||||||||||||||||||||
| 440 | # | ||||||||||||||||||||||
| 441 | # Raises: Text exception on failure | ||||||||||||||||||||||
| 442 | 1 | ▶ | sub update_spin { | ||||||||||||||||||||
|
Subroutine
update_spin: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||
| 443 | 1 | my ($self, $path) = @_; | |||||||||||||||||||||
| 444 | 1 | ▶ | $path = defined($path) ? path($path) : path(q{.}); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 445 | 1 | my $repo; | |||||||||||||||||||||
| 446 | 1 | ▶ | if ($path->child('.git')->is_dir()) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 447 | 1 | $repo = Git::Repository->new(work_tree => "$path"); | |||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||
| 449 | |||||||||||||||||||||||
| 450 | # Convert all *.faq files to *.spin files. | ||||||||||||||||||||||
| 451 | 1 | my $rule = Path::Iterator::Rule->new()->name(qr{ [.] faq \z }xms); | |||||||||||||||||||||
| 452 | 1 | my $iter = $rule->iter($path, { follow_symlinks => 0 }); | |||||||||||||||||||||
| 453 | 1 | ▶ | while (defined(my $file = $iter->())) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 454 | 3 | $self->_convert_faq_pointer(path($file), $repo); | |||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||
| 456 | |||||||||||||||||||||||
| 457 | # Convert all *.rpod files to *.spin files. | ||||||||||||||||||||||
| 458 | 1 | $rule = Path::Iterator::Rule->new()->name(qr{ [.] rpod \z }xms); | |||||||||||||||||||||
| 459 | 1 | $iter = $rule->iter($path, { follow_symlinks => 0 }); | |||||||||||||||||||||
| 460 | 1 | ▶ | while (defined(my $file = $iter->())) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 461 | 3 | $self->_convert_rpod_pointer(path($file), $repo); | |||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||
| 463 | 1 | return; | |||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||
| 465 | |||||||||||||||||||||||
| 466 | ############################################################################## | ||||||||||||||||||||||
| 467 | # Module return value and documentation | ||||||||||||||||||||||
| 468 | ############################################################################## | ||||||||||||||||||||||
| 469 | |||||||||||||||||||||||
| 470 | 3 | 1; | |||||||||||||||||||||
| 471 | __END__ | ||||||||||||||||||||||