develooper Front page | perl.perl5.porters | Postings from April 2018

Re: [perl #133123] eval '__PACKAGE__' in debug mode do not returnright package

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
April 19, 2018 14:47
Subject:
Re: [perl #133123] eval '__PACKAGE__' in debug mode do not returnright package
Message ID:
20180419144642.GJ25122@iabyn.com
On Thu, Apr 19, 2018 at 07:06:06AM -0700, KES wrote:
> [DOC](https://perldoc.perl.org/functions/eval.html)
> >An eval '' executed within a subroutine defined in the DB package doesn't
> see the usual surrounding lexical scope, but rather the scope of the first
> non-DB piece of code that called it

That paragraph says nothing about about the package an eval is executed;
it refers purely to what *lexical* scope is seen in. This code:

    my $x = 'outer';
    package notDB { sub f { my $x = 'notDB'; eval '$x' } }
    package DB    { sub f { my $x = 'DB';    eval '$x' } }
    print notDB::f(), "-", DB::f(), "\n";

outputs:

    notDB-outer

(which is what I expect).

> How to reproduce:
> 
> $ cat Devel/DB.pm
> package DB;
> 
> 
> sub DB {
>     print eval '__PACKAGE__';
> }
> 
> 1;
> 
> $ cat t.pl
> print __PACKAGE__;
> 
> $ perl -d:DB t.pl
> DBmain
> 
> Expected:
> mainmain

I would expect DBmain.


-- 
"Foul and greedy Dwarf - you have eaten the last candle."
    -- "Hordes of the Things", BBC Radio.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About