Re: [Catalyst] Going through tutorial, part 2 and getting error

2008-01-06 Thread Alejandro Imass
Does this give you any clues?
Can't locate MyAppDB/Customer.pm

Ok here is how it goes, I suspect you are using DBIx::Class

app from here on stands for the name your app, of course

You should have a Model class in your lib/app/Model/appDB.pm which
should be based on Catalyst::Model::DBIC::Schema

In this file, you will have config method where you specify the
connection parameters and the actual class that maps you DB objects.
Generally you can use the same name for the actual DB class, but with
another namespace (the actual schema mapper class will usually be
sitting directly in the lib/ directory).

In the schema mapper class, say lib/appDB.pm you will see that it is
based on DBIx::Class::Schema, here you should have a load_classes
method implemented with your tables as such:

# Cargar clases de DBIC
__PACKAGE__-load_classes({
vdcDB = [qw/
  creadores
  vida_creador
  categorias
  sub_categorias
[...]

Each entry will correspond to an individual ORM class in the appDB
subdirectory sitting right there in your main lib directory.

Each ORM class will derive from DBIx::Class directly and implement
your actual M class. Later in you C code you do stuff like:

$c-stash-{subcats_creador} = [$c-model('vdcDB::sub_categorias_creadores')
-search(
 {
 id_creador = $id,
 },
 {
 join = {'sub_categorias' = 
'categorias'},
 prefetch = {'sub_categorias' 
= 'categorias'},
 },
 )];

Which of course will put any Rails or PHP programmer to shame ;-] (in
fact don't know of any other ORM technology that can actually do this)

Here is a sample ORM class for your enjoyment. SPECIAL NOTE: I have
read about autoloading features of DBIx and generating the DB from the
ORM and vice versa. My recommendation is that DBIx::Class is so
powerful that defining you mappings by hand is by far the best method
(besides the fact that is very easy). There is nothing better like
good and sound database modeling (decent normalization, referential
integrity, default values, etc.) and then good and sound MANUAL ORM
mapping. Never try to push the ORM too far, even though DBIx::Class
can handle very complex things, it is usually best to resolve
complicated stuff in the DB with a View or Rule (if you're lucky or
smart enough to be working with PostgreSql ;-] ) If you actually
exploit a REAL ORDBMS (like Postgres, not the fake ones like Oracle)
things with a powerful ORM like DBIx::Class can get pretty
fascinating. Anyway, here's the example:

package vdcDB::sub_categorias;

use base qw/DBIx::Class/;

# Cosas requeridas de DBIC
__PACKAGE__-load_components(qw/PK::Auto Core/);
# Nombre de la tabla
__PACKAGE__-table('sub_categorias');
# Columnas de la tabla
__PACKAGE__-add_columns(qw/
 id
 id_categoria
 nombre
 descripcion
 /);

# Clave primaria
__PACKAGE__-set_primary_key(qw/id/);

# relación clave foránea con categorías
__PACKAGE__-belongs_to(categorias = vdcDB::categorias, 'id_categoria');

# Relación 1..n con sub_categorias_creadores
__PACKAGE__-has_many(sub_categorias_creadores =
'vdcDB::sub_categorias_creadores', 'id_sub_categoria');

1;

Perl. There is no substitute.

Alejandro Imass

P.S. Sorry about the spanish comments.


On Jan 6, 2008 2:59 AM, Andrew [EMAIL PROTECTED] wrote:
 A newbie getting back into perl and decided to start using it w/ Catalyst.

 I'm going through the tutorial, part 2 and modifying it by changing the
 Models, and slightly different presentation, but the structure of the data
 is the same (e.g. instead of a Book object I'm using a Customer object, but
 it's the same in that a Book can have many authors, a Customer can have many
 credit cards). So I'm making the example more applicable to what I'd to use
 it for and basically renaming stuff.

 When I run script/myApp_server.pl I get the following error:
 
 Couldn't instantiate component register::Model::registerModel, Cannot
 load schema class 'registerDB': DBIx::Class::Schema::throw_exception():
 Can't locate MyAppDB/Customer.pm in @INC (@INC contains:
 /mnt/hgfs/mac/Desktop/share/catalyst/webpage/apps/register/script/../lib
 /home/owner/local/lib/perl5 /home/owner/local/share/perl/5.8.8
 /home/owner/local/lib/perl/5.8.8 /home/owner/local/lib /etc/perl
 /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5
 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8
 /usr/local/lib/site_perl .) at (eval 110) line 3.
 Compilation failed in require at
 

[Catalyst] Going through tutorial, part 2 and getting error

2008-01-05 Thread Andrew
A newbie getting back into perl and decided to start using it w/ Catalyst.  

I'm going through the tutorial, part 2 and modifying it by changing the Models, 
and slightly different presentation, but the structure of the data is the same 
(e.g. instead of a Book object I'm using a Customer object, but it's the same 
in that a Book can have many authors, a Customer can have many credit cards). 
So I'm making the example more applicable to what I'd to use it for and 
basically renaming stuff.

When I run script/myApp_server.pl I get the following error:

Couldn't instantiate component register::Model::registerModel, Cannot load 
schema class 'registerDB': DBIx::Class::Schema::throw_exception(): Can't locate 
MyAppDB/Customer.pm in @INC (@INC contains: 
/mnt/hgfs/mac/Desktop/share/catalyst/webpage/apps/register/script/../lib 
/home/owner/local/lib/perl5 /home/owner/local/share/perl/5.8.8 
/home/owner/local/lib/perl/5.8.8 /home/owner/local/lib /etc/perl 
/usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 
/usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl 
.) at (eval 110) line 3.
Compilation failed in require at 
/usr/local/share/perl/5.8.8/Catalyst/Model/DBIC/Schema.pm line 271.
 at script/register_server.pl line 53 at script/register_server.pl line 53
Compilation failed in require at script/register_server.pl line 53.


Could I be running the helper scripts w/ the wrong arguments?  I know I have 
all the dependencies installed since I got the tutorial code from SVN, deployed 
in the same environment and it ran as expected.  I tried redoing it to see if I 
made any syntax mistakes and still same error message.  Any suggestions?  


   
-
Never miss a thing.   Make Yahoo your homepage.___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/