Why using a module now,
when you can do it later...

It all started with a problem...

Preparing the trap

package A;                           package B;

use base 'Exporter';                 use base 'Exporter';
our @EXPORT = qw(call_a);            our @EXPORT = qw(call_b);
use B;                               use A;

sub call_a {                         sub call_b { 
    return if (caller eq 'B');           call_a();
    call_b();                        }
}

1;                                   1;

Why in hell would we do that?

Loading the bomb

test.pl:


    #!/usr/bin/perl

    use strict;
    use warnings;

    use lib ".";
    use A;

    call_a();

Detonating the bomb


    [erwan@mcbk ~/code]$ ./test.pl 
    Undefined subroutine &B::call_a called at B.pm line 7.

(perl 5.8.6 on osx 10.4.9)

Huh??

package A;                           package B;

use base 'Exporter';                 use base 'Exporter';
our @EXPORT = qw(call_a);            our @EXPORT = qw(call_b);
use B;                               use A;

sub call_a {                         sub call_b { 
    return if (caller eq 'B');           call_a(); # error!
    call_b();                        }
}

1;                                   1;

Crawling around for a solution

Let's try using fully qualified names

package A;                           package B;

use B;                               use A;

sub call_a {                         sub call_b { 
    return if (caller eq 'B');           A::call_a();
    B::call_b();                     }
}

1;                                   1;

Crawling around for a solution


    #!/usr/bin/perl

    use strict;
    use warnings;

    use lib ".";
    use A;

    A::call_a();

So...


    [erwan@mcbk ~/code]$ ./test.pl 
    [erwan@mcbk ~/code]$

Crawling around for a solution

Let's try delaying using A...

package A;                           package B;

use base 'Exporter';                 use base 'Exporter';
our @EXPORT = qw(call_a);            our @EXPORT = qw(call_b);

use B;                               sub call_b { 
                                         require "use A";
sub call_a {                             require "import A";
    return if (caller eq 'B');           call_a();
    call_b();                        }
}

1;                                   1;

So...


    [erwan@mcbk ~/code]$ ./test.pl 
    [erwan@mcbk ~/code]$

What about?


    package B;

    use base 'Exporter';
    our @EXPORT = qw(call_b);
    use later A;

    sub call_b {
        call_a();
    }

    1;

And...


    [erwan@mcbk ~/code]$ ./test.pl 
    [erwan@mcbk ~/code]$

:)