Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added db-specific drivers. Not used yet, but they will be.
- Loading branch information
Showing
5 changed files
with
160 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package DBIx::Connection::Driver; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
DRIVERS: { | ||
my %DRIVERS; | ||
|
||
sub new { | ||
my $class = shift; | ||
return $DRIVERS{$class} ||= bless {} => $class; | ||
} | ||
} | ||
|
||
1; | ||
__END__ | ||
=head1 Name | ||
DBIx::Connection::Driver - Database-specific connection interface | ||
=begin comment | ||
=head3 C<new> | ||
=end comment | ||
=head1 Authors | ||
This module was written and is maintained by: | ||
=over | ||
=item David E. Wheeler <david@kineticode.com> | ||
=back | ||
It is based on code written by: | ||
=over | ||
=item Brandon Black <blblack@gmail.com> | ||
=item Matt S. Trout <mst@shadowcatsystems.co.uk> | ||
=item Alex Pavlovic <alex.pavlovic@taskforce-1.com> | ||
=back | ||
=head1 Copyright and License | ||
Copyright (c) 2009 David E. Wheeler. Some Rights Reserved. | ||
This module is free software; you can redistribute it and/or modify it under | ||
the same terms as Perl itself. | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package DBIx::Connection::Driver::Pg; | ||
|
||
use strict; | ||
use warnings; | ||
use base 'DBIx::Connection::Driver'; | ||
|
||
1; | ||
__END__ | ||
=head1 Name | ||
DBIx::Connection::Driver - Database-specific connection interface | ||
=begin comment | ||
=head3 C<new> | ||
=end comment | ||
=head1 Authors | ||
This module was written and is maintained by: | ||
=over | ||
=item David E. Wheeler <david@kineticode.com> | ||
=back | ||
It is based on code written by: | ||
=over | ||
=item Brandon Black <blblack@gmail.com> | ||
=item Matt S. Trout <mst@shadowcatsystems.co.uk> | ||
=item Alex Pavlovic <alex.pavlovic@taskforce-1.com> | ||
=back | ||
=head1 Copyright and License | ||
Copyright (c) 2009 David E. Wheeler. Some Rights Reserved. | ||
This module is free software; you can redistribute it and/or modify it under | ||
the same terms as Perl itself. | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env perl -w | ||
|
||
use strict; | ||
use warnings; | ||
use Test::More tests => 16; | ||
#use Test::More 'no_plan'; | ||
|
||
my $CLASS; | ||
BEGIN { | ||
$CLASS = 'DBIx::Connection::Driver'; | ||
use_ok $CLASS or die; | ||
use_ok 'DBIx::Connection' or die; | ||
use_ok "$CLASS\::Pg" or die; | ||
} | ||
|
||
# Make sure it's a singleton. | ||
ok my $dr = $CLASS->new, 'Create a new driver'; | ||
isa_ok $dr, $CLASS; | ||
is $CLASS->new, $dr, 'It should be a singleton'; | ||
|
||
# Subclass should have a different singleton. | ||
ok my $pg = "$CLASS\::Pg"->new, 'Get a Pg driver'; | ||
isa_ok $pg, "$CLASS\::Pg"; | ||
isa_ok $pg, $CLASS; | ||
isnt $pg, $dr, 'It should be a different object'; | ||
is "$CLASS\::Pg"->new, $pg, 'But it should be a singleton'; | ||
|
||
ok my $conn = DBIx::Connection->new( 'dbi:ExampleP:dummy', '', '' ), | ||
'Construct example connection'; | ||
is $conn->_set_driver, $dr, 'It should have the driver'; | ||
|
||
ok $conn = DBIx::Connection->new('dbi:Pg:dbname=try', '', '' ), | ||
'Construct a Pg connection'; | ||
isa_ok $conn->_set_driver, 'DBIx::Connection::Driver::Pg'; | ||
is $conn->{_driver}, $pg, 'It should be the Pg singleton'; |