Hello,
I have a fairly basic question as I'm not quite sure I get the big picture on modules. Maybe someone can give me a better picture.
I'll use 3 example modules: Main, Main::Config, and Main::HTML
Main is the main object which contains the variables needed (like $main->{config}) which it needs to share with HTML, so HTML can read $main->{config}->{dbhost} for example.

This is how I understand it...

So in Main, I say main is an exporter so I can give the allowance for other modules to import $main. (I understand EXPORT_OK, but what is EXPORT for? and if there's nothing needed to EXPORT, then is that line necessary?)
------------Main.pm--------------------
BEGIN {
       use Exporter ();

       @Main::ISA = qw/Exporter/;
       @Main::EXPORT = qw();
       @Main::EXPORT_OK = qw/ $main /;
}

use Main::Config;
use Main::HTML qw( get_template $main )

sub new{
      #for simplification I'll leave the regular class/bless stuff out
      $self->{config}= Main::Config->new();
}
-------------------------------------------------------------------------

The Main::Config module just has a simple new function which sets $self->{dbname}, etc. and returns $self.

Then Main::HTML I want to be able to interact with all of the $main variables including the config. So I have this:
------------HTML.pm-----------------------------------------------------
BEGIN {
       use Exporter ();
       @Main::HTML::ISA = qw(Exporter);
       @Main::HTML::EXPORT = qw();
       @Main::HTML::EXPORT_OK = qw(get_template $main);

}

use Main qw( $main );

sub get_template{
 $dbname = $ems->{config}->{'dbname'};
  print "DB name is $dbname\n";
}

-----------------------------------------------------------------
But dbname doesn't print out. So I guess my understanding of how the importing exporting works.
This is what I want, I think...
---------------------------------------
| Main                            -uses-----   |
|                                     | HTML |    |
|  $main        <---------- | \$main |    |
|                                     ----------   |
--------------------------------------
Any words of wisdom?
Thanks!
Tony

Reply via email to