Skip Menu |

This queue is for tickets about the Catalyst-Model-DBI CPAN distribution.

Report information
The Basics
Id: 37469
Status: open
Priority: 0/
Queue: Catalyst-Model-DBI

People
Owner: Nobody in particular
Requestors: janus [...] errornet.de
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Patch that adds support for DBI wrapper classes
Hi, as i'm working with small Catalyst::Model::DBI and custom DBI wrappers for various extensions i needed support for wrapper classes and wrote the attached patch. Now you can additionally configure DBI wrapper classes like this: $ script/create.pl model DBI DBI::Wrapper wrapper dsn user password In Catalyst::Model::DBI i've taken out the direct use of DBI and made new() execute Catalyst::Utils::ensure_class_loaded() instead to load a possibly configured alternative DBI class. Further i've added a check to connected() to prevent additional errors in the case the alternative DBI class wasn't found. I copied Catalyst::Helper::Model::DBI over to Catalyst::Helper::Model::DBI::Wrapper because i wasn't able to find a good and intuitive way to do the same with the existing helper. Besides that, i hope i did all that would be necessary to get a new release ready. It would be very nice to see this going upstream as it would ease the work for everyone who's using DBI wrappers. Kind regards, Simon
Subject: Catalyst-Model-DBI.diff
Index: t/01use.t =================================================================== --- t/01use.t (revision 8084) +++ t/01use.t (working copy) @@ -1,5 +1,6 @@ use strict; -use Test::More tests => 2; +use Test::More tests => 3; BEGIN { use_ok('Catalyst::Model::DBI') } BEGIN { use_ok('Catalyst::Helper::Model::DBI') } +BEGIN { use_ok('Catalyst::Helper::Model::DBI::Wrapper') } Index: lib/Catalyst/Helper/Model/DBI/Wrapper.pm =================================================================== --- lib/Catalyst/Helper/Model/DBI/Wrapper.pm (revision 0) +++ lib/Catalyst/Helper/Model/DBI/Wrapper.pm (revision 0) @@ -0,0 +1,103 @@ +package Catalyst::Helper::Model::DBI::Wrapper; + +use strict; +use File::Spec; + +our $VERSION = '0.19'; + +=head1 NAME + +Catalyst::Helper::Model::DBI - Helper for DBI Wrapper Models + +=head1 SYNOPSIS + + script/create.pl model DBI DBI::Wrapper wrapper dsn user password + +=head1 DESCRIPTION + +Helper for DBI Wrapper Model. + +=head2 METHODS + +=over 4 + +=item mk_compclass + +Reads the database and makes a main model class + +=item mk_comptest + +Makes tests for the DBI Model. + +=back + +=cut + +sub mk_compclass { + my ( $self, $helper, $wrapper, $dsn, $user, $pass ) = @_; + $helper->{wrapper} = $wrapper || 'DBI'; + $helper->{dsn} = $dsn || ''; + $helper->{user} = $user || ''; + $helper->{pass} = $pass || ''; + my $file = $helper->{file}; + $helper->render_file( 'dbiclass', $file ); + return 1; +} + +=head1 SEE ALSO + +L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>, +L<Catalyst::Response>, L<Catalyst::Helper> + +=head1 AUTHOR + +Alex Pavlovic, C<alex.pavlovic@taskforce-1.com> + +=head1 LICENSE + +This library is free software . You can redistribute it and/or modify +it under the same terms as perl itself. + +=cut + +1; +__DATA__ + +__dbiclass__ +package [% class %]; + +use strict; +use base 'Catalyst::Model::DBI'; + +__PACKAGE__->config( + wrapper => '[% wrapper %]', + dsn => '[% dsn %]', + user => '[% user %]', + password => '[% pass %]', + options => {}, +); + +=head1 NAME + +[% class %] - DBI Wrapper Model Class + +=head1 SYNOPSIS + +See L<[% app %]> + +=head1 DESCRIPTION + +DBI Wrapper Model Class. + +=head1 AUTHOR + +[% author %] + +=head1 LICENSE + +This library is free software, you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; Index: lib/Catalyst/Model/DBI.pm =================================================================== --- lib/Catalyst/Model/DBI.pm (revision 8084) +++ lib/Catalyst/Model/DBI.pm (working copy) @@ -3,9 +3,8 @@ use strict; use base 'Catalyst::Model'; use NEXT; -use DBI; -our $VERSION = '0.19'; +our $VERSION = '0.20'; __PACKAGE__->mk_accessors( qw/_dbh _pid _tid/ ); @@ -51,12 +50,15 @@ sub new { my $self = shift; - my ( $c ) = @_; + my ( $c, $config ) = @_; $self = $self->NEXT::new( @_ ); - $self->{namespace} ||= ref $self; - $self->{additional_base_classes} ||= (); + $self->{namespace} ||= ref $self; + $self->{class} = $config->{wrapper} || 'DBI'; $self->{log} = $c->log; $self->{debug} = $c->debug; + + Catalyst::Utils::ensure_class_loaded($self->{class}); + return $self; } @@ -101,6 +103,7 @@ sub connected { my $self = shift; + return unless $self->dbh; return $self->_dbh->{Active} && $self->_dbh->ping; } @@ -114,7 +117,7 @@ my $self = shift; my $dbh; eval { - $dbh = DBI->connect( + $dbh = $self->{class}->connect( $self->{dsn}, $self->{user}, $self->{password}, Index: MANIFEST =================================================================== --- MANIFEST (revision 8084) +++ MANIFEST (working copy) @@ -1,5 +1,6 @@ Changes lib/Catalyst/Helper/Model/DBI.pm +lib/Catalyst/Helper/Model/DBI/Wrapper.pm lib/Catalyst/Model/DBI.pm Makefile.PL MANIFEST This list of files
From: janus [...] errornet.de
On Sun Jul 06 17:18:02 2008, janus wrote: Show quoted text
> Hi, > as i'm working with small Catalyst::Model::DBI and custom DBI wrappers > for various extensions i needed support for wrapper classes and wrote > the attached patch. > Now you can additionally configure DBI wrapper classes like this: > $ script/create.pl model DBI DBI::Wrapper wrapper dsn user password > > In Catalyst::Model::DBI i've taken out the direct use of DBI and made > new() execute Catalyst::Utils::ensure_class_loaded() instead to load a > possibly configured alternative DBI class. > Further i've added a check to connected() to prevent additional errors > in the case the alternative DBI class wasn't found. > > I copied Catalyst::Helper::Model::DBI over to > Catalyst::Helper::Model::DBI::Wrapper because i wasn't able to find a > good and intuitive way to do the same with the existing helper. > > Besides that, i hope i did all that would be necessary to get a new > release ready. > > It would be very nice to see this going upstream as it would ease the > work for everyone who's using DBI wrappers. > > Kind regards, > Simon
The check in connected() is definitely wrong and leads to runtime errors. Here's an updated diff that doesn't crash. Regards, Simon
Index: t/01use.t =================================================================== --- t/01use.t (revision 8084) +++ t/01use.t (working copy) @@ -1,5 +1,6 @@ use strict; -use Test::More tests => 2; +use Test::More tests => 3; BEGIN { use_ok('Catalyst::Model::DBI') } BEGIN { use_ok('Catalyst::Helper::Model::DBI') } +BEGIN { use_ok('Catalyst::Helper::Model::DBI::Wrapper') } Index: lib/Catalyst/Helper/Model/DBI/Wrapper.pm =================================================================== --- lib/Catalyst/Helper/Model/DBI/Wrapper.pm (revision 0) +++ lib/Catalyst/Helper/Model/DBI/Wrapper.pm (revision 0) @@ -0,0 +1,103 @@ +package Catalyst::Helper::Model::DBI::Wrapper; + +use strict; +use File::Spec; + +our $VERSION = '0.19'; + +=head1 NAME + +Catalyst::Helper::Model::DBI - Helper for DBI Wrapper Models + +=head1 SYNOPSIS + + script/create.pl model DBI DBI::Wrapper wrapper dsn user password + +=head1 DESCRIPTION + +Helper for DBI Wrapper Model. + +=head2 METHODS + +=over 4 + +=item mk_compclass + +Reads the database and makes a main model class + +=item mk_comptest + +Makes tests for the DBI Model. + +=back + +=cut + +sub mk_compclass { + my ( $self, $helper, $wrapper, $dsn, $user, $pass ) = @_; + $helper->{wrapper} = $wrapper || 'DBI'; + $helper->{dsn} = $dsn || ''; + $helper->{user} = $user || ''; + $helper->{pass} = $pass || ''; + my $file = $helper->{file}; + $helper->render_file( 'dbiclass', $file ); + return 1; +} + +=head1 SEE ALSO + +L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>, +L<Catalyst::Response>, L<Catalyst::Helper> + +=head1 AUTHOR + +Alex Pavlovic, C<alex.pavlovic@taskforce-1.com> + +=head1 LICENSE + +This library is free software . You can redistribute it and/or modify +it under the same terms as perl itself. + +=cut + +1; +__DATA__ + +__dbiclass__ +package [% class %]; + +use strict; +use base 'Catalyst::Model::DBI'; + +__PACKAGE__->config( + wrapper => '[% wrapper %]', + dsn => '[% dsn %]', + user => '[% user %]', + password => '[% pass %]', + options => {}, +); + +=head1 NAME + +[% class %] - DBI Wrapper Model Class + +=head1 SYNOPSIS + +See L<[% app %]> + +=head1 DESCRIPTION + +DBI Wrapper Model Class. + +=head1 AUTHOR + +[% author %] + +=head1 LICENSE + +This library is free software, you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1; Index: lib/Catalyst/Model/DBI.pm =================================================================== --- lib/Catalyst/Model/DBI.pm (revision 8084) +++ lib/Catalyst/Model/DBI.pm (working copy) @@ -3,9 +3,8 @@ use strict; use base 'Catalyst::Model'; use NEXT; -use DBI; -our $VERSION = '0.19'; +our $VERSION = '0.20'; __PACKAGE__->mk_accessors( qw/_dbh _pid _tid/ ); @@ -51,12 +50,15 @@ sub new { my $self = shift; - my ( $c ) = @_; + my ( $c, $config ) = @_; $self = $self->NEXT::new( @_ ); - $self->{namespace} ||= ref $self; - $self->{additional_base_classes} ||= (); + $self->{namespace} ||= ref $self; + $self->{class} = $config->{wrapper} || 'DBI'; $self->{log} = $c->log; $self->{debug} = $c->debug; + + Catalyst::Utils::ensure_class_loaded($self->{class}); + return $self; } @@ -114,7 +116,7 @@ my $self = shift; my $dbh; eval { - $dbh = DBI->connect( + $dbh = $self->{class}->connect( $self->{dsn}, $self->{user}, $self->{password}, Index: MANIFEST =================================================================== --- MANIFEST (revision 8084) +++ MANIFEST (working copy) @@ -1,5 +1,6 @@ Changes lib/Catalyst/Helper/Model/DBI.pm +lib/Catalyst/Helper/Model/DBI/Wrapper.pm lib/Catalyst/Model/DBI.pm Makefile.PL MANIFEST This list of files
Hi, What exactly leads to runtime errors? Provide detailed report please next time. Runtime errors in patch you provided? Please clarify. Also I emailed you already, I won't be able to take a look at this for at least a few more days, since I am very busy. Thanks. On Sun Jul 06 17:29:44 2008, janus wrote: Show quoted text
> On Sun Jul 06 17:18:02 2008, janus wrote:
> > Hi, > > as i'm working with small Catalyst::Model::DBI and custom DBI
wrappers Show quoted text
> > for various extensions i needed support for wrapper classes and
wrote Show quoted text
> > the attached patch. > > Now you can additionally configure DBI wrapper classes like this: > > $ script/create.pl model DBI DBI::Wrapper wrapper dsn user
password Show quoted text
> > > > In Catalyst::Model::DBI i've taken out the direct use of DBI and
made Show quoted text
> > new() execute Catalyst::Utils::ensure_class_loaded() instead to
load a Show quoted text
> > possibly configured alternative DBI class. > > Further i've added a check to connected() to prevent additional
errors Show quoted text
> > in the case the alternative DBI class wasn't found. > > > > I copied Catalyst::Helper::Model::DBI over to > > Catalyst::Helper::Model::DBI::Wrapper because i wasn't able to
find a Show quoted text
> > good and intuitive way to do the same with the existing helper. > > > > Besides that, i hope i did all that would be necessary to get a
new Show quoted text
> > release ready. > > > > It would be very nice to see this going upstream as it would ease
the Show quoted text
> > work for everyone who's using DBI wrappers. > > > > Kind regards, > > Simon
> > The check in connected() is definitely wrong and leads to runtime > errors. Here's an updated diff that doesn't crash. > > Regards, > Simon
Subject: Re: [rt.cpan.org #37469] Patch that adds support for DBI wrapper classes
Date: Mon, 7 Jul 2008 09:35:59 +0200
To: Alex Pavlovic via RT <bug-Catalyst-Model-DBI [...] rt.cpan.org>
From: Simon Bertrang <janus [...] errornet.de>
On Sun, Jul 06, 2008 at 08:29:38PM -0400, Alex Pavlovic via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=37469 > > > Hi, > > What exactly leads to runtime errors? Provide detailed report please > next time. Runtime errors in patch you provided? Please clarify. Also > I emailed you already, I won't be able to take a look at this for at > least a few more days, since I am very busy. >
Oops, yes. My previous patch led to runtime errors because of the change i did in connected(). Looking forward to further comments when you found some time, kind regards Simon Show quoted text
> Thanks. > > On Sun Jul 06 17:29:44 2008, janus wrote:
> > On Sun Jul 06 17:18:02 2008, janus wrote:
> > > Hi, > > > as i'm working with small Catalyst::Model::DBI and custom DBI
> wrappers
> > > for various extensions i needed support for wrapper classes and
> wrote
> > > the attached patch. > > > Now you can additionally configure DBI wrapper classes like this: > > > $ script/create.pl model DBI DBI::Wrapper wrapper dsn user
> password
> > > > > > In Catalyst::Model::DBI i've taken out the direct use of DBI and
> made
> > > new() execute Catalyst::Utils::ensure_class_loaded() instead to
> load a
> > > possibly configured alternative DBI class. > > > Further i've added a check to connected() to prevent additional
> errors
> > > in the case the alternative DBI class wasn't found. > > > > > > I copied Catalyst::Helper::Model::DBI over to > > > Catalyst::Helper::Model::DBI::Wrapper because i wasn't able to
> find a
> > > good and intuitive way to do the same with the existing helper. > > > > > > Besides that, i hope i did all that would be necessary to get a
> new
> > > release ready. > > > > > > It would be very nice to see this going upstream as it would ease
> the
> > > work for everyone who's using DBI wrappers. > > > > > > Kind regards, > > > Simon
> > > > The check in connected() is definitely wrong and leads to runtime > > errors. Here's an updated diff that doesn't crash. > > > > Regards, > > Simon
> >