Skip Menu |

This queue is for tickets about the Rose-DB-Object CPAN distribution.

Report information
The Basics
Id: 78571
Status: resolved
Priority: 0/
Queue: Rose-DB-Object

People
Owner: Nobody in particular
Requestors: ALEXBYK [...] cpan.org
Cc: siracusa [...] gmail.com
AdminCc:

Bug Information
Severity: Important
Broken in: 0.798
Fixed in: 0.799



CC: siracusa [...] gmail.com
Subject: Rose::DB::Object::Loader bug
I think this is a bug. When I use ::Loader, it break the init_db method of the base_class. The test is included
Subject: db-object-loader-cached.t
#!/usr/bin/env perl # BUG: When you use Rose::DB::Object::Loader, # init_db method of the base_class does not work # ---------------- SETUP { package My::DB; use strict; use warnings; use parent qw(Rose::DB); use File::Temp qw/ tempfile /; my ($fh, $filename) = tempfile(); __PACKAGE__->use_private_registry; __PACKAGE__->register_db(driver => 'sqlite', database => $filename,); CREATE: { my $dbh = __PACKAGE__->new()->retain_dbh; $dbh->do('DROP TABLE IF EXISTS `sites`'); $dbh->do(<<CREATE); CREATE TABLE `sites` ( `id` int(10) NOT NULL, `host` varchar(45) DEFAULT NULL, PRIMARY KEY (`id`) ) CREATE } } { package My::DB::Object; use parent 'Rose::DB::Object'; use Mojo::Base -strict; # CACHED!!! sub init_db { return My::DB->new_or_cached; } } { package My::Model::Site; use strict; use base qw(My::DB::Object); __PACKAGE__->meta->setup( table => 'sites', columns => [ id => {type => 'serial', not_null => 1}, host => {type => 'varchar', length => 45}, ], primary_key_columns => ['id'], ); } # ---------------- TEST RIGHT NOW package main; use strict; use warnings; use Rose::DB::Object::Loader; use Test::More tests => 3; use Test::Deep; #1: works as expected is(My::Model::Site->new()->dbh, My::Model::Site->new()->dbh, 'cached dbh'); # overwrite our model with the help of the loader my $loader = Rose::DB::Object::Loader->new( db_class => 'My::DB', base_classes => 'My::DB::Object', class_prefix => 'My::Model::', ); cmp_deeply [$loader->make_classes], [qw/My::Model::Site My::Model::Site::Manager/]; #2: fail! init_db with new_or_cached does not work after loader's work is( My::Model::Site->new()->dbh, My::Model::Site->new()->dbh, 'cached dbh (loader)' );
Subject: Rose::DB::Object::Loader bugfix
diff -u Loader.pm.origin Loader.pm --- Loader.pm.origin 2012-07-25 23:43:12.097423258 +0300 +++ Loader.pm 2012-07-25 23:42:55.465423988 +0300 @@ -853,6 +853,7 @@ } else { + $init_db = sub { $db_class->new(%db_args) }; my $hash = perl_hashref(hash => \%db_args, @@ -904,10 +905,12 @@ else { if($made_new_db_class || $db_class ne 'Rose::DB') - { - no strict 'refs'; - no warnings; - *{"$base_classes[0]::init_db"} = $init_db; + { + unless ($base_classes[0]->can('init_db') ne Rose::DB::Object->can('init_db')) { + no strict 'refs'; + no warnings; + *{"$base_classes[0]::init_db"} = $init_db + } $extra_info->{'init_db_in_base_class'} = 1; $extra_info->{'base_classes'}{$base_classes[0]}++; }
Do not use my prev patch. I was drunk. I've attached the new one. Usage (from the parent dir): patch -p0 < loader_bugfix.path
Subject: loader_bugfix.path
Download loader_bugfix.path
application/octet-stream 4k

Message body not shown because it is not plain text.

This should be fixed in 0.799, just uploaded to CPAN.