Just a little update on my progress in case anyone is still interested ;)

I installed Class::DBI , and created an "Event" object to test with. The savings in the amount of code that I had to write was tremendous:

package Event; use base qw(Class::DBI); # Tell Class::DBI a little about yourself Event->table('events'); Event->columns('All', qw( name given_by location date time ) ); Event->columns('Primary', 'name'); Event->set_db('Main', 'dbi:mysql:xxx', 'xxx', 'xxx' ); 1;
But what I gain in simplicity, I lose a bit in performance:
#!/usr/bin/perl -w use DBI; use Guest; use Event; use Benchmark; # Connect to database my $dbh = DBI->connect( "dbi:mysql:web_stuff", 'xxx', 'xxx' ) or die "Can't connect to MySQL database: $DBI::errstr\n"; # Need to benchmark these solutions sub modify_event { ### Test (query) the Event object my $this_event = Event->retrieve('Party'); ### Test (modify) the Event object $this_event->time('9:00 PM'); $this_event->commit; } sub modify_guest { # Fetch One my $last_name = "Rodriguez"; my $q_last_name = $dbh->quote($last_name); my $first_names = "Alex"; my $q_first_names = $dbh->quote($first_names); my ($add,$city,$state,$zip,$cnt) = $dbh->selectrow_array( "SELECT address, city, state, zip, est_count FROM guest_list WHERE last_name = $q_last_name AND first_names = $q_first_names" ); my $guest = new Guest ($last_name,$first_names, $add,$city,$state,$zip,$cnt); #### Test Update $guest->state("TX"); $guest->update($dbh); } timethese(1000, {modify_event => 'modify_event()', modify_guest => 'modify_guest()' }); $dbh->disconnect(); exit;
Results:
Benchmark: timing 1000 iterations of modify_event, modify_guest... modify_event: 7 wallclock secs ( 5.25 usr + 0.26 sys = 5.51 CPU) modify_guest: 5 wallclock secs ( 2.89 usr + 0.15 sys = 3.04 CPU)

In reply to Re: Object Oriented Pattern help by thefid
in thread Object Oriented Pattern help by thefid

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.