Many thanks to the group and, in particular, Peter Karman.
I put my configuration initialization code inside of a BEGIN block. I
am then referencing the config variables using the "main" lexical
scoping:
$main::database_driver, etc.
as parameters to the register_db call. The $main variables is a little
hacky, but I hope to have it refactored now that I am confident that I
am heading in the right direction.
Cheers,
-mz
On Mon, Dec 17, 2012 at 11:42 AM, Matt Zagrabelny <
mzag...@d.umn.edu> wrote:
> Hi Peter,
>
> Thanks for the reply. Comments are inline.
>
> On Sun, Dec 16, 2012 at 8:35 PM, Peter Karman <
pek...@gmail.com> wrote:
>>
>>
>> On Dec 14, 4:43 pm, Matt Zagrabelny <
mzagr...@d.umn.edu> wrote:
>>
>>> ---{begin of program: /home/mzagrabe/git/rosetest/bin/rosetest}---
>>> #!/usr/bin/perl
>>>
>>> =head1
>>> CREATE TABLE "books" (
>>> "author" TEXT PRIMARY KEY,
>>> "title" TEXT
>>> );
>>> =cut
>>>
>>> use strict;
>>> use warnings;
>>>
>>> use lib "/home/mzagrabe/git/rosetest/lib";
>>>
>>> use RoseTest::DB;
>>
>>
>> at this point, register_db() has already been called in RoseTest::DB,
>> so your call to configs() below
>> doesn't result in 'database-driver' being set in the registry.
>>
>> suggested fix below.
>>
>>>
>>> RoseTest::DB->configs(
>>> {
>>> 'database-driver' => 'Pg',
>>> 'database-name' => 'rosetest',
>>> 'database-host' => 'localhost',
>>> 'database-user' => 'mike',
>>> 'database-pass' => 'GlermtheWorm',
>>> }
>>> );
>>>
>>> use RoseTest::Book;
>>>
>>> my $metadata = RoseTest::DB->new(
>>> type => 'rosetest',
>>> );
>>>
>>> my $book = RoseTest::Book->new(
>>> author => 'Tolkien',
>>> title => 'The Hobbit',
>>> );
>>>
>>> $book->save;
>>> ---{end of program}---
>>>
>>> ---{begin of module: /home/mzagrabe/git/rosetest/lib/RoseTest/DB.pm}---
>>> package RoseTest::DB;
>>>
>>> use strict;
>>> use warnings;
>>>
>>> use Carp;
>>> use Data::Dumper;
>>> use Rose::DB;
>>>
>>> use base qw( Rose::DB );
>>>
>>> {
>>> my $configs = {};
>>>
>>> sub configs {
>>> my $class = shift;
>>> if (scalar(@_) == 0) {
>>> return $configs;
>>> }
>>> elsif (scalar(@_) == 1) {
>>> $configs = $_[0];
>>> }
>>> else {
>>> croak "Error: Wrong number of arguments. Please pass zero
>>> or one argument.";
>>> }
>>
>> put your register_db() calls here for each in $configs
>
> Hmm. Not exactly sure what you mean by "for each in $configs". I did
> some testing by putting the register_db call into this subroutine, but
> it still doesn't work. The Object class (Book.pm) seems to not
> recognize the registry:
>
> No database information found for domain 'default' and type 'rosetest'
> and no driver type specified in call to RoseTest::DB->new(...) at
> /home/mzagrabe/git/rosetest/lib/RoseTest/Book.pm line 15
> Compilation failed in require at
> /home/mzagrabe/git/rosetest/bin/rosetest line 27.
> BEGIN failed--compilation aborted at
> /home/mzagrabe/git/rosetest/bin/rosetest line 27.
>
> Thanks for your help!
>
> -mz