Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix problem when using Schema::Loader and new method is overrided

  • Loading branch information...
commit 75e04d17651e7d99389cef7c9adae614c4d23fb5 1 parent 762840e
@Songmu Songmu authored
View
4 lib/Teng.pm
@@ -47,6 +47,7 @@ sub load_plugin {
sub new {
my $class = shift;
my %args = @_ == 1 ? %{$_[0]} : @_;
+ my $loader = delete $args{loader};
if ( my $mode = delete $args{mode} ) {
warn "IMPORTANT: 'mode' option is DEPRECATED AND *WILL* BE REMOVED. PLEASE USE 'no_ping' option.\n";
@@ -63,8 +64,7 @@ sub new {
%args,
}, $class;
- my @caller = caller(0);
- if ($caller[0] ne 'Teng::Schema::Loader' && ! $self->schema) {
+ if (!$loader && ! $self->schema) {
my $schema_class = $self->{schema_class};
Class::Load::load_class( $schema_class );
my $schema = $schema_class->instance;
View
2  lib/Teng/Schema/Loader.pm
@@ -19,7 +19,7 @@ sub load {
no strict 'refs'; @{"$namespace\::ISA"} = ('Teng');
};
- my $teng = $namespace->new(%args);
+ my $teng = $namespace->new(%args, loader => 1);
my $dbh = $teng->dbh;
unless ($dbh) {
Carp::croak("missing mandatory parameter 'dbh' or 'connect_info'");
View
30 t/001_basic/003_schema_loader.t
@@ -84,6 +84,36 @@ subtest 'auto create teng class' => sub {
is $db->single('user', { user_id => 3 })->name, 'inserted 3';
};
+{
+ package Mock::DB2;
+ use parent 'Teng';
+
+ sub new {
+ shift->SUPER::new(@_);
+ }
+}
+
+subtest 'constructor is overrided' => sub {
+ local $@;
+
+ my $db = eval {
+ Teng::Schema::Loader->load(
+ dbh => $dbh,
+ namespace => 'Mock::DB2',
+ );
+ };
+ ok !$@;
+ isa_ok $db, 'Mock::DB2';
+
+ my $user = $db->schema->get_table('user');
+ is($user->name, 'user');
+ is(join(',', @{$user->primary_keys}), 'user_id');
+ is(join(',', @{$user->columns}), 'user_id,name,email,created_on');
+
+ my $row = $db->schema->get_row_class('user');
+ is $row, 'Mock::DB2::Row::User';
+};
+
unlink './loader.db';
done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.