One possibility is using another module from the POOP group Ovid mentioned earlier: SPOPS. Here's some sample code for you:

#!/usr/bin/perl use strict; use DBI; use SPOPS::Initialize; my ( $DB ); sub My::Sample::global_datasource_handle { unless ( $DB ) { $DB = DBI->connect( 'DBI:mysql:sample', 'me', 'pass' ) || die "Cannot connect: $DBI::errstr"; $DB->{RaiseError} = 1; } return $DB; } sub dump_objects { my ( $object_list ) = @_; foreach my $object ( @{ $object_list } ) { print <<DUMP; a: $object->{a} b: $object->{b} c: $object->{c} d: $object->{d} DUMP } } { my %config = ( sample => { class => 'My::Sample', isa => [ 'SPOPS::DBI::MySQL', 'SPOPS::DBI' ], field => [ 'a', 'b', 'c', 'd' ], id_field => 'a', base_table => 'sampletable', }, ); SPOPS::Initialize->process({ config => \%config }); # Create a new object and save it: my $new_object = My::Sample->new({ a => 15, b => 'Smithson', c => 0.389, d => 'Arf!' }); $new_object->save; # Grab an existing object and modify a field my $saved_object = My::Sample->fetch( 15 ); $saved_object->{d} = 'Quack!'; $saved_object->save; # Grab all the objects my $all_objects = My::Sample->fetch_group({ order => 'a' }); dump_objects( $all_objects ); # Grab some of the objects my $some_objects = My::Sample->fetch_group({where=>'b LIKE ?', value=>['smith%']}); dump_objects( $some_objects ); }

There are tons of other things you can do -- relating objects to one another, giving your object custom behaviors, setting rules so that you can ensure the data going into the database conforms to your business logic, just to name a couple -- but this gives you a brief idea.

Chris
M-x auto-bs-mode


In reply to Re: OO Perl and Design Issues by lachoy
in thread OO Perl and Design Issues by jonjacobmoon

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.