Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Did Exporter ever die or issue a warning when it clobbers existing symbols? I think it should
$ perl -MData::Dump::Streamer -MYAML -le ' Data::Dump::Streamer::Dump( + \*Dump ) ' $GLOB1 = \*::Dump; *::Dump = sub { package YAML; use warnings; use strict 'refs'; my $yaml = 'YAML'->new; $yaml->dumper_class($DumperClass) if $DumperClass; return $yaml->dumper_object->dump(@_); }; $ perl -MData::Dump::Streamer -mYAML -le ' Data::Dump::Streamer::Dump( + \*Dump ) ' $GLOB1 = \*::Dump; *::Dump = sub { package Data::Dump::Streamer; use warnings; use strict 'refs'; my $obj; if (blessed($_[0]) and blessed($_[0]) eq 'Data::Dump::Stre +amer') { $obj = shift @_; } if (@_) { if (defined wantarray and not wantarray) { $obj ||= 'Data::Dump::Streamer'->new; $obj->_make_args(@_); return $obj; } else { $obj ||= 'Data::Dump::Streamer'; return $obj->Data(@_)->Out; } } else { if ($obj) { return $obj->Out; } else { return 'Data::Dump::Streamer'->new; } } }; $ pmvers Data::Dump::Streamer YAML Exporter Data::Dump::Streamer: 2.09 YAML: 0.70 Exporter: 5.63

Replies are listed 'Best First'.
Re: Exporter collision detection
by ikegami (Patriarch) on Sep 28, 2009 at 15:17 UTC

    It does.

    >type ModA.pm package ModA; use Exporter qw( import ); @EXPORT = qw( foo ); sub foo { print __PACKAGE__, "\n" } 1; >type ModB.pm package ModB; use Exporter qw( import ); @EXPORT = qw( foo ); sub foo { print __PACKAGE__, "\n" } 1; >perl -we"use ModA; use ModB;" Subroutine main::foo redefined at c:/Progs/perl5101/lib/Exporter.pm li +ne 67. at -e line 1

    You need to turn on warnings if you want warnings.

      I don't think that is good enough because it doesn't always work
      $ perl -MData::Dump::Streamer -MYAML -wle 1 $ perl -MData::Dump::Streamer -MYAML -Wle 1 Use of uninitialized value $ENV{"B_UTILS_TRACE"} in addition (+) at /u +sr/local/lib/perl5/site_perl/5.10.1/x86_32-linux/B/Utils.pm line 72. Subroutine main::Dump redefined at /usr/local/lib/perl5/5.10.1/lib/Exp +orter.pm line 67. at -e line 0 Name "Exporter::CARP_NOT" used only once: possible typo at /usr/local/ +lib/perl5/5.10.1/lib/Carp/Heavy.pm line 304. Name "main::CARP_NOT" used only once: possible typo at /usr/local/lib/ +perl5/5.10.1/lib/Carp/Heavy.pm line 304.