Ask::Question - an object overloading coderefification to call Ask
use Ask::Question; use Types::Standard qw( ArrayRef Int ); my $question = Ask::Question->new( text => 'Enter numbers', type => ArrayRef[Int], default => sub { [0..9] }, ); my $arrayref_of_numbers = $question->(); my $more_numbers = $question->ask(); # alternative way to call
These overloaded objects work nicely as Moose and Moo defaults:
package Foo { use Moo; use Ask; has numbers => ( is => 'lazy', type => ArrayRef[Int], default => Ask::Q( text => 'Enter numbers', type => ArrayRef[Int], default => sub { [0..9] }, ), ); }
Note Ask::Q(...) is a shortcut for Ask::Question->new(...).
Ask::Q(...)
Ask::Question->new(...)
Ask::Question provides an alternative approach to using Ask to request information from a user.
Ask::Question provides a fairly standard Moose-like constructor taking a hash of attributes. There's also a shortcut for it in the Ask package. If there are an odd number of arguments passed to the constructor, it is assumed the first one if the text attribute.
text
my $question = Ask::Question->new( $text, %attributes ); my $question = Ask::Question->new( %attributes ); my $question = Ask::Question->new( \%attributes ); my $question = Ask::Q( $text, %attributes ); my $question = Ask::Q( %attributes ); my $question = Ask::Q( \%attributes );
The text of the question. If a coderef is given, that coderef will be forwarded any of the arguments to $question->(...).
$question->(...)
backend
A blessed object implementing Ask::API. Defaults to the result of Ask->detect.
Ask->detect
title
A title to use for question prompts, used by certain Ask backends.
type
A type constraint to check answers against. If the answer provided by the user fails a type check (after coercion, if the type has a coercion), they will be prompted to answer again.
spec
If this Ask::Question is being used as the default for an attrbute spec, this can be used to hold the specification hash for the attribute, and Ask::Question will attempt to find missing information like type from the spec hash.
multiple
Indicates that you want to return an arrayref of answers. If type is a subtype of ArrayRef, this will be inferred.
choices
List of valid choices if the question has a list of valid answers.
my $question = Ask::Question->new( "What size t-shirt would you like?", choices => [qw( XS S M L XL XXL )], );
If type is a parameterize Enum or ArrayRef[Enum], then this will be automatic.
coderef
Generating this coderef is the entire point of Ask::Question. You cannot provide this to the constructor.
default
A fallback to use if no interaction with the user is possible.
method
The method name to call on the backend, such as question or entry. See Ask::API. Generally speaking, Ask::Question will figure this out by itself.
question
entry
ask()
$question->ask(...) is a shortcut for $question->coderef->(...).
$question->ask(...)
$question->coderef->(...)
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=Ask.
Ask.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2020 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
To install Ask, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Ask
CPAN shell
perl -MCPAN -e shell install Ask
For more information on module installation, please visit the detailed CPAN module installation guide.