It's not on CPAN yet (waiting for PAUSE id), but you might want to check out SPOPS: Simple Perl Object Persistence with Security. Here's a simple example using DBI (just swiping one of the eg/ files from the distribution):

#!/usr/bin/perl use strict; use DBI; use SPOPS::Configure::DBI; use Data::Dumper qw( Dumper ); # Change these lines as needed (test is normally # setup for MySQL tho...) my $DBI_DSN = 'DBI:mysql:test'; my $DBI_USERNAME = ''; my $DBI_PASSWORD = ''; my $db = DBI->connect( $DBI_DSN, $DBI_USERNAME, $DBI_PASSWORD ) || die "Cannot connect! Error: $DBI::errstr"; $db->{RaiseError} = 1; my $fb_table = <<'SQL'; CREATE TABLE fatbomb ( fatbomb_id int not null auto_increment, name varchar(100) null, calories int null, cost varchar(10) null, servings smallint null default 15, primary key ( fatbomb_id ) ) SQL $db->do( $fb_table ); my $spops = { fatbomb => { class => 'My::ObjectClass', isa => [ qw/ SPOPS::DBI::MySQL SPOPS::DBI / ], field => [ qw/ fatbomb_id calories cost name servings / +], base_table => 'fatbomb', id_field => 'fatbomb_id', skip_undef => [ qw/ servings / ], sql_defaults => [ qw/ servings / ], }, }; SPOPS::Configure::DBI->process_config({ config => $spops, require_isa => 1 }); My::ObjectClass->class_initialize; my $object = My::ObjectClass->new; $object->{calories} = 1500; $object->{cost} = '$3.50'; $object->{name} = "Super Deluxe Jumbo Big Mac"; my $fb_id = eval { $object->save( { db => $db } ) }; if ( $@ ) { my $ei = SPOPS::Error->get; die "Error found! ($@) Error information:\n", "System Message: $ei->{system_msg}\n", "Extra Stuff: $ei->{extra}->{sql}\n", "$ei->{extra}->{values}\n"; } print "Object saved ok!\n", "Object ID: $fb_id\n", "Servings: $object->{servings}\n"; undef $obj; my $new_obj = eval { My::ObjectClass->fetch( $fb_id ) }; if ( $@ ) { die "Error found! ($@) Error information:\n", "System Message: $ei->{system_msg}\n", "Extra Stuff: $ei->{extra}->{sql}\n", "$ei->{extra}->{values}\n"; print "Object fetched ok!\n", "Object ID: $new_obj->{fatbomb_id}\n", "Servings: $new_obj->{servings}\n"; # Uncomment the next line if you want to see the contents of the table # after the test has run $db->do( 'DROP TABLE fatbomb' ); $db->disconnect;

This is a really simple example and doesn't show you security, the ability to write 'rulesets' which apply logic across disparate objects, and more.

Currently there are only DBI 'drivers' for MySQL and Sybase (ASE/ASA -- which also includes using MS SQL Server thru DBD::ODBC), but others are very easy to write -- basically just specifying how a DBD retrieves unique primary key values (autoincrement, key pool, sequences, etc.) and whether it knows how to quote data with a DBI SQL_TYPE hint.

Want to know more? Check out the README or download the code.


In reply to Re: DBIx modules by lachoy
in thread DBIx modules by Penfold

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.