management has decided that we will be refactoring the codebase of our mod_perl web app. i'm looking at our database access methods and trying to decide whether to re-structure them. here's the code i've inherited.
module layout:
EG/DB.pm
EG/DB/
EG/DB/Access.pm
EG/DB/Clients.pm
EG/DB/Vendors.pm
EG/DB/Employees.pm
EG/Example.pm
relevant code from modules:
package EG::DB.pm;
use DBI;
sub new { db connection happens here }
sub commit {...}
package EG::DB::Access.pm
use base 'EG::DB::Clients';
use base 'EG::DB::Vendors';
use base 'EG::DB::Employees';
package EG::DB::Clients;
use base 'EG::DB';
sub get_client_id_for_username { ... }
package EG::Example;
use EG::DB::Access;
my $dbh = EG::DB::Access->new();
my $client_id = $dbh->get_client_id_for_username($client_username);
the good:
- none of the db modules need to know about each other, they only know about EG::DB.
- none of the client code needs to know about the specific modules, all methods are accessed through EG::DB.
- if methods move, for some strange reason, from one module to another, no calling code needs to be updated
- adding new db modules only necessitates a change to EG::DB::Access (an additional 'use base ...') and new 'use' statements don't need to be added to any other existing modules.
not so good:
- for certain calls, search path seems longer than is necessary, so when client code calls a db method:
EG::Example->get_client_id_for_username()
searches:
EG::DB::Access (no match)
EG::DB::Clients (no match)
EG::DB::Vendors (no match)
EG::DB::Employee (match)
and is even longer for the few methods in EG::DB such as
when client code calls "new" or "commit" method:
EG::DB::Access (no match)
EG::DB::Clients (no match)
EG::DB::Vendors (no match)
EG::DB::Employee (no match)
EG::DB (match)
so is it bad enough to warrant re-structuring? is the longish search path that expensive with mod_perl or should we just leave it alone. Does it really buy us that much convenience?
Should Access.pm be rolled into EG::DB to eliminate one additional search level? Thanks for any opinions.
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.