From 644789a377b99b52a5a300250526a9d267cd5b6e Mon Sep 17 00:00:00 2001 From: Krasimir Berov Date: Thu, 11 Oct 2012 01:57:05 +0300 Subject: [PATCH] v0.991 --- Changes | 9 ++++++++- Makefile.PL | 2 +- lib/Mojolicious/Plugin/DSC.pm | 27 +++++++++++++-------------- t/advanced.t | 32 ++++++++++++++++++++++++++------ t/lib/My.pm | 3 ++- t/lib/My/Groups.pm | 3 ++- t/lib/My/User.pm | 3 ++- t/lib/Your.pm | 8 +++++--- t/lib/Your/User.pm | 3 ++- 9 files changed, 61 insertions(+), 29 deletions(-) diff --git a/Changes b/Changes index 4098722..41f890c 100644 --- a/Changes +++ b/Changes @@ -1,9 +1,16 @@ Revision history for Mojolicious::Plugin::DSC +0.991 2012-10-11 01:43:05 EEST + - Fixed register(). Now using $app->$dbix_helper - not $app->dbix. + - Fixed POD so Test::Pod::Coverage does not report "config" as naked. + - Increased DBIx::Simple::Class verion dependency. + - Hidden from CPAN example classes used for testing. + - Jumping from 0.60 to be inline with DBIx::Simple::Class. 0.60 2012-08-09 22:48 EEST - Jumping from 0.06 to 0.60 to be closer to DBIx::Simple::Class. - - Multiple dbix helpers. My->dbix can be different from Your->dbix if overriden. See DBIx::Simple::Class/dbix + - Multiple dbix helpers. My->dbix can be different from Your->dbix + if overriden. See DBIx::Simple::Class/dbix - Try to guess default namespace for loading classes from $config->{database} and $config->{dsn}. Supported drivers:mysql, SQLite, Pg. diff --git a/Makefile.PL b/Makefile.PL index a7a77dc..b1d7739 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -9,7 +9,7 @@ WriteMakefile( ABSTRACT_FROM => 'lib/Mojolicious/Plugin/DSC.pm', AUTHOR => q{Красимир Беров }, LICENSE => 'artistic_2', - PREREQ_PM => {'Mojolicious' => '2.0', 'DBIx::Simple::Class' => '0.62'}, + PREREQ_PM => {'Mojolicious' => '2.0', 'DBIx::Simple::Class' => '0.991'}, META_MERGE => { requires => {perl => '5.010001'}, resources => { diff --git a/lib/Mojolicious/Plugin/DSC.pm b/lib/Mojolicious/Plugin/DSC.pm index 6503431..5317eda 100644 --- a/lib/Mojolicious/Plugin/DSC.pm +++ b/lib/Mojolicious/Plugin/DSC.pm @@ -5,12 +5,12 @@ use Mojo::Util qw(camelize); use Carp; -our $VERSION = '0.60'; +our $VERSION = '0.991'; #some known good defaults my $COMMON_ATTRIBUTES = { - RaiseError => 1, - AutoCommit => 1, + RaiseError => 1, + AutoCommit => 1, }; @@ -60,16 +60,12 @@ sub register { . 'must be an ARRAY reference containing a list of classes to load.') unless (ref($config->{load_classes}) eq 'ARRAY'); - DBIx::Simple::Class->DEBUG($config->{DEBUG}); - #ready... Go! my $dbix = DBIx::Simple->connect( $config->{dsn}, $config->{user} || '', $config->{password} || '', - { %$COMMON_ATTRIBUTES, - %{$config->{dbh_attributes}} - } + {%$COMMON_ATTRIBUTES, %{$config->{dbh_attributes}}} ); $config->{onconnect_do} ||= []; if (!ref($config->{onconnect_do})) { @@ -79,12 +75,15 @@ sub register { $dbix->dbh->do($sql); } - $config->{dbix_helper} ||= 'dbix'; - $app->attr($config->{dbix_helper}, sub {$dbix}); - $app->helper($config->{dbix_helper}, $app->dbix); #add helper dbix + my $dbix_helper = $config->{dbix_helper} ||= 'dbix'; + $app->attr($dbix_helper, sub {$dbix}); + $app->helper($dbix_helper, $app->$dbix_helper); #add helper dbix my $DSC = $config->{namespace} || 'DBIx::Simple::Class'; - eval { Mojo::Loader->load($DSC) || $DSC->dbix($app->dbix) } - || DBIx::Simple::Class->dbix($app->dbix); #do not forget + + #make sure user classes have same dbix ready for use + eval { Mojo::Loader->load($DSC) || $DSC->dbix($app->$dbix_helper) } + || DBIx::Simple::Class->dbix($app->$dbix_helper); + $DSC->DEBUG($config->{DEBUG}); $self->_load_classes($config); @@ -189,7 +188,7 @@ L and implements the following new ones. Register plugin in L application. -=head1 config +=head2 config This plugin own configuration. Returns a HASHref. diff --git a/t/advanced.t b/t/advanced.t index 54f6694..0225ca8 100644 --- a/t/advanced.t +++ b/t/advanced.t @@ -8,13 +8,28 @@ BEGIN { use lib qw(t/lib); } -use Test::More tests => 12; +use Test::More tests=>15; package main; use Mojolicious::Lite; use Test::Mojo; use Data::Dumper; + +#Suppress some warnings from DBIx::Simple::Class during tests. +local $SIG{__WARN__} = sub { + if ( + $_[0] =~ /(ddbix\sredefined + |SQL\sfrom)/x + ) + { + my ($package, $filename, $line, $subroutine) = caller(1); + ok($_[0], $subroutine . " warns '$1' OK"); + } + else { + warn $_[0]; + } +}; plugin('Charset', {charset => 'UTF-8'}); my $config = { database => ':memory:', @@ -24,7 +39,7 @@ my $config = { dbh_attributes => {sqlite_unicode => 1}, driver => 'SQLite', onconnect_do => [], - dbix_helper => 'dbix', + dbix_helper => 'ddbix', dsn => 'dbi:SQLite:database=:memory:' }; @@ -43,10 +58,12 @@ TAB $config->{load_classes} = ['My::User', 'Groups']; isa_ok(plugin('DSC', $config), 'Mojolicious::Plugin::DSC'); -ok(app->dbix->query($my_groups_table), 'app->dbix works'); -ok(app->dbix->query('INSERT INTO my_groups ("group") VALUES(?)', 'pojo'), - 'app->dbix->query works'); +ok(app->ddbix->query($my_groups_table), 'app->ddbix works'); + +ok(app->ddbix->query('INSERT INTO my_groups ("group") VALUES(?)', 'pojo'), + 'app->ddbix->query works'); + my $group = My::Groups->find(1); my $user = My::User->new( group_id => $group->id, @@ -63,10 +80,11 @@ my $your_config = { dbix_helper => 'your_dbix', dsn => 'dbi:SQLite:database=:memory:' }; + my $your_dbix = plugin('DSC', $your_config); can_ok(app, 'your_dbix'); -isnt(app->your_dbix, app->dbix, 'two schemas loaded'); +isnt(app->your_dbix, app->ddbix, 'two schemas loaded'); get '/' => sub { my $self = shift; @@ -89,3 +107,5 @@ $t->content_is('Hello ' . $user->login_name . ' from group ' . $group->group . ' $t->post_form_ok('/edit/user', {id => 1, login_password => 'alabala123'}) ->status_is(200)->content_is('New password for user петър is alabala123'); + +=comment diff --git a/t/lib/My.pm b/t/lib/My.pm index 87b930a..87aa5f5 100644 --- a/t/lib/My.pm +++ b/t/lib/My.pm @@ -1,6 +1,7 @@ { - package My; #our schema + package #hide + My; #our schema use 5.010; use strict; use warnings; diff --git a/t/lib/My/Groups.pm b/t/lib/My/Groups.pm index e9d5ce9..0aac58d 100644 --- a/t/lib/My/Groups.pm +++ b/t/lib/My/Groups.pm @@ -1,4 +1,5 @@ -package My::Groups; +package #hide + My::Groups; use strict; use warnings; use utf8; diff --git a/t/lib/My/User.pm b/t/lib/My/User.pm index 42e344b..55164c0 100644 --- a/t/lib/My/User.pm +++ b/t/lib/My/User.pm @@ -1,4 +1,5 @@ -package My::User; +package #hide + My::User; use Mojo::Base 'My'; sub TABLE {'users'} diff --git a/t/lib/Your.pm b/t/lib/Your.pm index 234d0a2..09a2fee 100644 --- a/t/lib/Your.pm +++ b/t/lib/Your.pm @@ -1,6 +1,7 @@ { - package Your; #our second schema + package #hide + Your; #our second schema use 5.010; use strict; use warnings; @@ -8,10 +9,11 @@ use base qw(DBIx::Simple::Class); sub dbix { - + # Singleton DBIx::Simple instance state $DBIx; - return ($DBIx = $_[1] ? $_[1] : $DBIx) || Carp::croak('DBIx::Simple is not instantiated for schema "Your"'); + return ($DBIx = $_[1] ? $_[1] : $DBIx) + || Carp::croak('DBIx::Simple is not instantiated for schema "Your"'); } } 1; diff --git a/t/lib/Your/User.pm b/t/lib/Your/User.pm index a06f38f..ddc92bc 100644 --- a/t/lib/Your/User.pm +++ b/t/lib/Your/User.pm @@ -1,4 +1,5 @@ -package Your::User; +package #hide + Your::User; use Mojo::Base 'Your'; sub TABLE {'users'}