s/DBIx::Database/DBIx::DataSource/
[DBIx-DataSource.git] / DataSource / Pg.pm
1 package DBIx::DataSource::Pg;
2
3 use strict;
4 use vars qw($VERSION @ISA);
5 use DBIx::DataSource::Driver;
6 @ISA = qw( DBIx::DataSource::Driver );
7
8 $VERSION = '0.01';
9
10 =head1 NAME
11
12 DBIx::DataSource::Pg - PostgreSQL driver for DBIx::DataSource
13
14 =head1 SYNOPSIS
15
16   use DBIx::DataSource;
17
18   use DBIx::DataSource qw( create_database drop_database );
19
20   create_database( "dbi:Pg:dbname=$dbname", $username, $password )
21     or warn $DBIx::DataSource::errstr;
22
23   create_database( "dbi:Pg:dbname=$dbname;host=$host;port=$port",
24                    $username, $password )
25     or warn $DBIx::DataSource::errstr;
26
27   drop_database( "dbi:Pg:dbname=$dbname", $username, $password )
28     or warn $DBIx::DataSource::errstr;
29
30   drop_database( "dbi:Pg:dbname=$dbname;host=$host;port=$port",
31                   $username, $password )
32     or warn $DBIx::DataSource::errstr;
33
34 =head1 DESCRIPTION
35
36 This is the PostgresSQL driver for DBIx::DataSource.
37
38 =cut
39
40 sub parse_dsn {
41   my( $class, $action, $dsn ) = @_;
42   $dsn =~ s/^(dbi:(\w*?)(?:\((.*?)\))?:)//i #nicked from DBI->connect
43                         or '' =~ /()/; # ensure $1 etc are empty if match fails
44   my $prefix = $1 or die "can't parse data source: $dsn";
45
46   my $database;
47   if ( $dsn =~ s/(^|[;:])dbname=([^=:;]+)([;:]|$)/$1dbname=template1$3/ ) {
48     $database = $2;
49   } else {
50     die "can't parse data source: $prefix$dsn";
51   }
52
53   ( "$prefix$dsn", "\U$action\E DATABASE $database" );
54 }
55
56 =head1 AUTHOR
57
58 Ivan Kohler <ivan-dbix-datasource@420.am>
59
60 =head1 COPYRIGHT
61
62 Copyright (c) 2000 Ivan Kohler
63 Copyright (c) 2000 Mail Abuse Prevention System LLC
64 All rights reserved.
65 This program is free software; you can redistribute it and/or modify it under
66 the same terms as Perl itself.
67
68 =head1 BUGS
69
70 =head1 SEE ALSO
71
72 L<DBIx::DataSource::Driver>, L<DBIx::DataSource>, L<DBD::Pg>, L<DBI>
73
74 =cut 
75
76 1;
77