App::C...Prompt(3pm)

πŸ“¦
version 1.006 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute

πŸ’– App::Cmd::Plugin::Prompt πŸ’–

okay bestie, welcome to App::Cmd::Plugin::Prompt β€” the manual page, but make it cute. this is the lil plugin that lets you plug prompting routines straight into your App::Cmd commands. you get to ask your users stuff and they have to answer. it's giving interactive. it's giving main character energy. ✨


🌸 VERSION 🌸

version 1.006 β€” no cap, that's the one.


πŸŽ€ SYNOPSIS πŸŽ€

so here's the vibe. in your app, you set it up like this:

package MyApp;
use App::Cmd::Setup -app => {
  plugins => [ qw(Prompt) ],
};

and then in your command, you actually use it:

package MyApp::Command::dostuff;
use MyApp -command;

sub run {
  my ($self, $opt, $args) = @_;

  return unless prompt_yn('really do stuff?', { default => 1 });

  ...
}

like, imagine just asking "really do stuff?" and bailing if they say no. iconic behavior honestly. πŸ’…


πŸ¦‹ PERL VERSION πŸ¦‹

this library should run on perls released even a long time ago. it should work on any version of perl released in the last five years. she's flexible, she's adaptable, she's lowkey timeless.

although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. the version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.

translation bestie: don't come at her asking her to support your ancient perl. she said what she said. πŸ™ˆ

✨ SUBROUTINES ✨

πŸ’œ prompt_str

my $input = prompt_str($prompt, \%opt)

this one prompts a user for string input. it can be directed to persist until input is 'acceptable'. so if they type nonsense, she will simply ask again until they get it right. persistent queen. πŸ‘‘

valid options are:

  • input β€” optional coderef, which, when invoked, returns the user's response; default is to read from STDIN.
  • output β€” optional coderef, which, when invoked (with two arguments: the prompt and the choices/default), should prompt the user; default is to write to STDOUT.
  • valid β€” an optional coderef which any input is passed into and which must return true in order for the program to continue
  • default β€” may be any string; must pass the 'valid' coderef (if given)
  • choices β€” what to display after the prompt; default is either the 'default' parameter or nothing
  • no_valid_default β€” do not test the 'default' parameter against the 'valid' coderef
  • invalid_default_error β€” error message to throw when the 'default' parameter is not valid (does not pass the 'valid' coderef)

πŸ’– prompt_yn

my $bool = prompt_yn($prompt, \%opt);

this prompts the user for a yes or no response and won't give up until it gets one. she is nothing if not determined. it returns true for yes and false for no.

valid options are:

  • default β€” may be yes or no, indicating how to interpret an empty response; if empty, require an explicit answer; defaults to empty
ngl, if you leave it empty, there's no vibing your way out of answering. they must pick. 😀

🌈 prompt_any_key($prompt)

my $input = prompt_any_key($prompt);

this routine prompts the user to "press any key to continue." $prompt, if supplied, is the text to prompt with. classic move. the "any key" moment. we've all been there. 🫢


🌟 SEE ALSO 🌟

  • App::Cmd β€” the whole reason she exists, go say hi

πŸ’« AUTHOR πŸ’«

Ricardo Signes <cpan@semiotic.systems>

⭐ CONTRIBUTOR ⭐

Ricardo Signes <rjbs@semiotic.systems>


This software is copyright (c) 2004 by Ricardo Signes.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


and that's the whole page bestie!! πŸŽ€βœ¨ this was App::Cmd::Plugin::Prompt version 1.006, from the User Contributed Perl Documentation, dated 2023-01-24, running under perl v5.36.0. go prompt somebody. slay. πŸ’–

πŸ“¦ where this page comes from