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;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.