Hi All,
  I'm about to split up my database module into 3 or 4 smaller more specific modules. At the moment I'll calling all the routines as methods, such as:-
package database_mod; use DBI; our $dbh; sub connect { $dbh->### DBI connect }#sub sub add_user { $dbh->### DBI SQL, ETC }#sub sub report { $dbh->### ETC }#sub
Using it with:-
use database_mod; database_mod::connect(); database_mod::add_user(); ### etc

Now I'm thinking if I split it up and keep using this method things will get messy.
package database_mod; use DBI; our $dbh; sub connect { $dbh->### DBI connect }#sub package database_user; sub add_user { $database_mod::dbh->### DBI SQL, ETC }#sub package database_report; sub report { $database_mod::dbh->### ETC }#sub
Using it with:-
use database_mod; use database_user; database_mod::connect(); database_user::add_user(); ### etc

So I'm wondering if now is a good time to switch the database system to OO Perl? I've not really written much at all in the way of OO Perl. But I'm guessing it'd be something like:-
package database_mod; use DBI; sub new { ### $class, $self, bless n all. }#sub sub connect { $self->### DBI connect }#sub package database_user; use base database_mod; sub add_user { $self->### DBI SQL, ETC }#sub package database_report; use base database_mod; sub report { $database_mod::dbh->### ETC }#sub
Using it with:-
use database_mod; use database_user; my $db = new database_mod; $db->connect(); $db->add_user(); $db->report(); ### etc

Would this be the best way to go? Certainly looks a lot cleaner, but would it be OO for the sake of OO? Have I got the OO package logic right? Or should I stick to using methods like before?
I'm sure many of you have a lot more OO Perl experience than me.


Lyle

In reply to Time to upgrade tp OO Perl? by cosmicperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.