David Christensen: > Here is a contrived example that shows circular modular dependency > without circular subroutine dependency:
In this particular case, I'd move subs bar2 and foo2 to another module FooBar.pm, and have Foo.pm and Bar.pm import those subs from FooBar.pm instead: > 2016-10-19 11:05:08 dpchrist@t7400 ~/sandbox/perl/circular-dependency > $ cat Foo.pm > package Foo; > use strict; > use warnings; > require Exporter; > our @ISA = qw( Exporter ); > our @EXPORT = qw( foo1 foo2 ); > use Bar; > sub foo1 { print "foo1\n"; bar2(); } > sub foo2 { print "foo2\n"; } package Foo; use strict; use warnings; require Exporter; our @ISA = qw( Exporter ); our @EXPORT = qw( foo1 ); use FooBar; sub foo1 { print "foo1\n"; bar2(); } > 2016-10-19 11:05:10 dpchrist@t7400 ~/sandbox/perl/circular-dependency > $ cat Bar.pm > package Bar; > use strict; > use warnings; > require Exporter; > our @ISA = qw( Exporter ); > our @EXPORT = qw( bar1 bar2 ); > use Foo; > sub bar1 { print "bar1\n"; foo2(); } > sub bar2 { print "bar2\n"; } package Bar; use strict; use warnings; require Exporter; our @ISA = qw( Exporter ); our @EXPORT = qw( bar1 ); use FooBar; sub bar1 { print "bar1\n"; foo2(); } # FooBar.pm package FooBar; use strict; use warnings; require Exporter; our @ISA = qw( Exporter ); our @EXPORT = qw( foo2 bar2 ); sub foo2 { print "foo2\n"; } sub bar2 { print "bar2\n"; } Deciding if bar2 and foo2 will go together or separatedly depends mostly on the problem at hand, so I'm suggesting the shortest path (i.e. together) with the information I have. Cheers, Alex