[Catalyst] creating a model

Hermida, Leandro Leandro.Hermida at fmi.ch
Fri Dec 22 10:19:15 GMT 2006


> From: Octavian Rasnita [mailto:orasnita at gmail.com] 
> Sent: Friday, December 22, 2006 20:35
> Subject: [Catalyst] creating a model
> 
> Hi,
> 
> I have tried creating a model using:
> 
> perl script/tranzactiibursiere_create.pl model Intranet DBIC 
> DBI:mysql:database=intranet root
> 
> The result shown was:
> 
> exists "E:\web\TranzactiiBursiere\lib\TranzactiiBursiere\Model"
> exists "E:\web\TranzactiiBursiere\t"
> This module has been deprecated in favor of 
> Catalyst::Model::DBIC::Schema at 
> D:/usr/site/lib/Catalyst/Helper/Model/DBIC.pm line 45.
> created 
> "E:\web\TranzactiiBursiere\lib\TranzactiiBursiere\Model\Intranet.pm"
> created 
> "E:\web\TranzactiiBursiere\lib\TranzactiiBursiere\Model\Intranet"
> created
> "E:\web\TranzactiiBursiere\lib\TranzactiiBursiere\Model\Intran
et\Analize.pm"
> created
> "E:\web\TranzactiiBursiere\lib\TranzactiiBursiere\Model\Intran
et\BvbStiri.pm"
> exists "E:\web\TranzactiiBursiere\t"
> exists "E:\web\TranzactiiBursiere\t\model_Intranet-Analize.t"
> exists "E:\web\TranzactiiBursiere\t"
> exists "E:\web\TranzactiiBursiere\t\model_Intranet-BvbStiri.t"
> 
> So it seems that the program found the 2 tables from my 
> database, and created the following files:
> 
> Model/Intranet.pm:
> 
> package TranzactiiBursiere::Model::Intranet;
> 
> use strict;
> use base 'Catalyst::Model::DBIC';
> 
> __PACKAGE__->config(
>     dsn           => 'DBI:mysql:database=intranet',
>     user          => 'root',
>     password      => '',
>     options       => {},
>     relationships => 1
> );
> 
> 1;
> 
> Model/Intranet/Analize.pm:
> 
> package TranzactiiBursiere::Model::Intranet::Analize;
> 
> use strict;
> use warnings;
> use base 'DBIx::Class::Core';
> 
> 1;
> 
> Model/Intranet/BvbStiri.pm:
> 
> package TranzactiiBursiere::Model::Intranet::BvbStiri;
> 
> use strict;
> use warnings;
> use base 'DBIx::Class::Core';
> 
> 1;
> 
> Now if I restart the web server, it doesn't want to start. It 
> pops up an error message window, but it doesn't print 
> anything in the Apache's log.
> If I click on the "details" button of that window, the 
> following text is
> displayed:
> 
> szAppName : httpd.exe szAppVer : 2.2.3.0 szModName : 
> perl58.dll szModVer : 5.8.8.819 offset : 00085b8c
> 
> 
> If I delete the model classes that I've just created, the 
> server can be started, and the program works.
> 
> Do you have any idea what could be the problem?
> If the model files created would not be correct, perl should 
> give an error, and Apache should print it in the log file, 
> but it doesn't.
> 
> I have also tried the program using perl 
> script/tranzactiibursiere_server.pl, but in this case the 
> program works, and in the log printed I can see that those 2 
> tables were loaded.
> I don't know why Apache is not working. I am using Windows XP Pro and:
> Server version: Apache/2.2.3
> Server built:   Jul 27 2006 16:49:49
> and
> perl, v5.8.8 built for MSWin32-x86-multi-thread Binary build 
> 819 [267479] provided by ActiveState 
> http://www.ActiveState.com Built Aug 29 2006 12:42:41
> 
> 
> I have also noticed that warning:
> This module has been deprecated in favor of 
> Catalyst::Model::DBIC::Schema at 
> D:/usr/site/lib/Catalyst/Helper/Model/DBIC.pm line 45.
> 
> So I have replaced DBIC with DBIC::Schema when creating the 
> model. I don't know if this is correct or not, but it created 
> a single Intranet.pm model file, and no other files for the 
> tables from the database. But in that case the server still 
> could not be started because of the same error window appears.
> 
> Thank you for any idea about this problem.
> 
> Octavian

Hi Octavian,

Maybe I am not understanding what you are trying to do but ou are trying
to use a deprecated module (see the output of your email above).  You
should not have to create *any* files manually in the lib/MyApp/Model/
directory.  The helper will create what you need or when you run
Catalyst it will create+load everything else dynamically.  Being a new
Catalyst user myself I would recommend you start by doing the complete
tutorial and then build your application from that by copying a lot of
things.  First, in the application lib directory, create a
DBIx::Class::Schema file (e.g. lib/Intranet/Schema.pm). Then create all
of the DBIx::Class data source files for each table (e.g.
lib/Intranet/Schema/Analize.pm and lib/Intranet/Schema/BvbStiri.pm).
Then, create your model using the DBIC::Schema helper:

                                name under MyApp::Model    helper  fully
qualified name of DBIx::Class::Schema file
                                                     |         |
|
[hermida at dla2 MyApp] script/myapp_create.pl model Intranet DBIC::Schema
Intranet::Schema 'DBI:mysql:database=intranet' 'root' ''
 exists "/home/hermida/MyApp/script/../lib/MyApp/Model"
 exists "/home/hermida/MyApp/script/../t"
created "/home/hermida/MyApp/script/../lib/MyApp/Model/Intranet.pm"
created "/home/hermida/MyApp/script/../t/model_Intranet.t"
[hermida at dla2 MyApp]$ 

This is it.  Your model is done and will work from here.  If you do need
to make any changes it will probably be to the model config so please
look at lib/MyApp/Model/Intranet.pm and make additions or adjustments.

Hope this helps,

Leandro Hermida





More information about the Catalyst mailing list