Skip to content

Inject macros via %envir#1391

Open
drdrew42 wants to merge 1 commit intoopenwebwork:developfrom
drdrew42:envir-macro-injection
Open

Inject macros via %envir#1391
drdrew42 wants to merge 1 commit intoopenwebwork:developfrom
drdrew42:envir-macro-injection

Conversation

@drdrew42
Copy link
Copy Markdown
Member

Consider this as a mechanism to bypass (or roll-your-own) hierarchy of search locations for macro files...

Existing pathways all remain behaviorally consistent, we just skip findMacroFile if content for a named macro is already provided in the environment hash.

Comment on lines +160 to +161
my ($result, $error, $fullerror) =
$self->PG_macro_file_eval($injected, "injected:$fileName");
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.

Comment on lines +176 to +177
@shortenedPaths = map { $_ =~ s|^$templateDirectory|[TMPL]/|; $_ } @shortenedPaths;
@shortenedPaths = map { $_ =~ s|^$pgDirectory|[PG]/macros/|; $_ } @shortenedPaths;
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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants