2015-11-22 23:44:01 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# DOC MANIFEST MODULE
|
|
|
|
####################################################################################################################################
|
|
|
|
package BackRestDoc::Common::DocManifest;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
|
|
|
use Cwd qw(abs_path);
|
|
|
|
use Exporter qw(import);
|
|
|
|
our @EXPORT = qw();
|
|
|
|
use File::Basename qw(dirname);
|
2016-06-02 15:32:56 +02:00
|
|
|
use JSON::PP;
|
2015-11-22 23:44:01 +02:00
|
|
|
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Common::String;
|
|
|
|
use pgBackRest::FileCommon;
|
2015-11-22 23:44:01 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# File constants
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant FILE_MANIFEST => 'manifest.xml';
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Render constants
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant RENDER => 'render';
|
|
|
|
use constant RENDER_FILE => 'file';
|
|
|
|
|
|
|
|
use constant RENDER_TYPE => 'type';
|
|
|
|
use constant RENDER_TYPE_HTML => 'html';
|
|
|
|
push @EXPORT, qw(RENDER_TYPE_HTML);
|
2015-12-23 18:04:26 +02:00
|
|
|
use constant RENDER_TYPE_MARKDOWN => 'markdown';
|
|
|
|
push @EXPORT, qw(RENDER_TYPE_MARKDOWN);
|
2015-11-22 23:44:01 +02:00
|
|
|
use constant RENDER_TYPE_PDF => 'pdf';
|
|
|
|
push @EXPORT, qw(RENDER_TYPE_PDF);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# CONSTRUCTOR
|
|
|
|
####################################################################################################################################
|
|
|
|
sub new
|
|
|
|
{
|
|
|
|
my $class = shift; # Class name
|
|
|
|
|
|
|
|
# Create the class hash
|
|
|
|
my $self = {};
|
|
|
|
bless $self, $class;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
(
|
|
|
|
my $strOperation,
|
|
|
|
$self->{stryKeyword},
|
|
|
|
$self->{stryRequire},
|
2016-06-02 15:32:56 +02:00
|
|
|
$self->{stryExclude},
|
2015-11-22 23:44:01 +02:00
|
|
|
my $oVariableOverride,
|
2016-06-02 15:32:56 +02:00
|
|
|
$self->{strDocPath},
|
|
|
|
$self->{bDeploy},
|
|
|
|
$self->{bCacheOnly},
|
2015-11-22 23:44:01 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-05-26 15:09:42 +02:00
|
|
|
__PACKAGE__ . '->new', \@_,
|
2015-11-22 23:44:01 +02:00
|
|
|
{name => 'stryKeyword'},
|
|
|
|
{name => 'stryRequire'},
|
2016-06-02 15:32:56 +02:00
|
|
|
{name => 'stryExclude'},
|
2015-11-22 23:44:01 +02:00
|
|
|
{name => 'oVariableOverride', required => false},
|
|
|
|
{name => 'strDocPath', required => false},
|
2016-06-02 15:32:56 +02:00
|
|
|
{name => 'bDeploy', required => false},
|
|
|
|
{name => 'bCacheOnly', required => false},
|
2015-11-22 23:44:01 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
# Set the base path if it was not passed in
|
|
|
|
if (!defined($self->{strDocPath}))
|
|
|
|
{
|
|
|
|
$self->{strDocPath} = abs_path(dirname($0));
|
|
|
|
}
|
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
# Set cache file names
|
|
|
|
$self->{strExeCacheLocal} = $self->{strDocPath} . "/output/exe.cache";
|
|
|
|
$self->{strExeCacheDeploy} = $self->{strDocPath} . "/resource/exe.cache";
|
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
# Load the manifest
|
|
|
|
$self->{oManifestXml} = new BackRestDoc::Common::Doc("$self->{strDocPath}/manifest.xml");
|
|
|
|
|
|
|
|
# Iterate the sources
|
|
|
|
$self->{oManifest} = {};
|
|
|
|
|
|
|
|
foreach my $oSource ($self->{oManifestXml}->nodeGet('source-list')->nodeList('source'))
|
|
|
|
{
|
|
|
|
my $oSourceHash = {};
|
|
|
|
my $strKey = $oSource->paramGet('key');
|
2016-05-19 23:10:34 +02:00
|
|
|
my $strSourceType = $oSource->paramGet('type', false);
|
2015-11-22 23:44:01 +02:00
|
|
|
|
|
|
|
logDebugMisc
|
|
|
|
(
|
|
|
|
$strOperation, 'load source',
|
2016-05-19 23:10:34 +02:00
|
|
|
{name => 'strKey', value => $strKey},
|
|
|
|
{name => 'strSourceType', value => $strSourceType}
|
2015-11-22 23:44:01 +02:00
|
|
|
);
|
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
# Skip sources in exclude list
|
|
|
|
if (grep(/^$strKey$/, @{$self->{stryExclude}}))
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
$$oSourceHash{doc} = new BackRestDoc::Common::Doc("$self->{strDocPath}/xml/${strKey}.xml");
|
|
|
|
|
|
|
|
# Read variables from source
|
|
|
|
$self->variableListParse($$oSourceHash{doc}->nodeGet('variable-list', false), $oVariableOverride);
|
|
|
|
|
|
|
|
${$self->{oManifest}}{source}{$strKey} = $oSourceHash;
|
2016-05-19 23:10:34 +02:00
|
|
|
${$self->{oManifest}}{source}{$strKey}{strSourceType} = $strSourceType;
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Iterate the renderers
|
|
|
|
foreach my $oRender ($self->{oManifestXml}->nodeGet('render-list')->nodeList('render'))
|
|
|
|
{
|
|
|
|
my $oRenderHash = {};
|
|
|
|
my $strType = $oRender->paramGet(RENDER_TYPE);
|
|
|
|
|
|
|
|
# Only one instance of each render type can be defined
|
|
|
|
if (defined(${$self->{oManifest}}{&RENDER}{$strType}))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "render ${strType} has already been defined");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get the file param
|
|
|
|
$${oRenderHash}{file} = $oRender->paramGet(RENDER_FILE, false);
|
|
|
|
|
|
|
|
logDebugMisc
|
|
|
|
(
|
|
|
|
$strOperation, ' load render',
|
|
|
|
{name => 'strType', value => $strType},
|
|
|
|
{name => 'strFile', value => $${oRenderHash}{file}}
|
|
|
|
);
|
|
|
|
|
|
|
|
# Error if file is set and render type is not pdf
|
|
|
|
if (defined($${oRenderHash}{file}) && $strType ne RENDER_TYPE_PDF)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'only the pdf render type can have file set')
|
|
|
|
}
|
|
|
|
|
|
|
|
# Iterate the render sources
|
|
|
|
foreach my $oRenderOut ($oRender->nodeList('render-source'))
|
|
|
|
{
|
|
|
|
my $oRenderOutHash = {};
|
|
|
|
my $strKey = $oRenderOut->paramGet('key');
|
|
|
|
my $strSource = $oRenderOut->paramGet('source', false, $strKey);
|
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
# Skip sources in exclude list
|
|
|
|
if (grep(/^$strSource$/, @{$self->{stryExclude}}))
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
$$oRenderOutHash{source} = $strSource;
|
|
|
|
|
2015-12-23 18:04:26 +02:00
|
|
|
# Get the menu caption
|
|
|
|
if (defined($oRenderOut->paramGet('menu', false)) && $strType ne RENDER_TYPE_HTML)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "menu is only valid with html render type");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get the filename
|
|
|
|
if (defined($oRenderOut->paramGet('file', false)))
|
|
|
|
{
|
|
|
|
if ($strType eq RENDER_TYPE_HTML || $strType eq RENDER_TYPE_MARKDOWN)
|
|
|
|
{
|
|
|
|
$$oRenderOutHash{file} = $oRenderOut->paramGet('file');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "file is only valid with html or markdown render types");
|
|
|
|
}
|
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
|
2015-12-23 18:04:26 +02:00
|
|
|
if (defined($oRenderOut->paramGet('menu', false)))
|
2015-11-22 23:44:01 +02:00
|
|
|
{
|
2015-12-23 18:04:26 +02:00
|
|
|
if ($strType eq RENDER_TYPE_HTML)
|
|
|
|
{
|
|
|
|
$$oRenderOutHash{menu} = $oRenderOut->paramGet('menu', false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'only the html render type can have menu set');
|
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
logDebugMisc
|
|
|
|
(
|
|
|
|
$strOperation, ' load render source',
|
|
|
|
{name => 'strKey', value => $strKey},
|
|
|
|
{name => 'strSource', value => $strSource},
|
|
|
|
{name => 'strMenu', value => $${oRenderOutHash}{menu}}
|
|
|
|
);
|
|
|
|
|
|
|
|
$${oRenderHash}{out}{$strKey} = $oRenderOutHash;
|
|
|
|
}
|
|
|
|
|
|
|
|
${$self->{oManifest}}{render}{$strType} = $oRenderHash;
|
|
|
|
}
|
|
|
|
|
2016-05-26 20:17:50 +02:00
|
|
|
# Set the doc path variable
|
|
|
|
$self->variableSet('doc-path', $self->{strDocPath});
|
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
# Read variables from manifest
|
|
|
|
$self->variableListParse($self->{oManifestXml}->nodeGet('variable-list', false), $oVariableOverride);
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'self', value => $self}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# isBackRest
|
|
|
|
#
|
|
|
|
# Until all the backrest specific code can be abstracted, this function will identify when BackRest docs are being built.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub isBackRest
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2016-04-14 15:30:54 +02:00
|
|
|
return($self->variableTest('project-exe', 'pgbackrest'));
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# keywordMatch
|
|
|
|
#
|
|
|
|
# See if all the keywords were on the command line.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub keywordMatch
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strKeywordRequired = shift;
|
|
|
|
|
|
|
|
if (defined($strKeywordRequired))
|
|
|
|
{
|
|
|
|
for my $strKeyword (split(',', $strKeywordRequired))
|
|
|
|
{
|
|
|
|
$strKeyword = trim($strKeyword);
|
|
|
|
|
|
|
|
if (!grep(/^$strKeyword$/, @{$self->{stryKeyword}}))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# variableListParse
|
|
|
|
#
|
|
|
|
# Parse a variable list and store variables.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub variableListParse
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$oVariableList,
|
|
|
|
$oVariableOverride
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-05-26 15:09:42 +02:00
|
|
|
__PACKAGE__ . '->variableListParse', \@_,
|
2015-11-22 23:44:01 +02:00
|
|
|
{name => '$oVariableList', required => false},
|
|
|
|
{name => '$oVariableOverride', required => false}
|
|
|
|
);
|
|
|
|
|
|
|
|
if (defined($oVariableList))
|
|
|
|
{
|
|
|
|
foreach my $oVariable ($oVariableList->nodeList('variable'))
|
|
|
|
{
|
|
|
|
if ($self->keywordMatch($oVariable->paramGet('keyword', false)))
|
|
|
|
{
|
|
|
|
my $strKey = $oVariable->paramGet('key');
|
2016-06-02 15:32:56 +02:00
|
|
|
my $strValue = $self->variableReplace($oVariable->valueGet());
|
2015-11-22 23:44:01 +02:00
|
|
|
|
|
|
|
if ($oVariable->paramTest('eval', 'y'))
|
|
|
|
{
|
2016-02-23 16:39:37 +02:00
|
|
|
# In this case we really do want to evaluate the contents of strValue and not treat it as a literal.
|
|
|
|
$strValue = eval($strValue); ## no critic (BuiltinFunctions::ProhibitStringyEval)
|
2015-11-22 23:44:01 +02:00
|
|
|
|
|
|
|
if ($@)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "unable to evaluate ${strKey}: $@\n" . $oVariable->valueGet());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->variableSet($strKey, defined($$oVariableOverride{$strKey}) ? $$oVariableOverride{$strKey} : $strValue);
|
|
|
|
|
|
|
|
logDebugMisc
|
|
|
|
(
|
|
|
|
$strOperation, ' load variable',
|
|
|
|
{name => 'strKey', value => $strKey},
|
|
|
|
{name => 'strValue', value => $strValue}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# variableReplace
|
|
|
|
#
|
|
|
|
# Replace variables in the string.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub variableReplace
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strBuffer = shift;
|
|
|
|
my $strType = shift;
|
|
|
|
|
|
|
|
if (!defined($strBuffer))
|
|
|
|
{
|
2016-02-23 16:25:22 +02:00
|
|
|
return;
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $strName (sort(keys(%{$self->{oVariable}})))
|
|
|
|
{
|
|
|
|
my $strValue = $self->{oVariable}{$strName};
|
|
|
|
|
|
|
|
$strBuffer =~ s/\{\[$strName\]\}/$strValue/g;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($strType) && $strType eq 'latex')
|
|
|
|
{
|
|
|
|
$strBuffer =~ s/\\\_/\_/g;
|
|
|
|
$strBuffer =~ s/\_/\\\_/g;
|
|
|
|
$strBuffer =~ s/\\\#/\#/g;
|
|
|
|
$strBuffer =~ s/\#/\\\#/g;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $strBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# variableSet
|
|
|
|
#
|
|
|
|
# Set a variable to be replaced later.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub variableSet
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strKey = shift;
|
|
|
|
my $strValue = shift;
|
|
|
|
my $bForce = shift;
|
|
|
|
|
|
|
|
if (defined(${$self->{oVariable}}{$strKey}) && (!defined($bForce) || !$bForce))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "${strKey} variable is already defined");
|
|
|
|
}
|
|
|
|
|
|
|
|
${$self->{oVariable}}{$strKey} = $self->variableReplace($strValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# variableGet
|
|
|
|
#
|
|
|
|
# Get the current value of a variable.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub variableGet
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strKey = shift;
|
|
|
|
|
|
|
|
return ${$self->{oVariable}}{$strKey};
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# variableTest
|
|
|
|
#
|
|
|
|
# Test that a variable is defined or has an expected value.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub variableTest
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strKey = shift;
|
|
|
|
my $strExpectedValue = shift;
|
|
|
|
|
|
|
|
# Get the variable
|
|
|
|
my $strValue = ${$self->{oVariable}}{$strKey};
|
|
|
|
|
|
|
|
# Return false if it is not defined
|
|
|
|
if (!defined($strValue))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return false if it does not equal the expected value
|
|
|
|
if (defined($strExpectedValue) && $strValue ne $strExpectedValue)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# sourceGet
|
|
|
|
####################################################################################################################################
|
|
|
|
sub sourceGet
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strSource
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-05-26 15:09:42 +02:00
|
|
|
__PACKAGE__ . '->sourceGet', \@_,
|
2015-11-22 23:44:01 +02:00
|
|
|
{name => 'strSource', trace => true}
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!defined(${$self->{oManifest}}{source}{$strSource}))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "source ${strSource} does not exist");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'oSource', value => ${$self->{oManifest}}{source}{$strSource}}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# renderList
|
|
|
|
####################################################################################################################################
|
|
|
|
sub renderList
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
2016-05-26 15:09:42 +02:00
|
|
|
my ($strOperation) = logDebugParam(__PACKAGE__ . '->renderList');
|
2015-11-22 23:44:01 +02:00
|
|
|
|
|
|
|
# Check that the render output exists
|
|
|
|
my @stryRender;
|
|
|
|
|
|
|
|
if (defined(${$self->{oManifest}}{render}))
|
|
|
|
{
|
2016-05-19 16:25:04 +02:00
|
|
|
@stryRender = sort(keys(%{${$self->{oManifest}}{render}}));
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'stryRender', value => \@stryRender}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# renderGet
|
|
|
|
####################################################################################################################################
|
|
|
|
sub renderGet
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strType
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-05-26 15:09:42 +02:00
|
|
|
__PACKAGE__ . '->renderGet', \@_,
|
2015-11-22 23:44:01 +02:00
|
|
|
{name => 'strType', trace => true}
|
|
|
|
);
|
|
|
|
|
|
|
|
# Check that the render exists
|
|
|
|
if (!defined(${$self->{oManifest}}{render}{$strType}))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "render type ${strType} does not exist");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'oRenderOut', value => ${$self->{oManifest}}{render}{$strType}}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# renderOutList
|
|
|
|
####################################################################################################################################
|
|
|
|
sub renderOutList
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strType
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-05-26 15:09:42 +02:00
|
|
|
__PACKAGE__ . '->renderOutList', \@_,
|
2015-11-22 23:44:01 +02:00
|
|
|
{name => 'strType'}
|
|
|
|
);
|
|
|
|
|
|
|
|
# Check that the render output exists
|
|
|
|
my @stryRenderOut;
|
|
|
|
|
|
|
|
if (defined(${$self->{oManifest}}{render}{$strType}))
|
|
|
|
{
|
2016-05-19 16:25:04 +02:00
|
|
|
@stryRenderOut = sort(keys(%{${$self->{oManifest}}{render}{$strType}{out}}));
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'stryRenderOut', value => \@stryRenderOut}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# renderOutGet
|
|
|
|
####################################################################################################################################
|
|
|
|
sub renderOutGet
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strType,
|
2016-06-02 15:32:56 +02:00
|
|
|
$strKey,
|
|
|
|
$bIgnoreMissing,
|
2015-11-22 23:44:01 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-05-26 15:09:42 +02:00
|
|
|
__PACKAGE__ . '->renderOutGet', \@_,
|
2015-11-22 23:44:01 +02:00
|
|
|
{name => 'strType', trace => true},
|
2016-06-02 15:32:56 +02:00
|
|
|
{name => 'strKey', trace => true},
|
|
|
|
{name => 'bIgnoreMissing', default => false, trace => true},
|
2015-11-22 23:44:01 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
# use Data::Dumper; print Dumper(${$self->{oManifest}}{render});
|
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
if (!defined(${$self->{oManifest}}{render}{$strType}{out}{$strKey}) && !$bIgnoreMissing)
|
2015-11-22 23:44:01 +02:00
|
|
|
{
|
|
|
|
confess &log(ERROR, "render out ${strKey} does not exist");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'oRenderOut', value => ${$self->{oManifest}}{render}{$strType}{out}{$strKey}}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# cacheKey
|
|
|
|
####################################################################################################################################
|
|
|
|
sub cacheKey
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my ($strOperation) = logDebugParam(__PACKAGE__ . '->cacheKey');
|
|
|
|
|
|
|
|
my $strKeyword = join("\n", @{$self->{stryKeyword}});
|
|
|
|
my $strRequire = defined($self->{stryRequire}) && @{$self->{stryRequire}} > 0 ?
|
|
|
|
join("\n", @{$self->{stryRequire}}) : 'all';
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'strKeyword', value => $strKeyword},
|
|
|
|
{name => 'strRequire', value => $strRequire},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# cacheRead
|
|
|
|
####################################################################################################################################
|
|
|
|
sub cacheRead
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my ($strOperation) = logDebugParam(__PACKAGE__ . '->cacheRead');
|
|
|
|
|
|
|
|
$self->{hCache} = undef;
|
|
|
|
|
|
|
|
my $strCacheFile = $self->{bDeploy} ? $self->{strExeCacheDeploy} : $self->{strExeCacheLocal};
|
|
|
|
|
|
|
|
if (!fileExists($strCacheFile) && !$self->{bDeploy})
|
|
|
|
{
|
|
|
|
$strCacheFile = $self->{strExeCacheDeploy};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fileExists($strCacheFile))
|
|
|
|
{
|
|
|
|
my ($strKeyword, $strRequire) = $self->cacheKey();
|
|
|
|
my $oJSON = JSON::PP->new()->allow_nonref();
|
|
|
|
$self->{hCache} = $oJSON->decode(fileStringRead($strCacheFile));
|
|
|
|
|
|
|
|
foreach my $strSource (sort(keys(%{${$self->{oManifest}}{source}})))
|
|
|
|
{
|
|
|
|
my $hSource = ${$self->{oManifest}}{source}{$strSource};
|
|
|
|
|
|
|
|
if (defined(${$self->{hCache}}{$strKeyword}{$strRequire}{$strSource}))
|
|
|
|
{
|
|
|
|
$$hSource{hyCache} = ${$self->{hCache}}{$strKeyword}{$strRequire}{$strSource};
|
|
|
|
&log(DETAIL, "cache load $strSource (keyword = ${strKeyword}, require = ${strRequire})");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# cacheWrite
|
|
|
|
####################################################################################################################################
|
|
|
|
sub cacheWrite
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my ($strOperation) = logDebugParam(__PACKAGE__ . '->cacheWrite');
|
|
|
|
|
|
|
|
my $strCacheFile = $self->{bDeploy} ? $self->{strExeCacheDeploy} : $self->{strExeCacheLocal};
|
|
|
|
my ($strKeyword, $strRequire) = $self->cacheKey();
|
|
|
|
|
|
|
|
foreach my $strSource (sort(keys(%{${$self->{oManifest}}{source}})))
|
|
|
|
{
|
|
|
|
my $hSource = ${$self->{oManifest}}{source}{$strSource};
|
|
|
|
|
|
|
|
if (defined($$hSource{hyCache}))
|
|
|
|
{
|
|
|
|
${$self->{hCache}}{$strKeyword}{$strRequire}{$strSource} = $$hSource{hyCache};
|
|
|
|
&log(DETAIL, "cache load $strSource (keyword = ${strKeyword}, require = ${strRequire})");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($self->{hCache}))
|
|
|
|
{
|
|
|
|
my $oJSON = JSON::PP->new()->canonical()->allow_nonref()->pretty();
|
|
|
|
fileStringWrite($strCacheFile, $oJSON->encode($self->{hCache}), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# cacheReset
|
|
|
|
####################################################################################################################################
|
|
|
|
sub cacheReset
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strSource
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->cacheReset', \@_,
|
|
|
|
{name => 'strSource', trace => true}
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($self->{bCacheOnly})
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'Cache reset disabled by --cache-only option');
|
|
|
|
}
|
|
|
|
|
|
|
|
&log(WARN, "Cache will be reset for source ${strSource} and rendering retried automatically");
|
|
|
|
delete(${$self->{oManifest}}{source}{$strSource}{hyCache});
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
1;
|