[Catalyst] Setting up CDBI::Sweet and more..

Bernard FRIT bernard.frit at gmail.com
Mon Aug 8 11:48:32 CEST 2005


Hi,

I'm trying to use CDBI::Sweet within Catalyst and as there's no helper 
for CDBI::Sweet I don't exactly know where and how to put things together.

1. I have a simple working Catalyst app and a simple working CDBI::Sweet app
using the same database.

I have :
MyApp/lib/MyApp/M/CDBI.pm
MyApp/lib/MyApp/M/CDBI/
MyApp/lib/MyApp/M/CDBI/...(my tables).pm

Should I need ? :
MyApp/lib/MyApp/M/CDBI/Sweet.pm
MyApp/lib/MyApp/M/CDBI/Sweet/
MyApp/lib/MyApp/M/CDBI/Sweet/...(my tables).pm

With Sweet.pm :

package MyApp::M::CDBI::Sweet;

use strict;
use base 'Catalyst::Model::CDBI::Sweet';

__PACKAGE__->connection('dbi:mysql:MyDB:localhost','user,'pass');

and for each table

package MyApp::M::CDBI::Sweet::MyTable ;

__PACKAGE__->table('MyTable');
__PACKAGE__->columns(Essential => qw/Id Col1 Col2/);

2. I want to set up things for each table within a YAML file that way :

--- #YAML:1.0
list:
  items_per_page: 16
  current_page: 4
  order_by: Col1
  columns: Col1 Col2 Col4 
  template: list.tt
  mappings:
    Col1: text_to_display.
    Col2: Text....
    Col3: Text.....
    ....
edit:
  template: edit.tt
  mappings:
    Col1: other_text_to_display.
    Col2: Text....
    Col3: Text.....
    ....    	
   
>From a best practice point of view where is the best place to put the loading
and vars init code for each table :
- inside MyApp::M::CDBI::Sweet::MyTable ?
- inside MyApp::C::MyTable ? But where ? Within begin or auto ?
- inside MyApp::V::TT ? But how ?
- somewhere else ?

3. And last is it "good practice" to use such a YAML file to set up
table views ?
    
Thanks in advance.
--
Bernard FRIT



More information about the Catalyst mailing list