-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify that __clean_eval does not use strict or warnings. #35
base: master
Are you sure you want to change the base?
Conversation
this is incomplete needs an extra diff --git a/cpan/Module-Metadata/lib/Module/Metadata.pm b/cpan/Module-Metadata/lib/Module/Metadata.pm
index 0309d768ae..1013a7e0bc 100644
--- a/cpan/Module-Metadata/lib/Module/Metadata.pm
+++ b/cpan/Module-Metadata/lib/Module/Metadata.pm
@@ -691,6 +691,7 @@ sub _evaluate_version_line {
my $eval = qq{ my \$dummy = q# Hide from _packages_inside()
#; package Module::Metadata::_version::p${pn};
use version;
+ no strict 'vars';
sub {
local $sigil$variable_name;
$line; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when strict is enabled the test suite fails with this change when trying to parse something like this
package Simple;
our $CVSVERSION = '$Revision: 1.7 $';
our ($VERSION) = ($CVSVERSION =~ /(\d+\.\d+)/);
}
|
77e5af9
to
2afad13
Compare
Agreed. Changed it to our. |
fbd275f
to
693a8fd
Compare
Sorry this doesn't make any sense. Can you give an example that is currently failing? |
Perhaps what it should be doing is |
|
Right but you can't localize a variable that hasn't yet been declared in the package. In this case,
So in the end, the issue was that |
That's one of the tricky things here. Ideally it would eval that line in the same environment as it has in the source file, but it may not be easy to establish if it should be strict or not (or something in between). Not evaluating any of the other lines only complicates that further. |
The change has been re-worked. This part is no longer a part of the merge. |
@@ -10,7 +10,7 @@ package Module::Metadata; | |||
# perl modules (assuming this may be expanded in the distant | |||
# parrot future to look at other types of modules). | |||
|
|||
sub __clean_eval { eval $_[0] } | |||
sub __clean_eval { no strict; no warnings; eval $_[0] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm mostly ok with this, but just would like to note that "no warnings" does not currently bring things to the "default" state, it in fact disables default warnings. However, I don't believe there is any reason for this module to care about default warnings here either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific warning category that is being targeted here? If so, can't we just disable that one?
In other words, what forms of syntax are being tripped up by having warnings enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is meant to guard against anything specific, but against the possibility of warnings being enabled in an outer scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was simply trying to explicitly do what I guessed the intentions were by declaring this sub prior to use warnings/strict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And as far as I know there is no way to declare that a scope should use what is currently the default set of warnings, which is an unfortunate limitation of the warnings.pm api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the current change make the original intent clear.
The function __clean_eval
as it stands (before this fix) is eval without warnings and strict hint set.
With this patch, it stays the same but would avoid someone to figure out what's happening and make the intent clear.
Yes this is hiding some issues that would have been exposed with strict and warnings, but I think this is a different case, no?
That code runs without warnings and strict being set.
sub alien { $x = "2:" + 3; return $x }
use strict;
use warnings;
print alien() . "\n";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. I am pointing out that it is not in fact the same as without warnings and strict set. "no warnings" also disables default warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. I am pointing out that it is not in fact the same as without warnings and strict set. "no warnings" also disables default warnings.
What do you suggest instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would note that this sub is only used in 2 places and the change that created it seemed to want to turn off all strict/warnings regardless. I didn't write it so I can only speculate on the intention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I had a better suggestion I would not have approved it 😉
MM's code to determine version does a local on $VERSION without having
first declared it. Instead it should do 'my' on it unless the variable
is defined at a distance.
Doing this causes this code to pass strict where it did not previously
do so.