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

This is Ikegami's example I'm working off of, http://www.perlmonks.org/?node_id=383504#mutual_use, demonstrates how to use exporter. I create 3 files: sand_kidA.pm, sand_kidB.pm, and sand_parent.pl.

In this example, I have provided print methods to the sibling's variable inside opposite modules for the sake of demonstration of Exporter only. I am trying to get it so that the 'subroutine redefined' warning is appeased, even if the correct result is printed. On a higher level, the problem I am trying to solve is modules that reference each other. I am running on linux, perl 5.8.8. Please do not suggest turning the warnings off. Thanks in advance.

sand_parent.pl
#!/usr/bin/perl use sand_kidA qw(get_a); use sand_kidB qw(get_b); print get_a(); print get_b();
sand_kidA.pm
#!/usr/bin/perl use strict; use warnings; package sand_kidA; BEGIN { our @ISA = qw( Exporter ); our @EXPORT_OK = qw(set_a get_a print_b); # symbols to export on +request require Exporter; } use sand_kidB qw(get_b); my $a = 5; sub print_b { print get_b(); } sub set_a { my $val = shift; $a = $val; } sub get_a { return $a; } 1;
sand_kidB.pm
#!/usr/bin/perl use strict; use warnings; package sand_kidB; BEGIN { our @ISA = qw( Exporter ); our @EXPORT_OK = qw(set_b get_b print_a); # symbols to export on +request require Exporter; } use sand_kidA qw(get_a); my $b = 6; sub print_a { print get_a(); } sub set_b { my $val = shift; $b = $val; } sub get_b { return $b; } 1;

Replies are listed 'Best First'.
Re: Exporter module help/example
by ikegami (Patriarch) on Nov 26, 2007 at 17:59 UTC

    I don't get any such warnings. And I don't see anything that should cause the warning you describe. Could you provide the exact error message? Are you sure the .pm files you think are being loaded are actually the ones being loaded?

    >perl -lw sand_parent.pl 5 6 >perl -v This is perl, v5.8.8 built for MSWin32-x86-multi-thread (with 25 registered patches, see perl -V for more detail)
    $ perl -lw sand_parent.pl 5 6 $ perl -v This is perl, v5.8.4 built for i386-linux-thread-multi
      perl -c sand_kidB.pm
      Subroutine print_a redefined at sand_kidB.pm line 19. Subroutine set_b redefined at sand_kidB.pm line 24. Subroutine get_b redefined at sand_kidB.pm line 30.


      Same for kid A.
        perl's argument is a Perl script. sand_kidB.pm is not a Perl script. You mean
        perl -c -e'use sand_kidB'
        or
        perl -c -Msand_kidB -e1