Hi,
I have a question regarding modules. I am learning Perl, slowly. For a project I am creating modules and classes, but something just doesn't feel right.
Currently, they're all interdependent. For example, one class handles sessions, a module contains misc subroutines, but each requires that the database class has been invoke so that they can call
$main::db->query($sql);.
Something just feels wrong... is that the proper way of going about it? I have considered starting up the database individually in each module, but that would cause the server to do a lot of extra work, and would result in me doing extra work too if I changed the password or something.
What
is the right way of creating classes and modules which "depend" on other classes and modules?
Thanks
Oh. Duh. I'd never really thought of passing along an object as a parameter. Is this an example of modules working "nicely" with each other? It just hit me while rereading your responses (and made me feel very stupid in the process :D !).
salazar: Question: If you pass an object as a parameter to a sub, can that sub access that object's properties and methods? e.g., my $obj = shift; $obj->active( time());, where active is a get-set method of $obj. Does this work?
tye: of course
salazar: -.-X
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.