From: Nicholas Clark Date: Thu, 25 Nov 2010 14:58:42 +0000 (+0000) Subject: Extend -d:foo=bar to make -d:-foo expand to C, consistent with -M-foo X-Git-Tag: accepted/trunk/20130322.191538~6597 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b19934fbc3c981a7e4bb888f0d6a20f926a0bc17;p=platform%2Fupstream%2Fperl.git Extend -d:foo=bar to make -d:-foo expand to C, consistent with -M-foo --- 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 section. [ List each enhancement as a =head2 entry ] +=head2 C<-d:-foo> calls C + +The syntax C<-dIfoo>> was extended in 5.6.1 to make C<-dI<:fooB<=bar>>> +equivalent to C<-Mfoo=bar>, which expands internally to C. +F now allows prefixing the module name with C<->, with the same +semantics as C<-M>, I + +=over 4 + +=item C<-d:-foo> + +Equivalent to C<-M-foo>, expands to C, calls C<< foo->unimport() >> +if the method exists. + +=item C<-d:-foo=bar> + +Equivalent to C<-M-foo=bar>, expands to C, calls +C<< foo->unimport('bar') >> if the method exists. + +=back + +This is particularly useful to suppresses the default actions of a +C module's C 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 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;import;DB;sub;DB;DB;sub;DB;sub;DB;sub;DB;$/); + $r = runperl( + switches => [ '-Ilib', '-f', '-d:-switchd=a,42' ], + progfile => $filename, + args => ['4'], + ); + like($r, qr/^sub;unimport;DB;sub;DB;DB;sub;DB;sub;DB;sub;DB;$/); } # [perl #71806]