Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Cross-Package/Object Communication

by IOrdy (Friar)
on Aug 21, 2002 at 16:06 UTC ( #191780=note: print w/replies, xml ) Need Help??


in reply to Cross-Package/Object Communication

At the moment I've been writing my first "big" application and I've been structuring my code roughly like yours (2 style) though with a lot more packages and I too would love to know if there is a better solution as it's become increasingly awkward to access all the data my application needs at any one point. My current structure is as follows: Xmlio::Apache::Handler (mod_perl apache handler starts new instance of Xmilo)

Xmilo (main package)
  # inits in order the following and adds returned reference to blessed hash.
  - Xmilo::Config (loads config from XML file and returns reference)
  - Xmilo::DB::mySQL (make DB connection and returns reference)
  - Xmilo::User (checks cookie data against database, uses Xmilo::Cookie to fetch cookie data and returns reference to user info hash)

  # check for an OP code by checking the params added when Xmilo::Apache::Handler started Xmilo. example ?op=new;
  - Xmilo::OP (reads OP directory for all OP classes and checks tha then using a common constructor creates a new instance of the OP and passes everything in the main hash to the OP package)
    - Xmilo::OP::<opcode> (checks that current user has level of access required for module then executes sql statements etc. and parses returned XML with Xmilo::XSLT and returns XHTML to Xmilo)

  # Display returned XML
  Xmilo::Apache::Handler (takes returned XHTML from Xmilo::OP::<opcode> and displayes it vi Xmilo::Apache::Handler)

  # End


Now the problem is my main class will be the only class ever that has all the elements required to create a new Xmilo::Config object so when I need to access config data from Xmilo::Config in say one of the OP codes I have to use $xmilo->{config}->get_value('name');

It's a short example but sometimes I end up with $xmilo->{foo}->{bar}->{foobar}->method(); which just seems wrong.

Is there something fundamental that I too am missing?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://191780]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (1)
As of 2023-02-06 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (36 votes). Check out past polls.

    Notices?