/* 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);
[ 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
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.
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 }
# This test depends on t/lib/Devel/switchd*.pm.
-plan(tests => 4);
+plan(tests => 5);
my $r;
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,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;$/);
+ $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,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;sub<Bar::bar>;DB<Bar,$::tempfile_regexp,2>;$/);
}
# [perl #71806]