view release on metacpan or search on metacpan
lib/App/Info.pm view on Meta::CPAN
like "Path to your httpd executable?". If this parameter is not provided,
App::Info will construct one for you using your class' C<key_name()> method
and the C<key> parameter. The result would be something like "Enter a valid
FooApp version". The C<prompt> parameter value will be stored in the
C<message> attribute of the App::Info::Request object passed to event
handlers.
=item callback
Assuming a handler has collected a value for your unknown data point, it might
make sense to validate the value. For example, if you prompt the user for a
directory location, and the user enters one, it makes sense to ensure that the
directory actually exists. The C<callback> parameter allows you to do this. It
is a code reference that takes the new value or values as its arguments, and
returns true if the value is valid, and false if it is not. For the sake of
convenience, the first argument to the callback code reference is also stored
in C<$_> .This makes it easy to validate using functions or operators that,
er, operate on C<$_> by default, but still allows you to get more information
from C<@_> if necessary. For the directory example, a good callback might be
C<sub { -d }>. The C<callback> parameter code reference will be stored in the
C<callback> attribute of the App::Info::Request object passed to event
handlers.
=item error
The error parameter is the error message to display in the event that the
C<callback> code reference returns false. This message may then be used by the
lib/App/Info.pm view on Meta::CPAN
=item value
The value to be confirmed. This is the value you've found, and it will be
provided to the user as the default option when they're prompted for a new
value. This value will be stored in the C<value> attribute of the
App::Info::Request object passed to event handlers.
=item callback
Same as for C<unknown()>. Because the user can enter data to replace the
default value provided via the C<value> parameter, you might want to validate
it. Use this code reference to do so. The callback will be stored in the
C<callback> attribute of the App::Info::Request object passed to event
handlers.
=item error
Same as for C<unknown()>: an error message to display in the event that a
value entered by the user isn't validated by the C<callback> code reference.
This value will be stored in the C<error> attribute of the App::Info::Request
object passed to event handlers.
=back
Here's an example usage demonstrating all of the above arguments:
my $exe = $self->confirm( key => 'shell',
prompt => 'Path to your shell?',
value => '/bin/sh',
lib/App/Info/HTTPD/Apache.pm view on Meta::CPAN
=item unknown
Enter a valid Apache 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->{executable};
# Load data.
$get_version->($self) unless exists $self->{-v};
# Handle an unknown value.
$self->{major} = $self->unknown( key => 'apache major version number',
callback => $is_int)
lib/App/Info/HTTPD/Apache.pm view on Meta::CPAN
$_ =~ s/^-D\s+//;
$self->{lc $_} = 1;
}
}
# Issue a warning if no httpd root was found.
$self->error("Cannot parse HTTPD root from ",
qq{`"$self->{executable}" -V`}) unless $self->{httpd_root};
};
# This code reference is used by httpd_root(), lib_dir(), bin_dir(), and
# so_lib_dir() to validate a directory entered by the user.
my $is_dir = sub { -d };
sub httpd_root {
my $self = shift;
return unless $self->{executable};
# Get the compile settings.
$get_compile_settings->($self) unless $self->{-V};
# Handle an unknown value.
$self->{httpd_root} = $self->unknown( key => 'apache httpd root',
callback => $is_dir)
lib/App/Info/Handler/Prompt.pm view on Meta::CPAN
my $prompter = App::Info::Handler::Print->new;
my $app = App::Info::Category::FooApp->new( on_unknown => $prompter );
# Or...
my $app = App::Info::Category::FooApp->new( on_confirm => 'prompt' );
=head1 DESCRIPTION
App::Info::Handler::Prompt objects handle App::Info events by printing their
messages to C<STDOUT> and then accepting a new value from C<STDIN>. The new
value is validated by any callback supplied by the App::Info concrete subclass
that triggered the event. If the value is valid, App::Info::Handler::Prompt
assigns the new value to the event request. If it isn't it prints the error
message associated with the event request, and then prompts for the data
again.
Although designed with unknown and confirm events in mind,
App::Info::Handler::Prompt handles info and error events as well. It will
simply print info event messages to C<STDOUT> and print error event messages
to C<STDERR>. For more interesting info and error event handling, see
L<App::Info::Handler::Print|App::Info::Handler::Print> and
lib/App/Info/Lib/Expat.pm view on Meta::CPAN
Enter a valid Expat include directory
Enter a valid Expat 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->{libexpat};
# Get data.
$get_version->($self) unless exists $self->{version};
# Handle an unknown value.
lib/App/Info/Lib/Expat.pm view on Meta::CPAN
Cannot find include directory
=item unknown
Enter a valid Expat include directory
=back
=cut
# This code reference is used by inc_dir() and so_lib_dir() to validate a
# directory entered by the user.
my $is_dir = sub { -d };
sub inc_dir {
my $self = shift;
return unless $self->{libexpat};
unless (exists $self->{inc_dir}) {
$self->info("Searching for include directory");
my @incs = $self->search_inc_names;
lib/App/Info/Lib/Iconv.pm view on Meta::CPAN
Enter a valid libiconv include directory
Enter a valid libiconv version number
=back
=cut
# This code reference is used by major_version() and minor_version() to
# validate a version number entered by a user.
my $is_int = sub { /^\d+$/ };
sub major_version {
my $self = shift;
return unless $self->{executable};
# Get data.
$get_version->($self) unless exists $self->{version};
# Handle an unknown value.
lib/App/Info/Lib/Iconv.pm view on Meta::CPAN
Cannot find bin directory
=item unknown
Enter a valid libiconv bin directory
=back
=cut
# This code reference is used by inc_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->{executable};
unless (exists $self->{bin_dir}) {
# This is all probably redundant, but let's do the drill, anyway.
$self->info("Searching for bin directory");
if (my $bin = File::Basename::dirname($self->{executable})) {
lib/App/Info/Lib/OSSPUUID.pm view on Meta::CPAN
=item unknown
Enter a valid OSSP UUID 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->{uuid_config};
# Load data.
$get_version->($self) unless exists $self->{'--version'};
# Handle an unknown value.
$self->{major} = $self->unknown(
key => 'OSSP UUID major version number',
lib/App/Info/Lib/OSSPUUID.pm view on Meta::CPAN
=item unknown
Enter a valid OSSP UUID 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->{uuid_config};
unless (exists $self->{bin_dir} ) {
if (my $dir = $get_data->($self, '--bindir')) {
$self->{bin_dir} = $dir;
} else {
# Handle an unknown value.
lib/App/Info/RDBMS/PostgreSQL.pm view on Meta::CPAN
=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)
lib/App/Info/RDBMS/PostgreSQL.pm view on Meta::CPAN
=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.
lib/App/Info/RDBMS/SQLite.pm view on Meta::CPAN
=item unknown
Enter a valid SQLite 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->installed;
# Load data.
$get_version->($self) unless exists $self->{'--version'};
# Handle an unknown value.
$self->{major} = $self->unknown( key => 'sqlite major version number',
callback => $is_int)