hmadhi has asked for the wisdom of the Perl Monks concerning the following question:

I need guidance on creating Classes that will interact with Oracle/mysql database.

The basic requirements would be to :

1. connect/disconnect to/from oracle/mysql database.
2. query tables and return data.
3. process data and create relevant html reports.

I am using Moose and would like to create Objects within the Moose framework. The projects I am involved with require these tasks to be performed regularly and I want to start making use of OOP to take advantage of the 'write code once' philosophy.
Your assistance will be highly appreciated.
  • Comment on Creating Moose Classes to Interact with mySQL/Oracle

Replies are listed 'Best First'.
Re: Creating Moose Classes to Interact with mySQL/Oracle
by stvn (Monsignor) on Feb 22, 2011 at 14:56 UTC

    I would suggest DBIx::Class, Fey::ORM or Rose::DB::Object. They are all excellent modules, fully OOP and all will do everything you want and more, allowing for your application to grow. However, if you feel you want to write this from scratch here are a few CPAN modules you will want to look at.

    1. connect/disconnect to/from oracle/mysql database.

    Obviously you need DBI, but I also recommend using DBIx::Connector to manage your DB connections, it is battle tested code that has been extracted from DBIx::Class and will just make your life easier.

    2. query tables and return data.

    You really don't need anything more then DBI to do this, but you might want to look at Fey and in particular Fey::SQL as it is a nice way to manage your tables and have proper SQL generated for you. To make things a little easier when querying, you can take a look at FeyX::Active, which just wraps Fey::SQL (see the SYNOPSIS for details)

    3. process data and create relevant html reports.

    Well you will probably want Template to do HTML templating to create your reports with, and if you need to do any charts or graphs, I highly recommend Chart::Clicker. For data processing, well that is what Perl does best, but you might want to check out a few really useful CPAN modules like List::AllUtils and Data::Visitor::Callback.

    -stvn
Re: Creating Moose Classes to Interact with mySQL/Oracle
by Your Mother (Archbishop) on Feb 22, 2011 at 14:46 UTC

    Perl has several first rate ORMs/DB-kits on the CPAN. All of which will be better than anything you will be be able to write by yourself. Unless you are a DB/DBD/DBI expert, or doing exploration for fun or learning exercises, writing your own ORM is a big mistake.

    Fey and KiokuDB are the most natively Moosey. Update: "natively Moosey" isn't an endorsement for "best." Also Rose::HTML::Objects makes the full Rose suite the closest match for the 3 tasks you listed. Template or Mason or any of a few other template kits would serve fine with any of the ORMs too.

Re: Creating Moose Classes to Interact with mySQL/Oracle
by jethro (Monsignor) on Feb 22, 2011 at 14:46 UTC

    There are already a lot of modules that do this (many without Moose though), for example DBIx::Class and Rose::DB. You could either just use them or provide a wrapper around them. Or you could look at their interface and how they do it and implement the parts that you like in Moose