App-Info
view release on metacpan or search on metacpan
lib/App/Info/RDBMS/PostgreSQL.pm view on Meta::CPAN
# Load data.
$get_version->($self) unless $self->{'--version'};
# Handle an unknown value.
unless ($self->{version}) {
# Create a validation code reference.
my $chk_version = sub {
# Try to get the version number parts.
my ($x, $y, $z) = /^(\d+)\.(\d+).(\d+)$/;
# Return false if we didn't get all three.
return unless $x and defined $y and defined $z;
# Save all three parts.
@{$self}{qw(major minor patch)} = ($x, $y, $z);
# Return true.
return 1;
};
$self->{version} = $self->unknown( key => 'postgres version number',
callback => $chk_version);
}
return $self->{version};
}
##############################################################################
=head3 major version
my $major_version = $pg->major_version;
Returns the PostgreSQL major version number. App::Info::RDBMS::PostgreSQL
parses the major version number from the system call C<`pg_config --version`>.
For example, if C<version()> returns "7.1.2", then this method returns "7".
B<Events:>
=over 4
=item info
Executing `pg_config --version`
=item error
Failed to find PostgreSQL version with `pg_config --version`
Unable to parse name from string
Unable to parse version from string
Failed to parse PostgreSQL version parts from string
=item unknown
Enter a valid PostgreSQL major version number
=back
=cut
# This code reference is used by major_version(), minor_version(), and
# patch_version() to validate a version number entered by a user.
my $is_int = sub { /^\d+$/ };
sub major_version {
my $self = shift;
return unless $self->{pg_config};
# Load data.
$get_version->($self) unless exists $self->{'--version'};
# Handle an unknown value.
$self->{major} = $self->unknown( key => 'postgres major version number',
callback => $is_int)
unless $self->{major};
return $self->{major};
}
##############################################################################
=head3 minor version
my $minor_version = $pg->minor_version;
Returns the PostgreSQL minor version number. App::Info::RDBMS::PostgreSQL
parses the minor version number from the system call C<`pg_config --version`>.
For example, if C<version()> returns "7.1.2", then this method returns "2".
B<Events:>
=over 4
=item info
Executing `pg_config --version`
=item error
Failed to find PostgreSQL version with `pg_config --version`
Unable to parse name from string
Unable to parse version from string
Failed to parse PostgreSQL version parts from string
=item unknown
Enter a valid PostgreSQL minor version number
=back
=cut
sub minor_version {
my $self = shift;
return unless $self->{pg_config};
# Load data.
$get_version->($self) unless exists $self->{'--version'};
# Handle an unknown value.
$self->{minor} = $self->unknown( key => 'postgres minor version number',
callback => $is_int)
unless defined $self->{minor};
return $self->{minor};
lib/App/Info/RDBMS/PostgreSQL.pm view on Meta::CPAN
# We found it. Confirm.
$self->{$key} = $self->confirm(
key => "path to $key",
prompt => "Path to $key executable?",
value => $exe,
callback => sub { -x },
error => 'Not an executable'
);
} else {
# Handle an unknown value.
$self->{$key} = $self->unknown(
key => "path to $key",
prompt => "Path to $key executable?",
callback => sub { -x },
error => 'Not an executable'
);
}
}
return $self->{$key};
};
for my $exe (@EXES) {
no strict 'refs';
*{$exe} = sub { shift->$find_exe($exe) };
*{"search_$exe\_names"} = sub { @{ shift->{"search_$exe\_names"} } }
}
*executable = \&postgres;
##############################################################################
=head3 bin_dir
my $bin_dir = $pg->bin_dir;
Returns the PostgreSQL binary directory path. App::Info::RDBMS::PostgreSQL
gathers the path from the system call C<`pg_config --bindir`>.
B<Events:>
=over 4
=item info
Executing `pg_config --bindir`
=item error
Cannot find bin directory
=item unknown
Enter a valid PostgreSQL bin directory
=back
=cut
# This code reference is used by bin_dir(), lib_dir(), and so_lib_dir() to
# validate a directory entered by the user.
my $is_dir = sub { -d };
sub bin_dir {
my $self = shift;
return unless $self->{pg_config};
unless (exists $self->{bin_dir} ) {
if (my $dir = $get_data->($self, '--bindir')) {
$self->{bin_dir} = $dir;
} else {
# Handle an unknown value.
$self->error("Cannot find bin directory");
$self->{bin_dir} = $self->unknown( key => 'postgres bin dir',
callback => $is_dir)
}
}
return $self->{bin_dir};
}
##############################################################################
=head3 inc_dir
my $inc_dir = $pg->inc_dir;
Returns the PostgreSQL include directory path. App::Info::RDBMS::PostgreSQL
gathers the path from the system call C<`pg_config --includedir`>.
B<Events:>
=over 4
=item info
Executing `pg_config --includedir`
=item error
Cannot find include directory
=item unknown
Enter a valid PostgreSQL include directory
=back
=cut
sub inc_dir {
my $self = shift;
return unless $self->{pg_config};
unless (exists $self->{inc_dir} ) {
if (my $dir = $get_data->($self, '--includedir')) {
$self->{inc_dir} = $dir;
} else {
# Handle an unknown value.
$self->error("Cannot find include directory");
$self->{inc_dir} = $self->unknown( key => 'postgres include dir',
callback => $is_dir)
}
( run in 0.829 second using v1.01-cache-2.11-cpan-39bf76dae61 )