develooper Front page | perl.perl5.changes | Postings from November 2010

[perl.git] branch blead, updated. v5.13.7-92-gb19934f

From:
Nicholas Clark
Date:
November 25, 2010 07:04
Subject:
[perl.git] branch blead, updated. v5.13.7-92-gb19934f
Message ID:
E1PLdMn-0004KF-Du@camel.ams6.corp.booking.com
In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/b19934fbc3c981a7e4bb888f0d6a20f926a0bc17?hp=a3179684398978e8bf4afba360eb728e4215d751>

- Log -----------------------------------------------------------------
commit b19934fbc3c981a7e4bb888f0d6a20f926a0bc17
Author: Nicholas Clark <nick@ccl4.org>
Date:   Thu Nov 25 14:58:42 2010 +0000

    Extend -d:foo=bar to make -d:-foo expand to C<no foo>, consistent with -M-foo
-----------------------------------------------------------------------

Summary of changes:
 perl.c                 |   18 ++++++++++++++----
 pod/perldelta.pod      |   24 ++++++++++++++++++++++++
 pod/perlrun.pod        |    1 +
 t/lib/Devel/switchd.pm |    1 +
 t/run/switchd.t        |    8 +++++++-
 5 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/perl.c b/perl.c
index 438106e..d2571a8 100644
--- a/perl.c
+++ b/perl.c
@@ -3048,11 +3048,21 @@ Perl_moreswitches(pTHX_ const char *s)
 	/* The following permits -d:Mod to accepts arguments following an =
 	   in the fashion that -MSome::Mod does. */
 	if (*s == ':' || *s == '=') {
-	    const char *start = ++s;
-	    const char *const end = s + strlen(s);
-	    SV * const sv = newSVpvs("use Devel::");
+	    const char *start;
+	    const char *end;
+	    SV *sv;
+
+	    if (*++s == '-') {
+		++s;
+		sv = newSVpvs("no Devel::");
+	    } else {
+		sv = newSVpvs("use Devel::");
+	    }
+
+	    start = s;
+	    end = s + strlen(s);
 
-	    /* We now allow -d:Module=Foo,Bar */
+	    /* We now allow -d:Module=Foo,Bar and -d:-Module */
 	    while(isALNUM(*s) || *s==':') ++s;
 	    if (*s != '=')
 		sv_catpvn(sv, start, end - start);
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index f612dcd..f269ac3 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -28,6 +28,30 @@ here, but most should go in the L</Performance Enhancements> section.
 
 [ List each enhancement as a =head2 entry ]
 
+=head2 C<-d:-foo> calls C<Devel::foo::unimport>
+
+The syntax C<-dI<B<:>foo>> was extended in 5.6.1 to make C<-dI<:fooB<=bar>>>
+equivalent to C<-Mfoo=bar>, which expands internally to C<use foo 'bar';>.
+F<perl> now allows prefixing the module name with C<->, with the same
+semantics as C<-M>, I<i.e.>
+
+=over 4
+
+=item C<-d:-foo>
+
+Equivalent to C<-M-foo>, expands to C<no foo;>, calls C<< foo->unimport() >>
+if the method exists.
+
+=item C<-d:-foo=bar>
+
+Equivalent to C<-M-foo=bar>, expands to C<no foo 'bar';>, calls
+C<< foo->unimport('bar') >> if the method exists.
+
+=back
+
+This is particularly useful to suppresses the default actions of a
+C<Devel::*> module's C<import> method whilst still loading it for debugging.
+
 =head1 Security
 
 XXX Any security-related notices go here.  In particular, any security
diff --git a/pod/perlrun.pod b/pod/perlrun.pod
index 62c1ebb..473205a 100644
--- a/pod/perlrun.pod
+++ b/pod/perlrun.pod
@@ -361,6 +361,7 @@ tracing module installed as Devel::foo. E.g., B<-d:DProf> executes
 the program using the Devel::DProf profiler.  As with the B<-M>
 flag, options may be passed to the Devel::foo package where they
 will be received and interpreted by the Devel::foo::import routine.
+Again, like B<-M>, use -d:-foo to call Devel::foo::unimport instead of import.
 The comma-separated list of options must follow a C<=> character.
 If B<t> is specified, it indicates to the debugger that threads
 will be used in the code being debugged.
diff --git a/t/lib/Devel/switchd.pm b/t/lib/Devel/switchd.pm
index e5b0629..d436cd4 100644
--- a/t/lib/Devel/switchd.pm
+++ b/t/lib/Devel/switchd.pm
@@ -1,6 +1,7 @@
 package Devel::switchd;
 use strict; BEGIN { } # use strict; BEGIN { ... } to incite [perl #21890]
 sub import { print "import<@_>;" }
+sub unimport { print "unimport<@_>;" }
 package DB;
 sub DB { print "DB<", join(",", caller), ">;" }
 sub sub { print "sub<$DB::sub>;"; goto &$DB::sub }
diff --git a/t/run/switchd.t b/t/run/switchd.t
index 3cac218..3ea4681 100644
--- a/t/run/switchd.t
+++ b/t/run/switchd.t
@@ -9,7 +9,7 @@ BEGIN { require "./test.pl"; }
 
 # This test depends on t/lib/Devel/switchd*.pm.
 
-plan(tests => 4);
+plan(tests => 5);
 
 my $r;
 
@@ -42,6 +42,12 @@ __SWDTEST__
 		 args => ['4'],
 		);
     like($r, qr/^sub<Devel::switchd::import>;import<Devel::switchd a 42>;DB<main,$::tempfile_regexp,9>;sub<Foo::foo>;DB<Foo,$::tempfile_regexp,5>;DB<Foo,$::tempfile_regexp,6>;sub<Bar::bar>;DB<Bar,$:: ... [109 chars truncated]
+    $r = runperl(
+		 switches => [ '-Ilib', '-f', '-d:-switchd=a,42' ],
+		 progfile => $filename,
+		 args => ['4'],
+		);
+    like($r, qr/^sub<Devel::switchd::unimport>;unimport<Devel::switchd a 42>;DB<main,$::tempfile_regexp,9>;sub<Foo::foo>;DB<Foo,$::tempfile_regexp,5>;DB<Foo,$::tempfile_regexp,6>;sub<Bar::bar>;DB<Bar ... [113 chars truncated]
 }
 
 # [perl #71806]

--
Perl5 Master Repository



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