Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

how do you include multiple modules using one module

by diabelek (Beadle)
on Feb 25, 2009 at 14:14 UTC ( #746270=perlquestion: print w/replies, xml ) Need Help??

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

Is there any way to include multiple modules using a single module. IE in C, you could have #include "my_common.h" which would have #include "file_a.h", #include "file_b.h"...

In perl, the only thing I can find that is comparable to write a line of code using eval, join and map but that still has to be written in every file.

We're looking for a solution that would let users do "use framework;" to include the whole framework we have written or chunks of it using qw(a b c). In our framework modules, we could use "use framework_common;" to include or common logging, constants, etc files.

  • Comment on how do you include multiple modules using one module

Replies are listed 'Best First'.
Re: how do you include multiple modules using one module
by sweetblood (Prior) on Feb 25, 2009 at 14:29 UTC

      I.e. ToolSet

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: how do you include multiple modules using one module
by weismat (Friar) on Feb 25, 2009 at 14:30 UTC
Re: how do you include multiple modules using one module
by citromatik (Curate) on Feb 25, 2009 at 14:34 UTC

    You can use Filter::Macro:

    package framework use Filter::Macro; use strict; use warnings; use ... .... 1;

    Then, a program or module that says use Filter::Macro will expand lines below use Filter::Macro into their own code

    You can also take a look at Toolkit

    citromatik

Re: how do you include multiple modules using one module
by Anonymous Monk on Feb 25, 2009 at 14:30 UTC
Re: how do you include multiple modules using one module
by doom (Deacon) on Feb 26, 2009 at 20:31 UTC
    Toolkit looks like it may be on the right track... but don't ignore the obvious, this sort of thing works:
    package Module::DemoGroupExport; # doom@kzsu.stanford.edu # 26 Feb 2009 =head1 NAME Module::DemoGroupExport - repaces many "use" statements with one =head1 SYNOPSIS use Module::DemoGroupExport qw( carp croak Dumper mkpath dirname ); my $file = shift; my $loc = dirname( $file ); unless (-d $loc) { carp "Creating $loc..."; mkpath( $loc ) or croak "Could not create $loc: $!"; } =head1 DESCRIPTION Demonstration of a simple strategy for ganging together multiple use statments for many Exporter-based modules into one, so that you can replace many lines of commonly used "use" statements with a single one. Note: automatic exporting is now frowned upon -- better to explicitly state what you want. =head2 EXPORT None by default. =cut use 5.8.0; use strict; use warnings; use Carp qw( carp cluck croak confess shortmess longmess ); use Data::Dumper qw( Dumper ); use File::Path qw( mkpath ); use File::Basename qw( fileparse basename dirname ); use File::Copy qw( copy move ); use Cwd qw( cwd abs_path ); require Exporter; our @ISA = qw(Exporter); our %EXPORT_TAGS = ( 'all' => [ qw( carp cluck croak confess shortmess longmess Dumper mkpath fileparse basename dirname copy move cwd abs_path ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( ); # exported into callers namespace by default. # (don't use this without a very good reason.) our $VERSION = '0.01'; 1; =head1 SEE ALSO o The cpan module L<Toolkit> =head1 AUTHOR Joseph Brenner, E<lt>doom@kzsu.stanford.eduE<gt> =head1 COPYRIGHT AND LICENSE Copyright (C) 2009 by Joseph Brenner This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available. =head1 BUGS None reported... yet. =cut
      Hey, Got the simple solution for the problem. When you declare a common module do not define it as package and dont use any return 1; statement at the bottom. exp: #Code for common.pm use strict; use File; use myCustom::abcmod; .... ... ... #code for calling script use common.pm; that's all no need to define common module as a package. remove the top declaration of package common; and remove the return 1; it will work. thanks.
      Hey, Got the simple solution for the problem. When you declare a common module do not define it as package. exp: #Code for common.pm use strict; use File; use myCustom::abcmod; .... ... ... #code for calling script use common.pm; that's all no need to define common module as a package. remove the top declaration of package common; it will work. thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://746270]
Approved by sweetblood
Front-paged by almut
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2019-08-22 06:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?