schwern/method-signatures — Issue #41: Problem loading Method::Signatures when Moose::Roles is involved
Author: Potatohead
Created: 2011-10-26 03:05:43+00:00
State: open

[This gist implements the problem](https://gist.github.com/1315248)

There seems to be a problem with loading Method::Signatures when roles get involved in the order things are getting loaded. perl -c on OuterUserWorks.pm goes fine, but on OuterUserBroken.pm I get

```
Couldn't load class (InnerRole) because: Devel::Pragma: scope overflow at /home/cmckay/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/i686-linux-thread-multi/Devel/Pragma.pm line 34.
BEGIN failed--compilation aborted at InnerRole.pm line 3.
Compilation failed in require at /home/cmckay/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/i686-linux-thread-multi/Class/MOP.pm line 117.
at /home/cmckay/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/i686-linux-thread-multi/Class/MOP.pm line 123
Class::MOP::__ANON__('Devel::Pragma: scope overflow at /home/cmckay/perl5/perlbrew/...') called at /home/cmckay/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Try/Tiny.pm line 100
Try::Tiny::try('CODE(0x8ab3e40)', 'Try::Tiny::Catch=REF(0x924c2f8)') called at /home/cmckay/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/i686-linux-thread-multi/Class/MOP.pm line 128
Class::MOP::load_first_existing_class('InnerRole') called at /home/cmckay/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/i686-linux-thread-multi/Class/MOP.pm line 140
Class::MOP::load_class('InnerRole', undef) called at /home/cmckay/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/i686-linux-thread-multi/Moose/Util.pm line 131
Moose::Util::_apply_all_roles('Moose::Meta::Class=HASH(0x9205650)', undef, 'InnerRole') called at /home/cmckay/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/i686-linux-thread-multi/Moose/Util.pm line 98
Moose::Util::apply_all_roles('Moose::Meta::Class=HASH(0x9205650)', 'InnerRole') called at /home/cmckay/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/i686-linux-thread-multi/Moose.pm line 65
Moose::with('Moose::Meta::Class=HASH(0x9205650)', 'InnerRole') called at /home/cmckay/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/i686-linux-thread-multi/Moose/Exporter.pm line 356
Moose::with('InnerRole') called at OuterImplementor.pm line 4
require OuterImplementor.pm called at OuterUserBroken.pm line 4
OuterUserBroken::BEGIN() called at OuterImplementor.pm line 0
eval {...} called at OuterImplementor.pm line 0
Compilation failed in require at OuterUserBroken.pm line 4.
BEGIN failed--compilation aborted at OuterUserBroken.pm line 4.
```
Moving the Method::Signatures load to after the class using the role as seen in OuterUserWorks.pm makes all the problems go away. Originally came across this issue using Method::Signatures::Modifiers with MooseX::Declare and eventually reduced it to this implementation of the error. Unfortunately The magic of all these mixed together is beyond my understanding so I can't figure out any more than it's broken in this manner.

Tested on 2 platforms:

```
Summary of my perl5 (revision 5 version 14 subversion 0) configuration:

Platform:
osname=linux, osvers=2.6.18-238.9.1.el5, archname=i686-linux-thread-multi
uname='linux cmckay.devve.iseek.com.au 2.6.18-238.9.1.el5 #1 smp tue apr 12 18:10:56 edt 2011 i686 i686 i386 gnulinux '
config_args='-de -Dprefix=/home/cmckay/perl5/perlbrew/perls/perl-5.14.0 -Dusethreads'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
ccversion='', gccversion='4.1.2 20080704 (Red Hat 4.1.2-50)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib/libc-2.5.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.5'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'

Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP
PERL_PRESERVE_IVUV USE_ITHREADS USE_LARGE_FILES
USE_PERLIO USE_PERL_ATOF USE_REENTRANT_API
Built under linux
Compiled at May 16 2011 11:27:19
%ENV:
PERLBREW_PATH="/home/cmckay/perl5/perlbrew/bin:/home/cmckay/perl5/perlbrew/perls/perl-5.14.0/bin"
PERLBREW_PERL="perl-5.14.0"
PERLBREW_ROOT="/home/cmckay/perl5/perlbrew"
PERLBREW_VERSION="0.20"
PERL_AUTOINSTALL="--alldeps"
@INC:
/home/cmckay/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/i686-linux-thread-multi
/home/cmckay/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0
/home/cmckay/perl5/perlbrew/perls/perl-5.14.0/lib/5.14.0/i686-linux-thread-multi
/home/cmckay/perl5/perlbrew/perls/perl-5.14.0/lib/5.14.0
.
```
with
* Method::Signatures 20111020
* Moose 2.0205

and

```
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
Platform:
osname=linux, osvers=2.6.18-53.el5,
archname=x86_64-linux-thread-multi
uname='linux builder10.centos.org 2.6.18-53.el5 #1 smp mon nov 12
02:14:55 est 2007 x86_64 x86_64 x86_64 gnulinux '
config_args='-des -Doptimize=-O2 -g -pipe -Wall
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m64 -mtune=generic -Dversion=5.8.8
-Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc
-Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr
-Dlibpth=/usr/local/lib64 /lib64 /usr/lib64
-Dprivlib=/usr/lib/perl5/5.8.8
-Dsitelib=/usr/lib/perl5/site_perl/5.8.8
-Dvendorlib=/usr/lib/perl5/vendor_perl/5.8.8
-Darchlib=/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi
-Dsitearch=/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi
-Dvendorarch=/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi
-Darchname=x86_64-linux-thread-multi -Dvendorprefix=/usr
-Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads
-Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm
-Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio
-Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly
-Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto
-Ud_endhostent_r_proto -Ud_sethostent_r_proto
-Ud_endprotoent_r_proto -Ud_setprotoent_r_proto
-Ud_endservent_r_proto -Ud_setservent_r_proto
-Dinc_version_list=5.8.7 5.8.6 5.8.5 -Dscriptdir=/usr/bin'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=define use64bitall=define uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing
-pipe -Wdeclaration-after-statement -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions
-fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic',
cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe
-Wdeclaration-after-statement -I/usr/local/include
-I/usr/include/gdbm'
ccversion='', gccversion='4.1.2 20080704 (Red Hat 4.1.2-50)',
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='gcc', ldflags =''
libpth=/usr/local/lib64 /lib64 /usr/lib64
libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread
-lc
perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.5'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E
-Wl,-rpath,/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE'
cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m64 -mtune=generic'

Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_IMPLICIT_CONTEXT
PERL_MALLOC_WRAP USE_64_BIT_ALL USE_64_BIT_INT
USE_ITHREADS USE_LARGE_FILES USE_PERLIO
USE_REENTRANT_API
Built under linux
Compiled at Jun 13 2011 05:55:31
%ENV:
PERL5LIB="/home/bkolera/lib/perl5/lib/perl5/x86_64-linux-thread-multi:/home/bkolera/lib/perl5/lib/perl5"
PERL_LOCAL_LIB_ROOT="/home/bkolera/lib/perl5"
PERL_MB_OPT="--install_base /home/bkolera/lib/perl5"
PERL_MM_OPT="INSTALL_BASE=/home/bkolera/lib/perl5"
@INC:
/home/bkolera/lib/perl5/lib/perl5/x86_64-linux-thread-multi
/home/bkolera/lib/perl5/lib/perl5/x86_64-linux-thread-multi
/home/bkolera/lib/perl5/lib/perl5
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.8
/usr/lib/perl5/site_perl
/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.8
/usr/lib/perl5/vendor_perl
/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi
/usr/lib/perl5/5.8.8
.
```

with
* Method::Signatures 20110923.1726
* Moose 2.0007