Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions lib/PGloadfiles.pm
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,33 @@ sub loadMacros {
if $debugON;
unless ($macro_file_loaded) {
warn "loadMacros: loading macro file $fileName" if $debugON;
my $filePath = $self->findMacroFile($fileName);
#### (check for renamed files here?) ####
warn "loadMacros: look for $fileName at |$filePath|" if $debugON;
if ($filePath) {
$self->compile_file($filePath);
warn "loadMacros is compiling $filePath" if $debugON;

# Check for injected macro source (from OPL content-addressed macros)
# before searching the filesystem. This allows custom macros to be
# delivered via %envir without requiring them on disk.
my $injected = $self->{envir}{injectedMacros}{$fileName};
if ($injected) {
warn "loadMacros: using injected source for $fileName" if $debugON;
my ($result, $error, $fullerror) =
$self->PG_macro_file_eval($injected, "injected:$fileName");
Comment on lines +160 to +161
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be

Suggested change
my ($result, $error, $fullerror) =
$self->PG_macro_file_eval($injected, "injected:$fileName");
my ($result, $error, $fullerror) = $self->PG_macro_file_eval($injected, "injected:$fileName");

That is the reason this is failing the perltidy check.

if ($error) {
die "Error detected while loading injected macro $fileName:\n$fullerror";
}
} else {
my $pgDirectory = $self->{envir}{pgMacrosDir};
my $templateDirectory = $self->{envir}{templateDirectory};
my @shortenedPaths = @{$macrosPath};
@shortenedPaths = map { $_ =~ s|^$templateDirectory|[TMPL]/|; $_ } @shortenedPaths;
@shortenedPaths = map { $_ =~ s|^$pgDirectory|[PG]/macros/|; $_ } @shortenedPaths;
warn "Can't locate macro file |$fileName| via path: |" . join("|,<br/> |", @shortenedPaths) . "|\n";
my $filePath = $self->findMacroFile($fileName);
#### (check for renamed files here?) ####
warn "loadMacros: look for $fileName at |$filePath|" if $debugON;
if ($filePath) {
$self->compile_file($filePath);
warn "loadMacros is compiling $filePath" if $debugON;
} else {
my $pgDirectory = $self->{envir}{pgMacrosDir};
my $templateDirectory = $self->{envir}{templateDirectory};
my @shortenedPaths = @{$macrosPath};
@shortenedPaths = map { $_ =~ s|^$templateDirectory|[TMPL]/|; $_ } @shortenedPaths;
@shortenedPaths = map { $_ =~ s|^$pgDirectory|[PG]/macros/|; $_ } @shortenedPaths;
Comment on lines +176 to +177
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that this is the original code, but it should be fixed. It should not modify $_. See https://metacpan.org/release/THALJEF/Perl-Critic-1.06/view/lib/Perl/Critic/Policy/ControlStructures/ProhibitMutatingListFunctions.pm. Yeah, the reason for the policy is moot since the intent is to modify the array element, but then again, it doesn't make sense to make the assignment with that modification either and it is also good to prevent the Perl critic warning.

So could you fix this and change this to

Suggested change
@shortenedPaths = map { $_ =~ s|^$templateDirectory|[TMPL]/|; $_ } @shortenedPaths;
@shortenedPaths = map { $_ =~ s|^$pgDirectory|[PG]/macros/|; $_ } @shortenedPaths;
@shortenedPaths = map { $_ =~ s|^$templateDirectory|[TMPL]/|r } @shortenedPaths;
@shortenedPaths = map { $_ =~ s|^$pgDirectory|[PG]/macros/|r } @shortenedPaths;

warn "Can't locate macro file |$fileName| via path: |" . join("|,<br/> |", @shortenedPaths) . "|\n";
}
}

$init_subroutine = eval { \&{ 'main::' . $init_subroutine_name } };
Expand Down
Loading