Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

[PATCH] Add "use strict" to lib/perl5db.pl

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


shlomif at shlomifish

Jun 11, 2012, 2:43 AM

Post #1 of 9 (321 views)
Permalink
[PATCH] Add "use strict" to lib/perl5db.pl

Hi all,

the attached patch against blead adds "use strict" to lib/perl5db.pl, which is
the default perl debugger (what gets invoked by writing "perl -d".

A previous discussion about this patch took place in the 5.15.x development
branch, and the pumpking said he would like to delay integrating this patch to
after perl-5.16.0.

Regards,

Shlomi Fish

--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

He who reinvents the wheel, may actually invent a much better wheel.

Please reply to list if it's a mailing list post - http://shlom.in/reply .
Attachments: add-use-strict-to-perl5db.patch (25.2 KB)


davem at iabyn

Jun 11, 2012, 3:54 AM

Post #2 of 9 (316 views)
Permalink
Re: [PATCH] Add "use strict" to lib/perl5db.pl [In reply to]

On Mon, Jun 11, 2012 at 12:43:47PM +0300, Shlomi Fish wrote:
> the attached patch against blead adds "use strict" to lib/perl5db.pl, which is
> the default perl debugger (what gets invoked by writing "perl -d".

> @@ -510,6 +510,8 @@ where it has to go.
>
> package DB;
>
> +use strict;
> +
> BEGIN {eval 'use IO::Handle'}; # Needed for flush only? breaks under miniperl

This causes 'use strict' to be in scope for the 'eval' sub, which means
that code evaluated with 'x' is now run under 'use strict'.


--
In the 70's we wore flares because we didn't know any better.
What possible excuse does the current generation have?


shlomif at shlomifish

Jun 11, 2012, 4:12 AM

Post #3 of 9 (316 views)
Permalink
Re: [PATCH] Add "use strict" to lib/perl5db.pl [In reply to]

Hi Dave,

On Mon, 11 Jun 2012 11:54:05 +0100
Dave Mitchell <davem [at] iabyn> wrote:

> On Mon, Jun 11, 2012 at 12:43:47PM +0300, Shlomi Fish wrote:
> > the attached patch against blead adds "use strict" to lib/perl5db.pl, which is
> > the default perl debugger (what gets invoked by writing "perl -d".
>
> > @@ -510,6 +510,8 @@ where it has to go.
> >
> > package DB;
> >
> > +use strict;
> > +
> > BEGIN {eval 'use IO::Handle'}; # Needed for flush only? breaks under miniperl
>
> This causes 'use strict' to be in scope for the 'eval' sub, which means
> that code evaluated with 'x' is now run under 'use strict'.
>

Well, inside "sub eval" I am calling «eval ""» like that:

@res = eval "$usercontext $evalarg;\n"; # '\n' for nice recursive debug

In turn, $usercontext is calculated by

sub _calc_usercontext {
my ($package) = @_;

# Cancel strict completely for the evaluated code, so the code
# the user evaluates won't be affected by it. (Shlomi Fish)
return 'no strict; ($@, $!, $^E, $,, $/, $\, $^W) = @saved;'
. "package $package;"; # this won't let them modify, alas
}

And as one can see, "no strict;" is added there, so it should not affect the
evaled code.

Regards,

Shlomi Fish

--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
"Humanity" - Parody of Modern Life - http://shlom.in/humanity

My opinions may seem crazy but they all make sense. Insane sense, but sense
nonetheless.

Please reply to list if it's a mailing list post - http://shlom.in/reply .


richard.foley at rfi

Jun 11, 2012, 4:17 AM

Post #4 of 9 (315 views)
Permalink
Re: [PATCH] Add "use strict" to lib/perl5db.pl [In reply to]

A solution which would permit the patch (or one similar) might be to make the
"use strict" behaviour dependent on an option setting, something like:

PERLDB_OPTS="useStrict=1" perl -d ...

Just an idea.

--
Ciao

Richard Foley

http://www.rfi.net/books.html

On Mon, Jun 11, 2012 at 11:54:05AM +0100, Dave Mitchell wrote:
> On Mon, Jun 11, 2012 at 12:43:47PM +0300, Shlomi Fish wrote:
> > the attached patch against blead adds "use strict" to lib/perl5db.pl, which is
> > the default perl debugger (what gets invoked by writing "perl -d".
>
> > @@ -510,6 +510,8 @@ where it has to go.
> >
> > package DB;
> >
> > +use strict;
> > +
> > BEGIN {eval 'use IO::Handle'}; # Needed for flush only? breaks under miniperl
>
> This causes 'use strict' to be in scope for the 'eval' sub, which means
> that code evaluated with 'x' is now run under 'use strict'.
>
>
> --
> In the 70's we wore flares because we didn't know any better.
> What possible excuse does the current generation have?


davem at iabyn

Jun 11, 2012, 4:31 AM

Post #5 of 9 (310 views)
Permalink
Re: [PATCH] Add "use strict" to lib/perl5db.pl [In reply to]

On Mon, Jun 11, 2012 at 02:12:47PM +0300, Shlomi Fish wrote:
> > This causes 'use strict' to be in scope for the 'eval' sub, which means
> > that code evaluated with 'x' is now run under 'use strict'.
> >
>
> Well, inside "sub eval" I am calling eval "" like that:
>
> @res = eval "$usercontext $evalarg;\n"; # '\n' for nice recursive debug
>
> In turn, $usercontext is calculated by
>
> sub _calc_usercontext {
> my ($package) = @_;
>
> # Cancel strict completely for the evaluated code, so the code
> # the user evaluates won't be affected by it. (Shlomi Fish)
> return 'no strict; ($@, $!, $^E, $,, $/, $\, $^W) = @saved;'
> . "package $package;"; # this won't let them modify, alas
> }
>
> And as one can see, "no strict;" is added there, so it should not affect the
> evaled code.

Ah sorry, didn't notice that!

--
Never do today what you can put off till tomorrow.


shlomif at shlomifish

Jun 14, 2012, 1:16 AM

Post #6 of 9 (306 views)
Permalink
Re: [PATCH] Add "use strict" to lib/perl5db.pl [In reply to]

Hi Richard,

On Mon, 11 Jun 2012 13:17:21 +0200
Richard Foley <richard.foley [at] rfi> wrote:

> A solution which would permit the patch (or one similar) might be to make the
> "use strict" behaviour dependent on an option setting, something like:
>
> PERLDB_OPTS="useStrict=1" perl -d ...
>
> Just an idea.
>

This will be very hard to do properly because "use strict;" is lexically
scoped. For example, this code runs fine:

[CODE]
#!/usr/bin/perl

sub called_sub
{
$x = 500;
print "X = $x\n";
}

sub caller_sub
{
use strict;
called_sub();
}

caller_sub();
[/CODE]

Furthermore, since the patch makes the code conform to the "use strict;"
conventions, why not enable it and gain the advantages of strict.pm? Otherwise
we will have strict-compliant code without "use strict;".

Regards,

Shlomi Fish

--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Free (Creative Commons) Music Downloads, Reviews and more - http://jamendo.com/

<rindolf> If you repeat a scene 50k times, then the movie will have less
entropy and will compress better. ( irc://irc.freenode.org/#perlcafe )

Please reply to list if it's a mailing list post - http://shlom.in/reply .


richard.foley at rfi

Jun 15, 2012, 4:31 AM

Post #7 of 9 (302 views)
Permalink
Re: [PATCH] Add "use strict" to lib/perl5db.pl [In reply to]

Hi Shlomi,

I'm with you on wanting perl5db to be strict compliant.

--
Ciao

Richard Foley

http://www.rfi.net/books.html

On Thu, Jun 14, 2012 at 11:16:40AM +0300, Shlomi Fish wrote:
> Hi Richard,
>
> On Mon, 11 Jun 2012 13:17:21 +0200
> Richard Foley <richard.foley [at] rfi> wrote:
>
> > A solution which would permit the patch (or one similar) might be to make the
> > "use strict" behaviour dependent on an option setting, something like:
> >
> > PERLDB_OPTS="useStrict=1" perl -d ...
> >
> > Just an idea.
> >
>
> This will be very hard to do properly because "use strict;" is lexically
> scoped. For example, this code runs fine:
>
> [CODE]
> #!/usr/bin/perl
>
> sub called_sub
> {
> $x = 500;
> print "X = $x\n";
> }
>
> sub caller_sub
> {
> use strict;
> called_sub();
> }
>
> caller_sub();
> [/CODE]
>
> Furthermore, since the patch makes the code conform to the "use strict;"
> conventions, why not enable it and gain the advantages of strict.pm? Otherwise
> we will have strict-compliant code without "use strict;".
>
> Regards,
>
> Shlomi Fish
>
> --
> -----------------------------------------------------------------
> Shlomi Fish http://www.shlomifish.org/
> Free (Creative Commons) Music Downloads, Reviews and more - http://jamendo.com/
>
> <rindolf> If you repeat a scene 50k times, then the movie will have less
> entropy and will compress better. ( irc://irc.freenode.org/#perlcafe )
>
> Please reply to list if it's a mailing list post - http://shlom.in/reply .


pagaltzis at gmx

Jun 15, 2012, 5:43 AM

Post #8 of 9 (302 views)
Permalink
Re: [PATCH] Add "use strict" to lib/perl5db.pl [In reply to]

Hi Shlomi,

* Shlomi Fish <shlomif [at] shlomifish> [2012-06-14 10:20]:
> On Mon, 11 Jun 2012 13:17:21 +0200
> Richard Foley <richard.foley [at] rfi> wrote:
>
> > A solution which would permit the patch (or one similar) might be to
> > make the "use strict" behaviour dependent on an option setting,
> > something like:
> >
> > PERLDB_OPTS="useStrict=1" perl -d ...
> >
> > Just an idea.
>
> […] Furthermore, since the patch makes the code conform to the "use
> strict;" conventions, why not enable it and gain the advantages of
> strict.pm? Otherwise we will have strict-compliant code without "use
> strict;".

I figured after a moment of reflection that Richard meant using
PERLDB_OPTS to decide whether code the user typed at the prompt is
evaluated under strictures or not. (My first interpretation was that he
was proposing that users be able to choose whether perl5db.pl itself has
strictures turned on. But that makes no sense whatsoever, and people
don’t usually talk utter nonsense; if they seem to then the mistake is
usually the recipient’s.)

Even so I don’t think that’s useful, due to the way the debugger works.
Each line gets eval’ed, i.e. has a lexical scope of its own, so any
lexicals declared on a line go out of scope immediately. One tends to
work with globals when typing code in the debugger.

If that weren’t all the case then giving the user the choice to turn on
strictures for their code would be useful. But as it is I think they
should just stay off same as they always have.

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>


shlomif at shlomifish

Jun 18, 2012, 6:54 AM

Post #9 of 9 (293 views)
Permalink
Re: [PATCH] Add "use strict" to lib/perl5db.pl [In reply to]

Hi all,

On Mon, 11 Jun 2012 12:43:47 +0300
Shlomi Fish <shlomif [at] shlomifish> wrote:

> Hi all,
>
> the attached patch against blead adds "use strict" to lib/perl5db.pl, which is
> the default perl debugger (what gets invoked by writing "perl -d".
>
> A previous discussion about this patch took place in the 5.15.x development
> branch, and the pumpking said he would like to delay integrating this patch to
> after perl-5.16.0.
>
> Regards,
>
> Shlomi Fish
>

Replying to myself, I'd like to note that a modified version of this patch was
applied to blead yesterday. Thanks to Karl Williamson for committing it and
other people for reviewing it.

Regards,

Shlomi Fish

--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
List of Portability Libraries - http://shlom.in/port-libs

:)-<
+--
— Moses the Smiley by Shlomi Fish

Please reply to list if it's a mailing list post - http://shlom.in/reply .

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.