From dc7bb5693a27402bd32dbd077525727aafcbc98c Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 25 Sep 2000 12:44:09 +0000 Subject: s/DBIx::Database/DBIx::DataSource/ --- DataSource/Pg.pm | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 DataSource/Pg.pm (limited to 'DataSource/Pg.pm') 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 + +=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, L, L, L + +=cut + +1; + -- cgit v1.2.1