[Chicago-talk] Is there a way to simplify including multiple .pm files?

Joshua McAdams joshua.mcadams at gmail.com
Fri Mar 14 11:20:25 PDT 2008


>  http://search.cpan.org/~dconway/Toolkit-0.0.2/

Not sure if I like this solution either, but it works:

--(0)> cat x.pl
use warnings;
use strict;
use XY;

print $variable_in_x, "\n";
print $variable_in_y, "\n";

--(0)> cat XY.pm
package XY;

use warnings;
use strict;

sub import {
    my ($caller) = caller;
    eval "
package $caller;
use X;
use Y;
1;
" or die $!;
}

1;

--(0)> cat X.pm
package X;

use warnings;
use strict;

our $variable_in_x = 'this came from X.pm';

our @EXPORT = qw($variable_in_x);

use base 'Exporter';

1;

--(0)> cat Y.pm
package Y;

use warnings;
use strict;

our $variable_in_y = 'this came from Y.pm';

our @EXPORT = qw($variable_in_y);

use base 'Exporter';

1;


More information about the Chicago-talk mailing list