On Wed, 19 Oct 2016 14:20:42 GMT, mauke- wrote: > > This is a bug report for perl from l.mai@web.de, > generated with the help of perlbug 1.40 running under perl 5.24.0. > > > ----------------------------------------------------------------- > [Please describe your issue here] > > Here's the merge I'm talking about: > http://perl5.git.perl.org/perl.git/commitdiff/f9d9e965 > > Also listed in perl5220delta: > > Subroutines in packages no longer need to be stored in typeglobs: > declaring a subroutine will now put a simple sub reference directly in > the stash if possible, saving memory. > > This works fine for the main script: > > $ perl -wE 'sub foo { 42 } say $main::{foo}' > CODE(0xa06f668) > > But not in other packages: > > $ perl -wE 'package Other; sub foo { 42 } say $Other::{foo}' > *Other::foo > > I.e. this optimization doesn't apply to modules, which is where most > subroutines come from. > > ----- > > Speculation follows. > > I suspect this is due to the following code in op.c > (Perl_newATTRSUB_x): > > const I32 flags = > ec ? GV_NOADD_NOINIT > : PL_curstash != CopSTASH(PL_curcop) > || memchr(name, ':', namlen) || memchr(name, '\'', namlen) > ? gv_fetch_flags > : GV_ADDMULTI | GV_NOINIT | GV_NOTQUAL; > gv = gv_fetchsv(cSVOPo->op_sv, flags, SVt_PVCV); > > 'ec' stands for "error count"; this is normally false (unless we're > parsing past a syntax error). > > The 'name' check is fine (name = "foo", namlen = 3); what's tripping > us > up is the stash check. > > PL_curstash is \%X:: in this situation, but CopSTASH(PL_curcop) is > \%main::. So the stashes differ and we land in the gv_fetch_flags > path, > which adds a full typeglob. > Is this something where, for the short run, we would be best off simply noting the phenomenon in the documentation? I.e., something along the lines of: ##### Contrary to what was stated in pod/perl5220delta.pod, ... ##### Thank you very much. -- James E Keenan (jkeenan@cpan.org) --- via perlbug: queue: perl5 status: new https://rt.perl.org/Ticket/Display.html?id=129916