App-Info
view release on metacpan or search on metacpan
lib/App/Info/RDBMS/PostgreSQL.pm view on Meta::CPAN
C<new()> also takes a number of optional parameters in addition to those
documented for App::Info. These parameters allow you to specify alternate
names for PostgreSQL executables (other than F<pg_config>, which you specify
via the C<search_exe_names> parameter). These parameters are:
=over
=item search_postgres_names
=item search_createdb_names
=item search_createlang_names
=item search_createuser_names
=item search_dropd_names
=item search_droplang_names
=item search_dropuser_names
=item search_initdb_names
=item search_pg_dump_names
=item search_pg_dumpall_names
=item search_pg_restore_names
=item search_postmaster_names
=item search_psql_names
=item search_vacuumdb_names
=back
B<Events:>
=over 4
=item info
Looking for pg_config
=item confirm
Path to pg_config?
=item unknown
Path to pg_config?
=back
=cut
sub new {
# Construct the object.
my $self = shift->SUPER::new(@_);
# Find pg_config.
$self->info("Looking for pg_config");
my @paths = $self->search_bin_dirs;
my @exes = $self->search_exe_names;
if (my $cfg = $u->first_cat_exe(\@exes, @paths)) {
# We found it. Confirm.
$self->{pg_config} = $self->confirm( key => 'path to pg_config',
prompt => "Path to pg_config?",
value => $cfg,
callback => sub { -x },
error => 'Not an executable');
} else {
# Handle an unknown value.
$self->{pg_config} = $self->unknown( key => 'path to pg_config',
prompt => "Path to pg_config?",
callback => sub { -x },
error => 'Not an executable');
}
# Set up search defaults.
for my $exe (@EXES) {
my $attr = "search_$exe\_names";
if (exists $self->{$attr}) {
$self->{$attr} = [$self->{$attr}] unless ref $self->{$attr} eq 'ARRAY';
} else {
$self->{$attr} = [];
}
}
return $self;
}
# We'll use this code reference as a common way of collecting data.
my $get_data = sub {
return unless $_[0]->{pg_config};
$_[0]->info(qq{Executing `"$_[0]->{pg_config}" $_[1]`});
my $info = `"$_[0]->{pg_config}" $_[1]`;
chomp $info;
return $info;
};
##############################################################################
=head2 Class Method
=head3 key_name
my $key_name = App::Info::RDBMS::PostgreSQL->key_name;
Returns the unique key name that describes this class. The value returned is
the string "PostgreSQL".
=cut
sub key_name { 'PostgreSQL' }
##############################################################################
lib/App/Info/RDBMS/PostgreSQL.pm view on Meta::CPAN
=cut
sub configure {
my $self = shift;
return unless $self->{pg_config};
unless (exists $self->{configure} ) {
if (my $conf = $get_data->($self, '--configure')) {
$self->{configure} = $conf;
} else {
# Configure can be empty, so just make sure it exists and is
# defined. Don't prompt.
$self->{configure} = '';
}
}
return $self->{configure};
}
##############################################################################
=head3 home_url
my $home_url = $pg->home_url;
Returns the PostgreSQL home page URL.
=cut
sub home_url { "http://www.postgresql.org/" }
##############################################################################
=head3 download_url
my $download_url = $pg->download_url;
Returns the PostgreSQL download URL.
=cut
sub download_url { "http://www.postgresql.org/mirrors-ftp.html" }
##############################################################################
=head3 search_exe_names
my @search_exe_names = $app->search_exe_names;
Returns a list of possible names for F<pg_config> executable. By default, only
F<pg_config> is returned (or F<pg_config.exe> on Win32).
Note that this method is not used to search for the PostgreSQL server
executable, only F<pg_config>.
=cut
sub search_exe_names {
my $self = shift;
my $exe = 'pg_config';
$exe .= '.exe' if WIN32;
return ($self->SUPER::search_exe_names, $exe);
}
##############################################################################
=head3 search_bin_dirs
my @search_bin_dirs = $app->search_bin_dirs;
Returns a list of possible directories in which to search an executable. Used
by the C<new()> constructor to find an executable to execute and collect
application info. The found directory will also be returned by the C<bin_dir>
method.
The list of directories by default consists of the path as defined by
C<< File::Spec->path >>, as well as the following directories:
=over 4
=item $ENV{POSTGRES_HOME}/bin (if $ENV{POSTGRES_HOME} exists)
=item $ENV{POSTGRES_LIB}/../bin (if $ENV{POSTGRES_LIB} exists)
=item /usr/local/pgsql/bin
=item /usr/local/postgres/bin
=item /opt/pgsql/bin
=item /usr/local/bin
=item /usr/local/sbin
=item /usr/bin
=item /usr/sbin
=item /bin
=item C:\Program Files\PostgreSQL\bin
=back
=cut
sub search_bin_dirs {
return shift->SUPER::search_bin_dirs,
( exists $ENV{POSTGRES_HOME}
? ($u->catdir($ENV{POSTGRES_HOME}, "bin"))
: ()
),
( exists $ENV{POSTGRES_LIB}
? ($u->catdir($ENV{POSTGRES_LIB}, $u->updir, "bin"))
: ()
),
$u->path,
qw(/usr/local/pgsql/bin
/usr/local/postgres/bin
/usr/lib/postgresql/bin
/opt/pgsql/bin
/usr/local/bin
/usr/local/sbin
/usr/bin
/usr/sbin
/bin),
'C:\Program Files\PostgreSQL\bin';
}
##############################################################################
=head2 Other Executable Methods
These methods function just like the C<executable()> method, except that they
return different executables. PostgreSQL comes with a fair number of them; we
provide these methods to provide a path to a subset of them. Each method, when
called, checks for an executable in the directory returned by C<bin_dir()>.
The name of the executable must be one of the names returned by the
corresponding C<search_*_names> method.
The available executable methods are:
=over
=item postgres
=item createdb
=item createlang
=item createuser
=item dropdb
=item droplang
=item dropuser
=item initdb
=item pg_dump
=item pg_dumpall
=item pg_restore
=item postmaster
( run in 1.102 second using v1.01-cache-2.11-cpan-98e64b0badf )