| 1 | #! /bin/false | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | # Copyright (C) 2016-2018 Guido Flohr <guido.flohr@cantanea.com>, | ||||||||||||||||||||||||||||||||
| 4 | # all rights reserved. | ||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | # This program is free software: you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||
| 7 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||||||
| 8 | # the Free Software Foundation; either version 3 of the License, or | ||||||||||||||||||||||||||||||||
| 9 | # (at your option) any later version. | ||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||||||
| 14 | # GNU General Public License for more details. | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||||||
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | package Qgoda; | ||||||||||||||||||||||||||||||||
| 20 | 6 | $Qgoda::VERSION = 'v0.9.2'; | |||||||||||||||||||||||||||||||
| 21 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 6 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 24 | 6 | ▶ | use vars qw(@EXPORT $VERSION); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 25 | 6 | @EXPORT = qw($VERSION); | |||||||||||||||||||||||||||||||
| 26 | 6 | $VERSION = '0.9.0-alpha.1'; | |||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 6 | ▶ | use Locale::TextDomain qw(qgoda); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 29 | 6 | ▶ | use Locale::Messages; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | use Locale::gettext_dumb; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 31 | 6 | ▶ | use File::Find; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 32 | 6 | ▶ | use Scalar::Util qw(reftype blessed); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | use AnyEvent; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 34 | 6 | ▶ | use AnyEvent::Loop; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 35 | 6 | ▶ | use AnyEvent::Filesys::Notify; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 36 | 6 | ▶ | use AnyEvent::Handle; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 37 | 6 | ▶ | use File::Basename qw(fileparse); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 38 | 6 | ▶ | use Symbol qw(gensym); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 39 | 6 | ▶ | use IPC::Open3 qw(open3); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 40 | 6 | ▶ | use IPC::Signal; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 41 | 6 | ▶ | use POSIX qw(:sys_wait_h); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 42 | 6 | ▶ | use Template::Plugin::Gettext 0.6; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 43 | 6 | ▶ | use List::Util 1.45 qw(uniq); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 6 | ▶ | use Qgoda::Logger; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 46 | 6 | ▶ | use Qgoda::Config; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 47 | 6 | ▶ | use Qgoda::Site; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 48 | 6 | ▶ | use Qgoda::Asset; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 49 | 6 | ▶ | use Qgoda::Analyzer; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 50 | 6 | ▶ | use Qgoda::Builder; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 51 | 6 | use Qgoda::Util qw(empty strip_suffix interpolate normalize_path write_file | |||||||||||||||||||||||||||||||
| 52 | 6 | ▶ | collect_defaults purify perl_class class2module); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 53 | 6 | ▶ | use Qgoda::PluginUtils qw(load_plugins); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 6 | my $qgoda; | |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | sub new { | ||||||||||||||||||||||||||||||||
| 58 | 54 | ▶ | return $qgoda if $qgoda; | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 4 | Locale::Messages->select_package('gettext_pp'); | |||||||||||||||||||||||||||||||
| 61 | 4 | my ($class, $options, $params) = @_; | |||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 4 | ▶ | $options ||= {}; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$options ||= {}
MC/DC100%1/1
$options ||= {}
$options
Truth table100%2/2
A
A= $options
| |||||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | $params ||= {}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$params ||= {}
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
| |||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | 4 | my $self = $qgoda = bless {}, $class; | |||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 4 | $self->{__options} = { %$options }; | |||||||||||||||||||||||||||||||
| 69 | 4 | my $logger = $self->{__logger} = $self->logger; | |||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 4 | ▶ | $self->{__config} = Qgoda::Config->new unless $params->{no_config}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 72 | 4 | $self->{__builders} = [Qgoda::Builder->new]; | |||||||||||||||||||||||||||||||
| 73 | 4 | $self->{__processors} = {}; | |||||||||||||||||||||||||||||||
| 74 | 4 | $self->{__load_plugins} = 1; | |||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 4 | return $qgoda; | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | sub setSite { | ||||||||||||||||||||||||||||||||
| 80 | 2 | ▶ | my ($self, $site) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
setSite: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 2 | $self->{__site} = $site; | |||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 2 | return $self; | |||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | sub initPlugins { | ||||||||||||||||||||||||||||||||
| 88 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
initPlugins: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | delete $self->{__load_plugins} && load_plugins $qgoda; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 2 | return $self; | |||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | sub build { | ||||||||||||||||||||||||||||||||
| 96 | 2 | ▶ | my ($self, %options) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
build: called CC=15 SCAR=31.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 2 | $self->initPlugins; | |||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 2 | ▶ | if (!$self->{__build_options}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 101 | 2 | $self->{__build_options} = {%options}; | |||||||||||||||||||||||||||||||
| 102 | } elsif (!%options) { | ||||||||||||||||||||||||||||||||
| 103 | 0 | %options = %{$self->{__build_options}}; | |||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 2 | my $logger = $self->{__logger}; | |||||||||||||||||||||||||||||||
| 107 | 2 | my $config = $self->{__config}; | |||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | 2 | $logger->info(__"start building site"); | |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | chdir $self->{__config}->{srcdir} | ||||||||||||||||||||||||||||||||
| 112 | or $logger->fatal(__x("cannot chdir to source directory '{dir}': {error}", | ||||||||||||||||||||||||||||||||
| 113 | dir => $config->{srcdir}, | ||||||||||||||||||||||||||||||||
| 114 | 2 | ▶ | error => $!)); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 115 | 2 | my $site = Qgoda::Site->new($config); | |||||||||||||||||||||||||||||||
| 116 | 2 | $self->setSite($site); | |||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 2 | $self->{__outfiles} = []; | |||||||||||||||||||||||||||||||
| 119 | 2 | $self->scan($site); | |||||||||||||||||||||||||||||||
| 120 | $self->__initVersionControlled($site) | ||||||||||||||||||||||||||||||||
| 121 | 2 | ▶ | if !empty $config->{scm} && 'git' eq $config->{scm}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not &empty($config->{"scm"}) and "git" eq $config->{"scm"}
MC/DC0%0/2
not &empty($config->{"scm"}) and "git" eq $config->{"scm"}
not &empty($config->{"scm"})
"git" eq $config->{"scm"}
Truth table33%1/3
not(A) and B
A= not &empty($config->{"scm"})B= "git" eq $config->{"scm"}
| |||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | 2 | my $textdomain = $config->{po}->{textdomain}; | |||||||||||||||||||||||||||||||
| 124 | 2 | my $locale_dir = File::Spec->catfile($config->{srcdir}, 'LocaleData'); | |||||||||||||||||||||||||||||||
| 125 | 2 | Locale::gettext_dumb::bindtextdomain($textdomain, $locale_dir); | |||||||||||||||||||||||||||||||
| 126 | 2 | ▶ | if (!empty $config->{po}->{textdomain} && $config->{po}->{refresh}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not &empty($config->{"po"}{"textdomain"}) and $config->{"po"}{"refresh"}
MC/DC0%0/2
not &empty($config->{"po"}{"textdomain"}) and $config->{"po"}{"refresh"}
not &empty($config->{"po"}{"textdomain"})
$config->{"po"}{"refresh"}
Truth table66%2/3
not(A) and B
A= not &empty($config->{"po"}{"textdomain"})B= $config->{"po"}{"refresh"}
| |||||||||||||||||||||||||||||||||
| 127 | 0 | eval { | |||||||||||||||||||||||||||||||
| 128 | # Delete the cached translations so that changes are immediately | ||||||||||||||||||||||||||||||||
| 129 | # visible. | ||||||||||||||||||||||||||||||||
| 130 | # It is the privilege of the author to use private variables. ;) | ||||||||||||||||||||||||||||||||
| 131 | 0 | delete $Locale::gettext_pp::__gettext_pp_domain_cache->{$locale_dir}; | |||||||||||||||||||||||||||||||
| 132 | }; | ||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | 2 | ▶ | $self->__analyze($site) or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | $self->__locate($site) or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | 2 | $self->__build($site, %options); | |||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 2 | ▶ | return $self if $options{dry_run}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | 2 | my $deleted = $self->__prune($site); | |||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 2 | my $site = $self->getSite; | |||||||||||||||||||||||||||||||
| 145 | 2 | my $modified = scalar keys %{$site->getModified}; | |||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | 2 | ▶ | if (($modified + $deleted) && !empty $config->{paths}->{timestamp}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$modified + $deleted and not &empty($config->{"paths"}{"timestamp"})
MC/DC0%0/2
$modified + $deleted and not &empty($config->{"paths"}{"timestamp"})
$modified + $deleted
not &empty($config->{"paths"}{"timestamp"})
Truth table33%1/3
A and not(B)
A= $modified + $deletedB= not &empty($config->{"paths"}{"timestamp"})
| |||||||||||||||||||||||||||||||||
| 148 | my $timestamp_file = File::Spec->catfile($config->{srcdir}, | ||||||||||||||||||||||||||||||||
| 149 | 2 | $config->{paths}->{timestamp}); | |||||||||||||||||||||||||||||||
| 150 | 2 | ▶ | if (!write_file($timestamp_file, sprintf "%d\n", time)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 151 | 0 | $logger->error(__x("cannot write '{file}': {error}!", | |||||||||||||||||||||||||||||||
| 152 | file => $timestamp_file, error => $!)); | ||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | 2 | my $num_artefacts = $site->getArtefacts; | |||||||||||||||||||||||||||||||
| 157 | 2 | $logger->info(__nx("finished building site with one artefact", | |||||||||||||||||||||||||||||||
| 158 | "finished building site with {num} artefacts", | ||||||||||||||||||||||||||||||||
| 159 | $num_artefacts, | ||||||||||||||||||||||||||||||||
| 160 | num => $num_artefacts)); | ||||||||||||||||||||||||||||||||
| 161 | 2 | $logger->info(__nx("one artefact was changed and has been re-written", | |||||||||||||||||||||||||||||||
| 162 | "{num} artefacts were changed and have been re-written", | ||||||||||||||||||||||||||||||||
| 163 | $modified, | ||||||||||||||||||||||||||||||||
| 164 | num => $modified)); | ||||||||||||||||||||||||||||||||
| 165 | 2 | ▶ | if ($deleted) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 166 | 0 | $logger->info(__nx("one stale artefact has been deleted", | |||||||||||||||||||||||||||||||
| 167 | "{num} stale artefacts have been deleted", | ||||||||||||||||||||||||||||||||
| 168 | $deleted, | ||||||||||||||||||||||||||||||||
| 169 | num => $deleted)); | ||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | 2 | return $self; | |||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||
| 175 | sub dumpAssets { | ||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
dumpAssets: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | 0 | $self->build; | |||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | # Stringify all blessed references. | ||||||||||||||||||||||||||||||||
| 181 | 0 | map { purify { $_->dump } } $self->getSite->getAssets; | |||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||
| 184 | sub dump { | ||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | 0 | my $data = [$self->dumpAssets]; | |||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | 0 | my $format = $self->{__options}->{output_format}; | |||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | $format = 'JSON' if empty $format; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if ('JSON' eq uc $format) { | ||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||
| 193 | 0 | require JSON; | |||||||||||||||||||||||||||||||
| 194 | 0 | print JSON::encode_json($data); | |||||||||||||||||||||||||||||||
| 195 | } elsif ('YAML' eq uc $format) { | ||||||||||||||||||||||||||||||||
| 196 | 0 | require YAML::XS; | |||||||||||||||||||||||||||||||
| 197 | 0 | print YAML::XS::Dump($data); | |||||||||||||||||||||||||||||||
| 198 | } elsif ('STORABLE' eq uc $format) { | ||||||||||||||||||||||||||||||||
| 199 | 0 | require Storable; | |||||||||||||||||||||||||||||||
| 200 | 0 | print Storable::nfreeze($data); | |||||||||||||||||||||||||||||||
| 201 | } elsif ('PERL' eq uc $format) { | ||||||||||||||||||||||||||||||||
| 202 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||
| 203 | 0 | $Data::Dumper::Varname = 'Qgoda'; | |||||||||||||||||||||||||||||||
| 204 | 0 | print Data::Dumper::Dumper($data); | |||||||||||||||||||||||||||||||
| 205 | } else { | ||||||||||||||||||||||||||||||||
| 206 | 0 | die __x("Unsupported dump output format '{format}'.\n", | |||||||||||||||||||||||||||||||
| 207 | format => $format); | ||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | sub watch { | ||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | my ($self, %options) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
watch: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||
| 216 | 0 | my $logger = $self->{__logger}; | |||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||
| 218 | #eval { require AnyEvent::Filesys::Notify }; | ||||||||||||||||||||||||||||||||
| 219 | #if ($@) { | ||||||||||||||||||||||||||||||||
| 220 | # $logger->error($@); | ||||||||||||||||||||||||||||||||
| 221 | # $logger->fatal(__("You have to install AnyEvent::Filesys::Notify" | ||||||||||||||||||||||||||||||||
| 222 | # . " in order to use the watch functionality")); | ||||||||||||||||||||||||||||||||
| 223 | #} | ||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||
| 225 | 0 | eval { | |||||||||||||||||||||||||||||||
| 226 | # An initial build failure is fatal. | ||||||||||||||||||||||||||||||||
| 227 | 0 | $self->build(%options); | |||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | 0 | my $config = $self->{__config}; | |||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||
| 231 | 0 | $self->__startHelpers($config->{helpers}); | |||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | $logger->debug(__x("waiting for changes in '{dir}'", | ||||||||||||||||||||||||||||||||
| 234 | 0 | dir => $config->{srcdir})); | |||||||||||||||||||||||||||||||
| 235 | AnyEvent::Filesys::Notify->new( | ||||||||||||||||||||||||||||||||
| 236 | dirs => [$config->{srcdir}], | ||||||||||||||||||||||||||||||||
| 237 | interval => $config->{latency}, | ||||||||||||||||||||||||||||||||
| 238 | parse_events => 1, | ||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | cb => sub { $self->__onFilesysChange(@_) }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | filter => sub { $self->__filesysChangeFilter(@_) }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 241 | 0 | ); | |||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||
| 243 | 0 | AnyEvent::Loop::run; | |||||||||||||||||||||||||||||||
| 244 | }; | ||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | $logger->fatal($@) if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||
| 249 | sub __startHelpers { | ||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | my ($self, $helpers) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__startHelpers: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||
| 252 | 0 | $self->{__helpers} = {}; | |||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | foreach my $helper (sort keys %{$helpers || {}}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 255 | 0 | $self->__startHelper($helper, $helpers->{$helper}); | |||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||
| 261 | sub __startHelper { | ||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | my ($self, $helper, $args) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__startHelper: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | $args ||= []; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$args ||= []
MC/DC0%0/1
$args ||= []
$args
Truth table0%0/2
A
A= $args
| |||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | $args = [$helper] if !@$args; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 266 | 0 | my $logger = $self->logger; | |||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | 0 | my $safe_helper = $helper; | |||||||||||||||||||||||||||||||
| 269 | 0 | $safe_helper =~ s/[^a-z0-9]+/_/; | |||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||
| 271 | 0 | my $log_prefix = "[helper][$helper]"; | |||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||
| 273 | 0 | my $exec = $ENV{"QGODA_HELPER_$safe_helper"}; | |||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if (!empty $exec) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if ($>) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 276 | 0 | $logger->fatal($log_prefix | |||||||||||||||||||||||||||||||
| 277 | . __x("Environment variable '{variable}' ignored" | ||||||||||||||||||||||||||||||||
| 278 | . " when running as root", | ||||||||||||||||||||||||||||||||
| 279 | variable => "QGODA_HELPER_$helper")); | ||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||
| 281 | 0 | $args->[0] = $exec; | |||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | 0 | my @pretty; | |||||||||||||||||||||||||||||||
| 285 | 0 | foreach my $word (@$args) { | |||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | if ($word =~ s/([\\\"])/\\$1/g) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 287 | 0 | $word = qq{"$word"}; | |||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||
| 289 | 0 | push @pretty, $word; | |||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||
| 292 | 0 | my $pretty = join ' ', @pretty; | |||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||
| 294 | 0 | $logger->info($log_prefix . __x("starting helper: {helper}", | |||||||||||||||||||||||||||||||
| 295 | helper => $pretty)); | ||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||
| 297 | 0 | my $cout = gensym; | |||||||||||||||||||||||||||||||
| 298 | 0 | my $cerr = gensym; | |||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | my $pid = open3 undef, $cout, $cerr, @$args | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 301 | or $logger->fatal($log_prefix . __x("failure starting helper: {error}", | ||||||||||||||||||||||||||||||||
| 302 | error => $!)); | ||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||
| 304 | 0 | $self->{__helpers}->{$pid} = { | |||||||||||||||||||||||||||||||
| 305 | name => $helper, | ||||||||||||||||||||||||||||||||
| 306 | }; | ||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||
| 308 | $self->{__helpers}->{$pid}->{ahout} = AnyEvent::Handle->new( | ||||||||||||||||||||||||||||||||
| 309 | fh => $cout, | ||||||||||||||||||||||||||||||||
| 310 | on_error => sub { | ||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | my ($handle, $fatal, $msg) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | my $method = $fatal ? 'error' : 'warning'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 314 | 0 | $logger->$method($log_prefix . $msg); | |||||||||||||||||||||||||||||||
| 315 | }, | ||||||||||||||||||||||||||||||||
| 316 | on_read => sub { | ||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | my ($handle) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | while ($handle->{rbuf} =~ s{(.*?)\n}{}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 320 | 0 | $logger->info($log_prefix . $1); | |||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||
| 322 | }, | ||||||||||||||||||||||||||||||||
| 323 | 0 | ); | |||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||
| 325 | $self->{__helpers}->{$pid}->{aherr} = AnyEvent::Handle->new( | ||||||||||||||||||||||||||||||||
| 326 | fh => $cerr, | ||||||||||||||||||||||||||||||||
| 327 | on_error => sub { | ||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | my ($handle, $fatal, $msg) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | my $method = $fatal ? 'error' : 'warning'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 331 | 0 | $logger->$method($log_prefix . $msg); | |||||||||||||||||||||||||||||||
| 332 | }, | ||||||||||||||||||||||||||||||||
| 333 | on_read => sub { | ||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | my ($handle) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | while ($handle->{rbuf} =~ s{(.*?)\n}{}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 337 | 0 | $logger->warning($log_prefix . $1); | |||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||
| 339 | }, | ||||||||||||||||||||||||||||||||
| 340 | 0 | ); | |||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||
| 342 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||
| 345 | sub logger { | ||||||||||||||||||||||||||||||||
| 346 | 26 | ▶ | my ($self, $prefix) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
logger: called CC=4 SCAR=15.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||
| 348 | 26 | my %args = (prefix => $prefix); | |||||||||||||||||||||||||||||||
| 349 | 26 | ▶ | if ($self->{__options}->{verbose}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 350 | 0 | $args{debug} = 1; | |||||||||||||||||||||||||||||||
| 351 | } elsif ($self->{__options}->{quiet}) { | ||||||||||||||||||||||||||||||||
| 352 | 0 | $args{quiet} = 1; | |||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||
| 355 | 26 | ▶ | $args{log_fh} = \*STDERR if $self->{__options}->{log_stderr}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||
| 357 | 26 | return Qgoda::Logger->new(%args); | |||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||
| 360 | sub config { | ||||||||||||||||||||||||||||||||
| 361 | 70 | ▶ | shift->{__config}; | ||||||||||||||||||||||||||||||
|
Subroutine
config: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||
| 364 | sub dumpConfig { | ||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
dumpConfig: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||
| 367 | # Make a shallow copy so that we unbless the reference. | ||||||||||||||||||||||||||||||||
| 368 | 0 | my %config = %{$self->config}; | |||||||||||||||||||||||||||||||
| 369 | 0 | foreach my $key (grep { /^__q_/ } keys %config) { | |||||||||||||||||||||||||||||||
| 370 | 0 | delete $config{$key}; | |||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||
| 373 | 0 | require YAML::XS; | |||||||||||||||||||||||||||||||
| 374 | 0 | print YAML::XS::Dump(\%config); | |||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||
| 376 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||
| 379 | sub migrate { | ||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
migrate: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||
| 382 | 0 | my $from = $self->getOption('from_system'); | |||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | die __"The option '--from-system' is mandatory!\n" if empty $from; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||
| 385 | # Check for valid module names. Yes, you can use an apostrophe as the | ||||||||||||||||||||||||||||||||
| 386 | # separator in Perl but not allowing it here is at our discretion. | ||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | die __x("Invalid source system name '{software}'", software => $from) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 388 | unless $from =~ /^[a-z][a-z0-9_]+(?:(?:::|-)[a-z][a-z0-9_]+)*$/i; | ||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||
| 390 | 0 | my $module_name = 'Qgoda::Migrator::' . $from; | |||||||||||||||||||||||||||||||
| 391 | 0 | $module_name =~ s/-/::/g; | |||||||||||||||||||||||||||||||
| 392 | 0 | $module_name = lc $module_name; | |||||||||||||||||||||||||||||||
| 393 | 0 | $module_name = ucfirst $module_name; | |||||||||||||||||||||||||||||||
| 394 | 0 | $module_name =~ s/::(.)/'::' . ucfirst $1/ge; | |||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||
| 396 | 0 | my $class_name = $module_name; | |||||||||||||||||||||||||||||||
| 397 | 0 | $module_name =~ s{::}{/}g; | |||||||||||||||||||||||||||||||
| 398 | 0 | $module_name .= '.pm'; | |||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||
| 400 | 0 | eval {require $module_name}; | |||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 402 | 0 | my $error = $@; | |||||||||||||||||||||||||||||||
| 403 | 0 | my $message = __x("Unsupported source system '{software}'!\nTry the" | |||||||||||||||||||||||||||||||
| 404 | . " additional option '--verbose' for more" | ||||||||||||||||||||||||||||||||
| 405 | . " information!\n", | ||||||||||||||||||||||||||||||||
| 406 | software => $from); | ||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | $message .= $@ if $self->getOption('verbose'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 408 | 0 | die $message; | |||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||
| 411 | 0 | my $migrator = $class_name->new; | |||||||||||||||||||||||||||||||
| 412 | 0 | $migrator->migrate; | |||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||
| 414 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||
| 417 | sub init { | ||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | my ($self, $args, %options) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||
| 420 | 0 | require Qgoda::Init; | |||||||||||||||||||||||||||||||
| 421 | 0 | Qgoda::Init->new($args, %options)->init; | |||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||
| 423 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||
| 426 | sub _getProcessors { | ||||||||||||||||||||||||||||||||
| 427 | 6 | ▶ | my ($self, @names) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_getProcessors: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||
| 429 | 6 | my $processors = $self->config->{processors}; | |||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||
| 431 | 6 | my @processors; | |||||||||||||||||||||||||||||||
| 432 | 6 | foreach my $module (@names) { | |||||||||||||||||||||||||||||||
| 433 | 12 | my $class_name = 'Qgoda::Processor::' . $module; | |||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||
| 435 | 12 | ▶ | if ($self->{__processors}->{$class_name}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 436 | 6 | push @processors, $self->{__processors}->{$class_name}; | |||||||||||||||||||||||||||||||
| 437 | 6 | next; | |||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||
| 440 | 6 | ▶ | $self->logger->fatal(__x("invalid processor name '{processor}'", | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 441 | processor => $module)) | ||||||||||||||||||||||||||||||||
| 442 | if !perl_class $class_name; | ||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||
| 444 | 6 | my $module_name = class2module $class_name; | |||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||
| 446 | 6 | require $module_name; | |||||||||||||||||||||||||||||||
| 447 | 6 | my $options = $processors->{options}->{$module}; | |||||||||||||||||||||||||||||||
| 448 | 6 | my @options; | |||||||||||||||||||||||||||||||
| 449 | 6 | ▶ | if (defined $options) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 450 | 6 | ▶ | if (ref $options) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 451 | 6 | ▶ | if ('HASH' eq reftype $options) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 452 | 4 | @options = %{$options}; | |||||||||||||||||||||||||||||||
| 453 | } else { | ||||||||||||||||||||||||||||||||
| 454 | 2 | @options = @{$options}; | |||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||
| 456 | } else { | ||||||||||||||||||||||||||||||||
| 457 | 0 | @options = $options; | |||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||
| 461 | 6 | my $processor = $class_name->new(@options); | |||||||||||||||||||||||||||||||
| 462 | 6 | $self->{__processors}->{$class_name} = $processor; | |||||||||||||||||||||||||||||||
| 463 | 6 | push @processors, $processor; | |||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||
| 466 | 6 | return @processors; | |||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||
| 469 | sub getWrapperProcessors { | ||||||||||||||||||||||||||||||||
| 470 | 3 | ▶ | my ($self, $asset) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
getWrapperProcessors: called CC=7 SCAR=20.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||
| 472 | 3 | my $processors = $self->config->{processors}; | |||||||||||||||||||||||||||||||
| 473 | 3 | my $chain_name = $asset->{wrapper}; | |||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||
| 475 | 3 | ▶ | if (!defined $chain_name) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 476 | # Indirection. | ||||||||||||||||||||||||||||||||
| 477 | 3 | $chain_name = $asset->{chain}; | |||||||||||||||||||||||||||||||
| 478 | 3 | ▶ | return if !defined $chain_name; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 479 | 3 | ▶ | my $chain = $processors->{chains}->{$chain_name} or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||
| 481 | 3 | $chain_name = $chain->{wrapper}; | |||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||
| 483 | 3 | ▶ | return if !defined $chain_name; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||
| 485 | 3 | ▶ | my $chain = $processors->{chains}->{$chain_name} or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 486 | 3 | ▶ | my $names = $chain->{modules} or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||
| 488 | 3 | return $self->_getProcessors(@$names); | |||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||
| 491 | sub getProcessors { | ||||||||||||||||||||||||||||||||
| 492 | 3 | ▶ | my ($self, $asset) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
getProcessors: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||
| 494 | 3 | my $chain_name = $asset->{chain}; | |||||||||||||||||||||||||||||||
| 495 | 3 | ▶ | return if !defined $chain_name; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 496 | 3 | my $processors = $self->config->{processors}; | |||||||||||||||||||||||||||||||
| 497 | 3 | ▶ | my $chain = $processors->{chains}->{$chain_name} or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||
| 499 | 3 | ▶ | my $names = $chain->{modules} or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||
| 501 | 3 | return $self->_getProcessors(@$names); | |||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||
| 504 | sub getProcessor { | ||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
getProcessor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||
| 507 | 0 | return $self->{__processors}->{$name}; | |||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||
| 510 | sub scan { | ||||||||||||||||||||||||||||||||
| 511 | 2 | ▶ | my ($self, $site, $just_find) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
scan: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||
| 513 | 2 | my $logger = $self->{__logger}; | |||||||||||||||||||||||||||||||
| 514 | 2 | my $config = $self->{__config}; | |||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||
| 516 | 2 | my $outdir = $config->{paths}->{site}; | |||||||||||||||||||||||||||||||
| 517 | 2 | my $srcdir = $config->{srcdir}; | |||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||
| 519 | # Scan the source directory. | ||||||||||||||||||||||||||||||||
| 520 | $logger->debug(__x("scanning source directory '{srcdir}'", | ||||||||||||||||||||||||||||||||
| 521 | 2 | srcdir => $config->{srcdir})); | |||||||||||||||||||||||||||||||
| 522 | File::Find::find({ | ||||||||||||||||||||||||||||||||
| 523 | wanted => sub { | ||||||||||||||||||||||||||||||||
| 524 | 10 | ▶ | if (-f $_) { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 525 | 4 | my $path = Cwd::abs_path($_); | |||||||||||||||||||||||||||||||
| 526 | 4 | ▶ | if (!$config->ignorePath($path)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 527 | 3 | my $relpath = File::Spec->abs2rel($path, $config->{srcdir}); | |||||||||||||||||||||||||||||||
| 528 | 3 | my $asset = Qgoda::Asset->new($path, $relpath); | |||||||||||||||||||||||||||||||
| 529 | 3 | $site->addAsset($asset); | |||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||
| 532 | }, | ||||||||||||||||||||||||||||||||
| 533 | preprocess => sub { | ||||||||||||||||||||||||||||||||
| 534 | # Prevent descending into ignored directories. | ||||||||||||||||||||||||||||||||
| 535 | 6 | ▶ | my $path = Cwd::abs_path($File::Find::dir); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 536 | 6 | ▶ | if ($config->ignorePath($path)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 537 | 2 | return; | |||||||||||||||||||||||||||||||
| 538 | } else { | ||||||||||||||||||||||||||||||||
| 539 | 4 | return @_; | |||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||
| 542 | 2 | }, $config->{srcdir}); | |||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||
| 544 | 2 | ▶ | return $self if $just_find; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||
| 546 | # And the output directory. | ||||||||||||||||||||||||||||||||
| 547 | 2 | my @outfiles; | |||||||||||||||||||||||||||||||
| 548 | 2 | $self->{__outfiles} = \@outfiles; | |||||||||||||||||||||||||||||||
| 549 | $logger->debug(__x("scanning output directory '{outdir}'", | ||||||||||||||||||||||||||||||||
| 550 | 2 | outdir => $config->{paths}->{site})); | |||||||||||||||||||||||||||||||
| 551 | File::Find::find(sub { | ||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | if ($_ ne '.' && $_ ne '..') { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
Condition0%0/3
$_ ne "." and $_ ne ".."
MC/DC0%0/2
$_ ne "." and $_ ne ".."
$_ ne "."
$_ ne ".."
Truth table0%0/3
A and B
A= $_ ne "."B= $_ ne ".."
| |||||||||||||||||||||||||||||||||
| 553 | 0 | push @outfiles, Cwd::abs_path($_); | |||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||
| 555 | 2 | }, $config->{paths}->{site}); | |||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||
| 557 | 2 | return $self; | |||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||
| 560 | sub analyze { | ||||||||||||||||||||||||||||||||
| 561 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
analyze: called CC=5 SCAR=17.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||
| 563 | 2 | my $site = $self->getSite; | |||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||
| 565 | 2 | my $logger = $self->logger; | |||||||||||||||||||||||||||||||
| 566 | 2 | foreach my $analyzer (@{$self->{__analyzers}}) { | |||||||||||||||||||||||||||||||
| 567 | 2 | my $class = ref $analyzer; | |||||||||||||||||||||||||||||||
| 568 | local $SIG{__WARN__} = sub { | ||||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | my ($msg) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 570 | 0 | $logger->warning("[$class] $msg"); | |||||||||||||||||||||||||||||||
| 571 | 2 | }; | |||||||||||||||||||||||||||||||
| 572 | 2 | $logger->debug(__x("{class} setup", | |||||||||||||||||||||||||||||||
| 573 | class => "[$class]")); | ||||||||||||||||||||||||||||||||
| 574 | 2 | eval { | |||||||||||||||||||||||||||||||
| 575 | 2 | $analyzer->setup($site); | |||||||||||||||||||||||||||||||
| 576 | }; | ||||||||||||||||||||||||||||||||
| 577 | 2 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 578 | 0 | $logger->error("[$class] $@"); | |||||||||||||||||||||||||||||||
| 579 | 0 | return; | |||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||
| 582 | 2 | foreach my $asset ($site->getAssets) { | |||||||||||||||||||||||||||||||
| 583 | 3 | my $relpath = $asset->getRelpath; | |||||||||||||||||||||||||||||||
| 584 | local $SIG{__WARN__} = sub { | ||||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | my ($msg) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 586 | 0 | $logger->warning("[$class] $relpath: $msg"); | |||||||||||||||||||||||||||||||
| 587 | 3 | }; | |||||||||||||||||||||||||||||||
| 588 | 3 | $logger->debug(__x("{class} analyzing '{relpath}'", | |||||||||||||||||||||||||||||||
| 589 | class => "[$class]", relpath => $relpath)); | ||||||||||||||||||||||||||||||||
| 590 | 3 | eval { $analyzer->analyze($asset, $site) }; | |||||||||||||||||||||||||||||||
| 591 | 3 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 592 | 0 | $logger->error("[$class] $relpath: $@"); | |||||||||||||||||||||||||||||||
| 593 | 0 | $self->getSite->purgeAsset($asset); | |||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||
| 598 | 2 | return $self; | |||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||
| 601 | sub analyzeAssets { | ||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | my ($self, $assets, $included) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
analyzeAssets: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||
| 604 | 0 | my $site = $self->getSite; | |||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||
| 606 | 0 | my $logger = $self->logger; | |||||||||||||||||||||||||||||||
| 607 | 0 | foreach my $analyzer (@{$self->{__analyzers}}) { | |||||||||||||||||||||||||||||||
| 608 | 0 | my $class = ref $analyzer; | |||||||||||||||||||||||||||||||
| 609 | 0 | foreach my $asset (@$assets) { | |||||||||||||||||||||||||||||||
| 610 | 0 | my $relpath = $asset->getRelpath; | |||||||||||||||||||||||||||||||
| 611 | local $SIG{__WARN__} = sub { | ||||||||||||||||||||||||||||||||
| 612 | 0 | ▶ | my ($msg) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 613 | 0 | $logger->warning("[$class] $relpath: $msg"); | |||||||||||||||||||||||||||||||
| 614 | 0 | }; | |||||||||||||||||||||||||||||||
| 615 | 0 | $logger->debug(__x("{class} analyzing '{relpath}'", | |||||||||||||||||||||||||||||||
| 616 | class => "[$class]", relpath => $relpath)); | ||||||||||||||||||||||||||||||||
| 617 | 0 | eval { $analyzer->analyze($asset, $site, $included) }; | |||||||||||||||||||||||||||||||
| 618 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 619 | 0 | $logger->error("[$class] $relpath: $@"); | |||||||||||||||||||||||||||||||
| 620 | 0 | ▶ | $self->getSite->purgeAsset($asset) if !$included; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||
| 625 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||
| 628 | sub __analyze { | ||||||||||||||||||||||||||||||||
| 629 | 2 | ▶ | my ($self, $site) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__analyze: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||
| 631 | 2 | ▶ | $self->initAnalyzers if !$self->{__analyzers}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||
| 633 | 2 | return $self->analyze; | |||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||
| 636 | sub initAnalyzers { | ||||||||||||||||||||||||||||||||
| 637 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
initAnalyzers: called CC=4 SCAR=22.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||
| 639 | 2 | my @analyzers = (Qgoda::Analyzer->new); | |||||||||||||||||||||||||||||||
| 640 | 2 | $self->{__analyzers} = \@analyzers; | |||||||||||||||||||||||||||||||
| 641 | 2 | ▶ | my $names = $self->config->{analyzers} or return $self; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||
| 643 | 0 | foreach my $name (@$names) { | |||||||||||||||||||||||||||||||
| 644 | 0 | my $class_name = 'Qgoda::Analyzer::' . $name; | |||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||
| 646 | 0 | ▶ | $self->logger->fatal(__x("invalid analyzer name '{analyzer}'", | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 647 | analyzer => $name)) | ||||||||||||||||||||||||||||||||
| 648 | if !perl_class $class_name; | ||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||
| 650 | 0 | my $module_name = class2module $class_name; | |||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||
| 652 | 0 | require $module_name; | |||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||
| 654 | 0 | my $analyzer = $class_name->new; | |||||||||||||||||||||||||||||||
| 655 | 0 | push @analyzers, $analyzer; | |||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||
| 658 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||
| 661 | sub __build { | ||||||||||||||||||||||||||||||||
| 662 | 2 | ▶ | my ($self, %options) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__build: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||
| 664 | 2 | my $site = $self->getSite; | |||||||||||||||||||||||||||||||
| 665 | 2 | foreach my $builder (@{$self->{__builders}}) { | |||||||||||||||||||||||||||||||
| 666 | 2 | $builder->build($site, %options); | |||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||
| 669 | 2 | return $self; | |||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||
| 672 | # FIXME! This should instantiate plug-ins and use them instead. | ||||||||||||||||||||||||||||||||
| 673 | sub __prune { | ||||||||||||||||||||||||||||||||
| 674 | 2 | ▶ | my ($self, $site) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__prune: called CC=7 SCAR=32.7
| |||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||
| 676 | # Sort the output files by length first. That ensures that we do a | ||||||||||||||||||||||||||||||||
| 677 | # depth first clean-up. | ||||||||||||||||||||||||||||||||
| 678 | my @outfiles = sort { | ||||||||||||||||||||||||||||||||
| 679 | 0 | length($b) <=> length($a) | |||||||||||||||||||||||||||||||
| 680 | 2 | } @{$self->{__outfiles}}; | |||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||
| 682 | 2 | my $logger = $self->{__logger}; | |||||||||||||||||||||||||||||||
| 683 | 2 | my %directories; | |||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||
| 685 | 2 | my $deleted = 0; | |||||||||||||||||||||||||||||||
| 686 | 2 | foreach my $outfile (@outfiles) { | |||||||||||||||||||||||||||||||
| 687 | 0 | ▶ | if ($directories{$outfile} || $site->getArtefact($outfile)) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$directories{$outfile} or $site->getArtefact($outfile)
MC/DC0%0/2
$directories{$outfile} or $site->getArtefact($outfile)
$directories{$outfile}
$site->getArtefact($outfile)
Truth table0%0/3
A or B
A= $directories{$outfile}B= $site->getArtefact($outfile)
| |||||||||||||||||||||||||||||||||
| 688 | # Mark the containing directory as generated. | ||||||||||||||||||||||||||||||||
| 689 | 0 | my ($volume, $directory, $filename) = File::Spec->splitpath($outfile); | |||||||||||||||||||||||||||||||
| 690 | 0 | my $container = File::Spec->catpath($volume, $directory, ''); | |||||||||||||||||||||||||||||||
| 691 | 0 | $container =~ s{/$}{}; | |||||||||||||||||||||||||||||||
| 692 | 0 | $directories{$container} = 1; | |||||||||||||||||||||||||||||||
| 693 | } elsif (-d $outfile) { | ||||||||||||||||||||||||||||||||
| 694 | 0 | $logger->debug(__x("pruning directory '{directory}'", | |||||||||||||||||||||||||||||||
| 695 | directory => $outfile)); | ||||||||||||||||||||||||||||||||
| 696 | 0 | ▶ | $logger->error(__x("cannot remove directory '{directory}': {error}", | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 697 | directory => $outfile, error => $!)) | ||||||||||||||||||||||||||||||||
| 698 | if !rmdir $outfile; | ||||||||||||||||||||||||||||||||
| 699 | } else { | ||||||||||||||||||||||||||||||||
| 700 | 0 | ++$deleted; | |||||||||||||||||||||||||||||||
| 701 | 0 | $logger->debug(__x("pruning file '{file}'", | |||||||||||||||||||||||||||||||
| 702 | file => $outfile)); | ||||||||||||||||||||||||||||||||
| 703 | 0 | ▶ | $logger->error(__x("cannot remove file '{filename}': {error}", | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 704 | filename => $outfile, error => $!)) | ||||||||||||||||||||||||||||||||
| 705 | if !unlink $outfile; | ||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||
| 709 | 2 | return $deleted; | |||||||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||
| 712 | sub __filesysChangeFilter { | ||||||||||||||||||||||||||||||||
| 713 | 0 | ▶ | my ($self, $filename) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__filesysChangeFilter: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||
| 715 | 0 | my $config = $self->{__config}; | |||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | if ($config->ignorePath($filename, 1)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 718 | 0 | my $logger = $self->{__logger}; | |||||||||||||||||||||||||||||||
| 719 | 0 | $logger->debug(__x("changed file '{filename}' is ignored", | |||||||||||||||||||||||||||||||
| 720 | filename => $filename)); | ||||||||||||||||||||||||||||||||
| 721 | 0 | return; | |||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||
| 724 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||
| 727 | sub __onFilesysChange { | ||||||||||||||||||||||||||||||||
| 728 | 0 | ▶ | my ($self, @events) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__onFilesysChange: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||
| 730 | 0 | my @files; | |||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||
| 732 | 0 | my $logger = $self->{__logger}; | |||||||||||||||||||||||||||||||
| 733 | 0 | my $config = $self->{__config}; | |||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||
| 735 | 0 | foreach my $event (@events) { | |||||||||||||||||||||||||||||||
| 736 | $logger->debug(__x("file '{filename}' has changed", | ||||||||||||||||||||||||||||||||
| 737 | 0 | filename => $event->{path})); | |||||||||||||||||||||||||||||||
| 738 | 0 | push @files, $event->{path}; | |||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||
| 741 | 0 | ▶ | return if !@files; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||
| 743 | 0 | $logger->info(__"start rebuilding site because of file system change"); | |||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||
| 745 | 0 | eval { $self->build }; | |||||||||||||||||||||||||||||||
| 746 | 0 | ▶ | $logger->error($@) if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||
| 748 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||
| 751 | sub getAnalyzers { | ||||||||||||||||||||||||||||||||
| 752 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
getAnalyzers: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||
| 754 | 0 | return $self->{__analyzers}; | |||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||
| 757 | sub getBuilders { | ||||||||||||||||||||||||||||||||
| 758 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
getBuilders: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||
| 760 | 0 | return $self->{__builders}; | |||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||
| 763 | sub getSite { | ||||||||||||||||||||||||||||||||
| 764 | 17 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
getSite: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||
| 766 | 17 | return $self->{__site}; | |||||||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||
| 769 | sub __locate { | ||||||||||||||||||||||||||||||||
| 770 | 2 | ▶ | my ($self, $site) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__locate: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||
| 772 | 2 | foreach my $asset ($site->getAssets) { | |||||||||||||||||||||||||||||||
| 773 | 3 | $self->locateAsset($asset); | |||||||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||
| 776 | 2 | return $self; | |||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||
| 779 | sub locateAsset { | ||||||||||||||||||||||||||||||||
| 780 | 3 | ▶ | my ($self, $asset) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
locateAsset: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||
| 782 | 3 | my $site = $self->getSite; | |||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||
| 784 | 3 | my $logger = $self->logger; | |||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||
| 786 | 3 | $logger->debug(__x("locating asset '/{relpath}'", | |||||||||||||||||||||||||||||||
| 787 | relpath => $asset->getRelpath)); | ||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||
| 789 | my $location = $asset->{raw} ? '/' . $asset->getRelpath | ||||||||||||||||||||||||||||||||
| 790 | 3 | ▶ | : $self->expandLink($asset, $site, $asset->{location}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 791 | 3 | $logger->debug(__x("location '{location}'", | |||||||||||||||||||||||||||||||
| 792 | location => $location)); | ||||||||||||||||||||||||||||||||
| 793 | 3 | $asset->{location} = $location; | |||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||
| 795 | 3 | my ($significant, $directory) = fileparse $location; | |||||||||||||||||||||||||||||||
| 796 | 3 | ($significant) = strip_suffix $significant; | |||||||||||||||||||||||||||||||
| 797 | 3 | ▶ | if ($significant eq $asset->{index}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 798 | 3 | $asset->{'significant-path'} = $directory; | |||||||||||||||||||||||||||||||
| 799 | 3 | ▶ | $asset->{'significant-path'} .= '/' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 800 | unless '/' eq substr $directory, -1, 1; | ||||||||||||||||||||||||||||||||
| 801 | } else { | ||||||||||||||||||||||||||||||||
| 802 | 0 | $asset->{'significant-path'} = $location; | |||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||
| 804 | 3 | my $permalink = $self->expandLink($asset, $site, $asset->{permalink}, 1); | |||||||||||||||||||||||||||||||
| 805 | 3 | $logger->debug(__x("permalink '{permalink}'", | |||||||||||||||||||||||||||||||
| 806 | permalink => $permalink)); | ||||||||||||||||||||||||||||||||
| 807 | 3 | $asset->{permalink} = $permalink; | |||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||
| 809 | 3 | return $self; | |||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||
| 812 | sub expandLink { | ||||||||||||||||||||||||||||||||
| 813 | 6 | ▶ | my ($self, $asset, $site, $link, $trailing_slash) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
expandLink: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||
| 815 | 6 | my $interpolated = interpolate $link, $asset; | |||||||||||||||||||||||||||||||
| 816 | 6 | return normalize_path $interpolated, $trailing_slash; | |||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||
| 819 | sub debugging { | ||||||||||||||||||||||||||||||||
| 820 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
debugging: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||
| 822 | 0 | return $self->{__options}->{__verbose}; | |||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||
| 825 | sub getOption { | ||||||||||||||||||||||||||||||||
| 826 | 3 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
getOption: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||
| 828 | 3 | ▶ | return if !exists $self->{__options}->{$name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||
| 830 | 0 | return $self->{__options}->{$name}; | |||||||||||||||||||||||||||||||
| 831 | } | ||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||
| 833 | sub _reload { | ||||||||||||||||||||||||||||||||
| 834 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_reload: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||
| 836 | 0 | $self->{__config} = Qgoda::Config->new; | |||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||
| 838 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 839 | } | ||||||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||||||
| 841 | sub __initVersionControlled { | ||||||||||||||||||||||||||||||||
| 842 | 0 | ▶ | my ($self, $site) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__initVersionControlled: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||
| 844 | 0 | my $logger = $self->logger; | |||||||||||||||||||||||||||||||
| 845 | 0 | $logger->debug("finding files under version control (git)"); | |||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||
| 847 | 0 | my $config = $self->config; | |||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||
| 849 | 0 | require Git; | |||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||
| 851 | 0 | my $repo = Git->repository(Directory => $config->{srcdir}); | |||||||||||||||||||||||||||||||
| 852 | 0 | my @files = $repo->command(['ls-files'], STDERR => 0); | |||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||
| 854 | # These are all relative paths. | ||||||||||||||||||||||||||||||||
| 855 | 0 | my $version_controlled = { | |||||||||||||||||||||||||||||||
| 856 | absolute => {}, | ||||||||||||||||||||||||||||||||
| 857 | relative => {}, | ||||||||||||||||||||||||||||||||
| 858 | }; | ||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||
| 860 | 0 | my $srcdir = $config->{srcdir}; | |||||||||||||||||||||||||||||||
| 861 | 0 | foreach my $relpath (@files) { | |||||||||||||||||||||||||||||||
| 862 | 0 | my $abspath = File::Spec->rel2abs($relpath, $srcdir); | |||||||||||||||||||||||||||||||
| 863 | 0 | $version_controlled->{absolute}->{$abspath} = $relpath; | |||||||||||||||||||||||||||||||
| 864 | 0 | $version_controlled->{relative}->{$relpath} = $abspath; | |||||||||||||||||||||||||||||||
| 865 | } | ||||||||||||||||||||||||||||||||
| 866 | 0 | $self->{__version_controlled} = $version_controlled; | |||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||
| 868 | 0 | my $no_scm = $self->__initNoSCMPatterns; | |||||||||||||||||||||||||||||||
| 869 | 0 | foreach my $asset (values %{$site->{assets}}) { | |||||||||||||||||||||||||||||||
| 870 | 0 | ▶ | if (!$version_controlled->{absolute}->{$asset->getPath}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 871 | 0 | my $relpath = $asset->getRelpath; | |||||||||||||||||||||||||||||||
| 872 | 0 | ▶ | next if $no_scm && $no_scm->match($relpath); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$no_scm and $no_scm->match($relpath)
MC/DC0%0/2
$no_scm and $no_scm->match($relpath)
$no_scm
$no_scm->match($relpath)
Truth table0%0/3
A and B
A= $no_scmB= $no_scm->match($relpath)
| |||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||
| 874 | 0 | $logger->debug(__x("ignoring '{relpath}': not under version control", | |||||||||||||||||||||||||||||||
| 875 | relpath => $relpath)); | ||||||||||||||||||||||||||||||||
| 876 | 0 | $site->removeAsset($asset); | |||||||||||||||||||||||||||||||
| 877 | } | ||||||||||||||||||||||||||||||||
| 878 | } | ||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||
| 880 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 881 | } | ||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||
| 883 | sub __initNoSCMPatterns { | ||||||||||||||||||||||||||||||||
| 884 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
__initNoSCMPatterns: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||
| 886 | 0 | my $config = $self->config; | |||||||||||||||||||||||||||||||
| 887 | 0 | my $no_scm = $config->{no_scm}; | |||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||
| 889 | 0 | ▶ | return $no_scm if blessed $no_scm; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||
| 891 | 0 | require File::Globstar::ListMatch; | |||||||||||||||||||||||||||||||
| 892 | return $config->{no_scm} = | ||||||||||||||||||||||||||||||||
| 893 | File::Globstar::ListMatch->new($no_scm, | ||||||||||||||||||||||||||||||||
| 894 | 0 | $config->{'case-insensitive'}); | |||||||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||
| 897 | sub versionControlled { | ||||||||||||||||||||||||||||||||
| 898 | 0 | ▶ | my ($self, $path, $is_absolute) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
versionControlled: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||
| 900 | 0 | my $config = $self->config; | |||||||||||||||||||||||||||||||
| 901 | 0 | ▶ | return $self if !$config->{scm} || 'git' ne $config->{scm}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $config->{"scm"} or "git" ne $config->{"scm"}
MC/DC0%0/2
not $config->{"scm"} or "git" ne $config->{"scm"}
not $config->{"scm"}
"git" ne $config->{"scm"}
Truth table0%0/3
not(A) or B
A= not $config->{"scm"}B= "git" ne $config->{"scm"}
| |||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||
| 903 | 0 | ▶ | $self->__initVersionControlled if !$self->{__version_controlled}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||
| 905 | 0 | ▶ | my $key = $is_absolute ? 'absolute' : 'relative'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 906 | 0 | ▶ | return $self if $self->{__version_controlled}->{$key}->{$path}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||
| 908 | 0 | ▶ | my $no_scm = $self->__initNoSCMPatterns or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||||||
| 910 | 0 | $path = File::Spec->rel2abs($path, $self->config->{srcdir}); | |||||||||||||||||||||||||||||||
| 911 | 0 | ▶ | return $self if $no_scm->match($path); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||
| 913 | 0 | return; | |||||||||||||||||||||||||||||||
| 914 | } | ||||||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||||||
| 916 | sub buildOptions { | ||||||||||||||||||||||||||||||||
| 917 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
buildOptions: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||
| 919 | 3 | ▶ | return %{$self->{__build_options} || {}}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 920 | } | ||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||
| 922 | 6 | 1; | |||||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||||||
| 924 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||||||
| 926 | Qgoda - The Qgoda Static Site Generator | ||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||
| 928 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||
| 930 | qgoda --help | ||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||
| 932 | open http://www.qgoda.net/ | ||||||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||||||
| 934 | =head1 DOCUMENTATION | ||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||
| 936 | The documentation for Qgoda can be found at the | ||||||||||||||||||||||||||||||||
| 937 | L<Qgoda web site|http://www.qgoda.net/>. | ||||||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||||||
| 939 | Other Qgoda modules that do not contain POD are for internal use only and | ||||||||||||||||||||||||||||||||
| 940 | should not be used directly. | ||||||||||||||||||||||||||||||||