summaryrefslogtreecommitdiff
path: root/DataSource/Pg.pm
diff options
context:
space:
mode:
authorivan <ivan>2000-09-25 12:44:09 +0000
committerivan <ivan>2000-09-25 12:44:09 +0000
commitdc7bb5693a27402bd32dbd077525727aafcbc98c (patch)
tree90728465b6b98e496d5076515a6a2b4016be4af9 /DataSource/Pg.pm
s/DBIx::Database/DBIx::DataSource/STARTDBIx_DataSource_0_02
Diffstat (limited to 'DataSource/Pg.pm')
-rw-r--r--DataSource/Pg.pm77
1 files changed, 77 insertions, 0 deletions
diff --git a/DataSource/Pg.pm b/DataSource/Pg.pm
new file mode 100644
index 0000000..4956785
--- /dev/null
+++ b/DataSource/Pg.pm
@@ -0,0 +1,77 @@
+package DBIx::DataSource::Pg;
+
+use strict;
+use vars qw($VERSION @ISA);
+use DBIx::DataSource::Driver;
+@ISA = qw( DBIx::DataSource::Driver );
+
+$VERSION = '0.01';
+
+=head1 NAME
+
+DBIx::DataSource::Pg - PostgreSQL driver for DBIx::DataSource
+
+=head1 SYNOPSIS
+
+ use DBIx::DataSource;
+
+ use DBIx::DataSource qw( create_database drop_database );
+
+ create_database( "dbi:Pg:dbname=$dbname", $username, $password )
+ or warn $DBIx::DataSource::errstr;
+
+ create_database( "dbi:Pg:dbname=$dbname;host=$host;port=$port",
+ $username, $password )
+ or warn $DBIx::DataSource::errstr;
+
+ drop_database( "dbi:Pg:dbname=$dbname", $username, $password )
+ or warn $DBIx::DataSource::errstr;
+
+ drop_database( "dbi:Pg:dbname=$dbname;host=$host;port=$port",
+ $username, $password )
+ or warn $DBIx::DataSource::errstr;
+
+=head1 DESCRIPTION
+
+This is the PostgresSQL driver for DBIx::DataSource.
+
+=cut
+
+sub parse_dsn {
+ my( $class, $action, $dsn ) = @_;
+ $dsn =~ s/^(dbi:(\w*?)(?:\((.*?)\))?:)//i #nicked from DBI->connect
+ or '' =~ /()/; # ensure $1 etc are empty if match fails
+ my $prefix = $1 or die "can't parse data source: $dsn";
+
+ my $database;
+ if ( $dsn =~ s/(^|[;:])dbname=([^=:;]+)([;:]|$)/$1dbname=template1$3/ ) {
+ $database = $2;
+ } else {
+ die "can't parse data source: $prefix$dsn";
+ }
+
+ ( "$prefix$dsn", "\U$action\E DATABASE $database" );
+}
+
+=head1 AUTHOR
+
+Ivan Kohler <ivan-dbix-datasource@420.am>
+
+=head1 COPYRIGHT
+
+Copyright (c) 2000 Ivan Kohler
+Copyright (c) 2000 Mail Abuse Prevention System LLC
+All rights reserved.
+This program is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=head1 BUGS
+
+=head1 SEE ALSO
+
+L<DBIx::DataSource::Driver>, L<DBIx::DataSource>, L<DBD::Pg>, L<DBI>
+
+=cut
+
+1;
+