Permalink
Browse files

v0.991

  • Loading branch information...
1 parent c152739 commit 644789a377b99b52a5a300250526a9d267cd5b6e @kberov committed Oct 10, 2012
Showing with 61 additions and 29 deletions.
  1. +8 −1 Changes
  2. +1 −1 Makefile.PL
  3. +13 −14 lib/Mojolicious/Plugin/DSC.pm
  4. +26 −6 t/advanced.t
  5. +2 −1 t/lib/My.pm
  6. +2 −1 t/lib/My/Groups.pm
  7. +2 −1 t/lib/My/User.pm
  8. +5 −3 t/lib/Your.pm
  9. +2 −1 t/lib/Your/User.pm
View
@@ -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.
View
@@ -9,7 +9,7 @@ WriteMakefile(
ABSTRACT_FROM => 'lib/Mojolicious/Plugin/DSC.pm',
AUTHOR => q{Красимир Беров <berov@cpan.org>},
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 => {
@@ -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<Mojolicious::Plugin> and implements the following new ones.
Register plugin in L<Mojolicious> application.
-=head1 config
+=head2 config
This plugin own configuration. Returns a HASHref.
View
@@ -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
View
@@ -1,6 +1,7 @@
{
- package My; #our schema
+ package #hide
+ My; #our schema
use 5.010;
use strict;
use warnings;
View
@@ -1,4 +1,5 @@
-package My::Groups;
+package #hide
+ My::Groups;
use strict;
use warnings;
use utf8;
View
@@ -1,4 +1,5 @@
-package My::User;
+package #hide
+ My::User;
use Mojo::Base 'My';
sub TABLE {'users'}
View
@@ -1,17 +1,19 @@
{
- package Your; #our second schema
+ package #hide
+ Your; #our second schema
use 5.010;
use strict;
use warnings;
use utf8;
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;
View
@@ -1,4 +1,5 @@
-package Your::User;
+package #hide
+ Your::User;
use Mojo::Base 'Your';
sub TABLE {'users'}

0 comments on commit 644789a

Please sign in to comment.