Your new I would factor to something like this:
sub new { my ( $class, %config) = @_; # maybe check arg's bless { "_CONFIG" => \%config }, $class; }
but that is not of too much import.

I would have connect and disconnect warn or die when inappropriately called, i.e. connecting when already connected.

disconnect therefore would undef $self->{_DBH}.

Similiarly I would not be likely to have a connect call inside of the prepare routine. This makes the function name misleading and it just smells. There is a convenience factor but when I find my code having duplicate functionality like this it is a sign of losing track of the logical structure of the program. That I may have forgotten that connect was supposed to be called early on to setup the connection (or vice versa).

There are prettier ways to build your SQL in execute. I am not facile at building up strings of this sort--I find your SQL building to be understandable but error prone.

The continual linkage between $self and the %params might indicate that the object should be smarter. It is not possible to tell from the info you have given.

Be well, rir


In reply to Re: Comments on my code, advices how to improve it. by rir
in thread Comments on my code, advices how to improve it. by techcode

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.