[Raleigh-talk] Sharing data between modules

Trevor Little trevormg19 at gmail.com
Fri Dec 19 07:26:30 PST 2008


Andrew,
     I'm not sure I've got all the details right. When you say that the  
modules are "layed out like this", what to the arrows signify? Is that  
inheritance, or one module calling methods in another, or what? Sorry if  
I'm being dense. If it's inheritance and your creating data in a  
constructor of a parent Class that you want to be available in child  
classes it seems you could store it in the object as instance data. But  
I'm guessing that that's not the situation or there's a reason why that  
won't work for you. One thing I often forget is that every module can  
access any data in any other module (well, for the most part) by using the  
full name-space (ie $Glovebox::some_variable). It's not always pretty, but  
sometimes it a better alternative to exporting stuff and polluting  
name-spaces. Anyway, I'm not sure if any of that is helpful, cause I feel  
I might have misunderstood what you're asking. I'll be in #raleigh.pm on  
irc.perl.org today (along with a bunch smarter people) if you want to pop  
in and explain in more detail.

Trevor

On Fri, 19 Dec 2008 10:04:15 -0500, Andrew Rankin <andrew at eiknet.com>  
wrote:

> Hi All.
>
> I have question about sharing some data between some Perl modules and
> the best way to accomplish it.
>
> I have written an application for tracking our IBM bladecenters and
> Xen VMs, basically it gives you a list of "containers" (the Domain-O
> and the Blade centers) and lets you list the servers and information
> on those servers within that container:
> http://eiknet.com/glovebox01.png.  The backend is perl (obviously :)).
>  My issues is that I have a set of data that I'd like to share with
> the applications perl modules, they are layed out like this:
>
>                                                   ->
> Interfaces::VIRT.pm -> Shared::Library & DB
> AJAX -> index.pl -> Glovebox.pm -> Interfaces::SNMP.pm ->  
> Shared::Library & DB
>                                                   -> Shared::Library.pm
>                                                   -> DB
>
> Within Glovebox.pm's new() I open a database connection, collect the
> cgi paramaters, a list of interfaces and open the shared library.
> Which looks something like this:
>
> $VAR1 = {
>                  'interfaces' => {
>                                    'bladecenters' => {
>                                                        'deldev' => '0',
>                                                        'name' =>
> 'BladeCenter SNMP',
>                                                        'id' => '1',
>                                                        'class' =>
> 'Glovebox::Interface::SNMP',
>                                                        'type' =>  
> 'bladecenters',
>                                                        'enabled' => '1'
>                                                      },
>                                    'virt' => {
>                                                'deldev' => '1',
>                                                'name' => 'Xen Dom-0',
>                                                'id' => '2',
>                                                'class' =>
> 'Glovebox::Interface::VIRT',
>                                                'type' => 'virt',
>                                                'enabled' => '1'
>                                              }
>                                  },
>                  'db' => {
>                            'database' => 'systems',
>                            'lock_id' => 8797996,
>                            'db_user' => 'theuser',
>                            'dsn' =>  
> 'DBI:mysql:database=systems;host=localhost',
>                            'db_hostname' => 'localhost',
>                            'dbh' => bless( {}, 'DBI::db' ),
>                            'db_password' => 'notreallythepw'
>                          },
>                  'DevLib' => bless( {
>                                       'db' => {
>                                                 'database' => 'systems',
>                                                 'lock_id' => 7291450,
>                                                 'db_user' => 'theuser',
>                                                 'dsn' =>
> 'DBI:mysql:database=systems;host=localhost',
>                                                 'db_hostname' =>  
> 'localhost',
>                                                 'dbh' => bless( {},  
> 'DBI::db' ),
>                                                 'db_password' =>
> 'notreallythepw'
>                                               },
>                                       'container' => undef
>                                     }, 'Glovebox::Shared::DevLib' ),
>                  'param' => {
>                               'type' => 'virt'
>                             }
>                };
>
>
> I'd like to share that data between all the modules to avoid the
> multiple database connections and multiple shared library's being
> opened. Whats the best way of doing this?  So far I've had suggested
> using Exporter or defining a variable using 'our' in Glovebox.pm and
> just referencing back to it.  Thoughts?
>
> - Andrew Rankin
> _______________________________________________
> Raleigh-talk mailing list
> Raleigh-talk at pm.org
> http://mail.pm.org/mailman/listinfo/raleigh-talk




More information about the Raleigh-talk mailing list