Here is what I would like to do:
use Moose; with 'orm'; has table => ( name => 'my_database_table' );
Given a schema like so:
+--------------------+------------------+
| Field              | Type             |
+--------------------+------------------+
| id                 | int(10) unsigned |
| field1             | varchar(32)      |
| field2             | varchar(32)      |
+--------------------+------------------+
My ORM.pm role would parse this line:
has table => ( name => 'my_database_table' );
And effectively produce a Moose object that would be essentially the same as explicitly coding:
use Moose; has id => ( is => 'ro', isa => 'Int' ); has field1 => ( is => 'rw', isa => 'Str' ); has field2 => ( is => 'rw', isa => 'Str' );
The idea, however, is not to produce a text file ... but rather an in-memory object. I could always use Perl to create the text file for me, i.e. this one liner:
mysql -e 'desc my_database_table' | cut -f1 | perl -ple '$_=qq{has $_ +=> ( is => "rw" );}'
I have searched for others who might have this same desire, but so far no real luck. I imagine will need to use Moose::Exporter or possibly Moose::Util::MetaRole. I really don't know.

So, my question isn't "can someone do this for me?" but rather ... are there any Moose heads out there who might be able to sketch out a rough game plan for solving this problem. Personally, I am starting to believe this is more trouble than it is worth. But please remember -- I am not looking for a fully functional ORM that handles complex relationships -- just some sugar for preventing having to spell out the names of the columns in the table for now. I myself am not sure this is a great idea. :)

Thanks in advance.


In reply to Moose + ORM by Anonymous Monk

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.