in reply to what is a propper way to make a chunk of data accessible to all my packages for retrieval and modification ?

Yes. How about Class::DBI? It combines object definition and storage, not blazingly fast but nice for Webapp/*.pm.

But first yes, you can use class data or make a singleton class (singleton means there can only be one instance, which you don't necessarily want to have happen). You can store data in the class Bathroom itself (not in an instance of a given Bathroom object). This is for example easy to do with the "-static" option if you are using Class::MethodMaker. (which I am using now for a new soap project.. anybody have a better suggestion?)

Or check out Programming Perl, Tom's OO on class data or perltoot (scroll to class data).
The first link is easy to understand, especially about a decision you have to make when you start subclassing (i.e. does the data stick around or not)

So about Class::DBI.

Bathroom.pm maps to the bathroom table in your db.
Toilets.pm will map to the toilets table. DBI is being used so you don't need a real database, a database in a file or in memory is also useable.
So joetoilet and janetoilet are one row each in the toilets table, and the bathroom table has a toilet column, with the id of a toilet in the toilet table. So to get a toilet object for a given bathroom you say

my $mybathroom = Webapp::Bathroom->retrieve(id => 5); my $mytoilet = $mybathroom->toilet; or my $plunger = $mybathroom->toilet->plunger;
If you want to allow more than one toilet per bathroom, that is fine you can do this with Class::DBI using has_a and the neat thing is that a relation will return a full object. Check out this code from an old project of mine (I used a separate link table but you could just check the toilets table for the bathroom it has_a too):

In MgrCompanyLink.pm (which has fields id, company and manager): WebApp::MgrCompanyLink->has_a(company => 'WebApp::Company'); WebApp::MgrCompanyLink->has_a(manager => 'WebApp::Manager'); In Manager.pm (which has fields id and person): WebApp::Manager->has_a(person => 'WebApp::Person'); WebApp::Manager->has_many('companies', [ 'WebApp::MgrCompanyLink' => 'companyid'], 'mgrid', { order_by => 'companyid' } );
This way you can get an array of companies from the companies method of a manager, and each manager has a person field (id of a record in the person table) which returns a Person.pm object. You can write custom queries too.

Hope this helps. Reading the perltootc probably will answer what you're asking.

  • Comment on Re: what is a propper way to make a chunk of data accessible to all my packages for retrieval and modification ?
  • Select or Download Code