xslate / p5-Mouse

Lightweight class builder for Perl, as a subset of Moose
https://metacpan.org/release/Mouse
Other
46 stars 32 forks source link

'use strict' not enabled when 'use 5.010' follows 'use Mouse' #40

Closed genehack closed 9 years ago

genehack commented 9 years ago

This code:

package Foo;
use Mouse;
use 5.010;

sub bar { $x = 1 ; return $x }

1;

unexpectedly compiles ok:

% perl -c Foo.pm
Foo.pm syntax OK

reversing the order of the two use declarations gives the expected compilation failure:

package Foo;
use 5.010;
use Mouse;

sub bar { $x = 1 ; return $x }

1;

% perl -c Foo.pm
Global symbol "$x" requires explicit package name at Foo.pm line 5.
Global symbol "$x" requires explicit package name at Foo.pm line 5.
Foo.pm had compilation errors.

This is with:

Summary of my perl5 (revision 5 version 20 subversion 2) configuration:

Platform: osname=darwin, osvers=14.1.0, archname=darwin-2level uname='darwin phineas.home.genehack.org 14.1.0 darwin kernel version 14.1.0: mon dec 22 23:10:38 pst 2014; root:xnu-2782.10.72~2release_x86_64 x86_64 i386 macbookair4,2 darwin ' config_args='-Dprefix=/opt/plenv/versions/5.20.2 -de -Dusedevel -A'eval:scriptdir=/opt/plenv/versions/5.20.2/bin'' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/opt/local/include', optimize='-O3', cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/opt/local/include' ccversion='', gccversion='4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)', gccosandvers='' intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/usr/local/lib -L/opt/local/lib' libpth=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /usr/lib /usr/local/lib /opt/local/lib libs=-ldbm -ldl -lm -lutil -lc perllibs=-ldl -lm -lutil -lc libc=, so=dylib, useshrplib=false, libperl=libperl.a gnulibc_version='' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/local/lib -fstack-protector'

Characteristics of this binary (from libperl): Compile-time options: HAS_TIMES PERLIO_LAYERS PERL_DONT_CREATE_GVSV PERL_HASH_FUNC_ONE_AT_A_TIME_HARD PERL_MALLOC_WRAP PERL_NEW_COPY_ON_WRITE PERL_PRESERVE_IVUV PERL_USE_DEVEL USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF Locally applied patches: Devel::PatchPerl 1.30 Built under darwin Compiled at Feb 16 2015 09:20:29 %ENV: PERL_CPANM_OPT="--skip-installed --prompt" @INC: /opt/plenv/versions/5.20.2/lib/perl5/site_perl/5.20.2/darwin-2level /opt/plenv/versions/5.20.2/lib/perl5/site_perl/5.20.2 /opt/plenv/versions/5.20.2/lib/perl5/5.20.2/darwin-2level /opt/plenv/versions/5.20.2/lib/perl5/5.20.2 .

genehack commented 9 years ago

On further testing, this problem starts somewhere between 5.14.4 and 5.16.3:

 % plenv local 5.14.4

 % perl -c Foo.pm
 Global symbol "$x" requires explicit package name at Foo.pm line 5.
 Global symbol "$x" requires explicit package name at Foo.pm line 5.
 Foo.pm had compilation errors.

 % plenv local 5.16.3

 % perl -c Foo.pm
 Foo.pm syntax OK
genehack commented 9 years ago

And, upon further investigation:

 % plenv local 5.15.5 && perl -c Foo.pm
 Global symbol "$x" requires explicit package name at Foo.pm line 5.
 Global symbol "$x" requires explicit package name at Foo.pm line 5.
 Foo.pm had compilation errors.

 % plenv local 5.15.6 && perl -c Foo.pm
 Foo.pm syntax OK
karenetheridge commented 9 years ago

Looks like https://metacpan.org/pod/release/DROLSKY/perl-5.15.6/pod/perldelta.pod#use-VERSION -- so a subsequent use 5.010 after use Mouse will first disable strict and then enable the 5.10 features.

genehack commented 9 years ago

Note that this problem does not happen with Moose:

 % cat FooMoose.pm
 package Foo;
 use Moose;
 use 5.010;

 sub bar { $x = 1 ; return $x }

 1;

 % plenv local 5.15.5 && perl -c FooMoose.pm
 Global symbol "$x" requires explicit package name at FooMoose.pm line 5.
 Global symbol "$x" requires explicit package name at FooMoose.pm line 5.
 FooMoose.pm had compilation errors.

 % plenv local 5.15.6 && perl -c FooMoose.pm
 Global symbol "$x" requires explicit package name at FooMoose.pm line 5.
 Global symbol "$x" requires explicit package name at FooMoose.pm line 5.
 FooMoose.pm had compilation errors.

 % plenv local 5.20.2 && perl -c FooMoose.pm
 Global symbol "$x" requires explicit package name at FooMoose.pm line 5.
 Global symbol "$x" requires explicit package name at FooMoose.pm line 5.
 FooMoose.pm had compilation errors.
gfx commented 9 years ago

Hmm. Can you write a test and make a pull-request for it?