Hi Folks
First some code:
D:\Perl\site\lib\Monash\Rose\Morsecode\Base\DB.pm:
----<>8-----
package Monash::Rose::MorseCode::Base::DB;
use Rose::DB;
our @ISA = 'Rose::DB';
# -----------------------------------------------
Rose::DB -> use_private_registry();
Rose::DB -> default_domain('windows');
Rose::DB->register_db
(
domain => 'windows',
type => 'default',
driver => 'mysql',
database => 'morsecode',
host => 'localhost',
username => 'root',
password => 'pass',
);
print __PACKAGE__, ". Called: default_domain. \n";
# -----------------------------------------------
1;
----<>8-----
D:\Perl\site\lib\Monash\Rose\Morsecode\Base\Object.pm:
----<>8-----
package Monash::Rose::MorseCode::Base::Object;
use base 'Rose::DB::Object';
use Monash::Rose::MorseCode::Base::DB;
# -----------------------------------------------
sub init_db
{
print __PACKAGE__, ". About to call: Monash::Rose::MorseCode::Base::DB
->
new(). \n";
# The value returned by this sub must be of type Rose::DB.
# See Rose::DB::Object's docs for the object method db().
Monash::Rose::MorseCode::Base::DB -> new();
}
# -----------------------------------------------
1;
----<>8-----
The generated module
D:\Perl\site\lib\Monash\Rose\Morsecode\Faculty.pm:
----<>8-----
package Monash::Rose::MorseCode::Faculty;
use strict;
use Monash::Rose::MorseCode::Base::Object;
our @ISA = qw(Monash::Rose::MorseCode::Base::Object);
__PACKAGE__->meta->table('faculty');
print __PACKAGE__, ". Called: meta->table. \n";
__PACKAGE__->meta->columns
(
id => { type => 'integer', not_null => 1 },
name => { type => 'varchar', default => '', length => 255, not_null => 1 },
);
print __PACKAGE__, ". Called: meta->columns. \n";
__PACKAGE__->meta->primary_key_columns([ 'id' ]);
print __PACKAGE__, ". Called: meta->primary_key_columns. \n";
__PACKAGE__->meta->initialize;
print __PACKAGE__, ". Called: meta->initialize. \n";
1;
----<>8-----
----<>8-----
#!/usr/bin/perl
#
# Name:
# test-generated-code.pl.
use strict;
use warnings;
use Monash::Rose::MorseCode::Faculty;
# -----------------------------------
my($faculty) = Monash::Rose::MorseCode::Faculty -> new(id => 1);
$faculty -> load();
print "Faculty id => name: 1 => ", $faculty -> name(), ". \n";
----<>8-----
The output:
----<>8-----
Monash::Rose::MorseCode::Base::DB. Called: default_domain.
Monash::Rose::MorseCode::Faculty. Called: meta->table.
Monash::Rose::MorseCode::Faculty. Called: meta->columns.
Monash::Rose::MorseCode::Base::Object. About to call:
Monash::Rose::MorseCode::Base::DB -> new().
Monash::Rose::MorseCode::Faculty. Called: meta->primary_key_columns.
Monash::Rose::MorseCode::Base::Object. About to call:
Monash::Rose::MorseCode::Base::DB -> new().
Monash::Rose::MorseCode::Faculty. Called: meta->initialize.
Monash::Rose::MorseCode::Base::Object. About to call:
Monash::Rose::MorseCode::Base::DB -> new().
Faculty id => name: 1 => DEPUTY V-C (INTERNATIONAL AFFAIRS).
----<>8-----
The questions:
o At the start of the first package I have:
Rose::DB -> use_private_registry();
sort of as per the doc Rose::DB::Object::Tutorial sample code just under the
heading TUTORIAL/Preface.
Actually, that sample uses __PACKAGE__, not Rose::DB.
When I tried using __PACKAGE__ I got this error:
-----><8-----
No database information found for domain 'windows' and type 'default' at
d:/Perl/site/lib/Monash/Rose/MorseCode/Base/Object.pm line 16
Compilation failed in require at
D:\Monash\morsecode\scripts\test-generated-code.pl line 9.
BEGIN failed--compilation aborted at
D:\Monash\morsecode\scripts\test-generated-code.pl line 9.
Monash::Rose::MorseCode::Base::DB. Called: default_domain.
Monash::Rose::MorseCode::Faculty. Called: meta->table.
Monash::Rose::MorseCode::Faculty. Called: meta->columns.
Monash::Rose::MorseCode::Base::Object. About to call:
Monash::Rose::MorseCode::Base::DB -> new().
-----><8-----
where line 16 is:
Monash::Rose::MorseCode::Base::DB -> new();
So, why the error?
o Why is init_db called three times? Is this meant to happen?
--
Ron Savage
[EMAIL PROTECTED]
http://savage.net.au/index.html
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Rose-db-object mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rose-db-object