Term::Interact

Term::Interact allows you to interactively get validated data.
Download

Term::Interact Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Phil R Lawrence
  • Publisher web site:
  • http://search.cpan.org/~prl/Term-Interact-0.44/Interact.pm

Term::Interact Tags


Term::Interact Description

Term::Interact allows you to interactively get validated data. Term::Interact allows you to interactively get validated data.SYNOPSIS use Term::Interact; my $ti = Term::Interact->new( @args ); # get validated data interactively $validated_data = $ti->get( @args ); # check existing data non-interactively die "Invalid!" unless $ti->validate( $data, @args );Term::Interact enables you to interactively get validated data from a user. This is accomplished via a simple API, wherein you specify various parameters for prompting the user, as well as "checks" with which gotten data will be validated.EXAMPLES # set up object with some optional parameters my $ti = Term::Interact->new( # set desired date formatting behavior # (See perldoc Date::Manip for syntax) date_format_display => '%d-%b-%Y', date_format_return => '%s', # database handle (see perldoc DBI) to # allow sql_checks. dbh => $dbh, ); my $num1 = $ti->get( msg => 'Enter a single digit number.', prompt => 'Go ahead, make my day: ', re_prompt => 'Try Again Here: ', check => , ); # # Resulting Interaction looks like: # # Enter a single digit number. # Go ahead, make my day: w # 'w' is not a single digit number! # Try Again Here: 23 # '23' is not a single digit number! # Try Again Here: 2 my $date = $ti->get ( type => 'date', name => 'Date from 2001', confirm => 1, check => , ] ); # # Resulting Interaction looks like: # # Date from 2001: Enter a value. # > 2002-03-12 # You entered: '12-Mar-2002'. Is this correct? (Y|n) # '12-Mar-2002' is not foo # 'foo' is not a valid date # > 2000-12-31 # You entered: '31-Dec-2000'. Is this correct? (Y|n) # '31-Dec-2000' is not >= 01/01/2001. # > 2001-02-13 # You entered: '13-Feb-2001'. Is this correct? (Y|n) my $states_aref = $ti->get ( msg => 'Please enter a comma delimited list of states.', prompt => 'State: ', re_prompt => 'Try Again: ', delimiter => ',', case => 'uc', dbh => $dbh, check => , ); # # Resulting Interaction looks like: # # Please enter a comma delimited list of states. # State: FOO # 'FOO' is not a valid state code. Valid codes are: AA, AB, AE, AK, # AL, AP, AQ, AR, AS, AZ, BC, CA, CO, CT, CZ, DC, DE, FL, FM, GA, GU, # HI, IA, ID, IL, IN, KS, KY, LA, LB, MA, MB, MD, ME, MH, MI, MN, MO, # MP, MS, MT, NB, NC, ND, NE, NF, NH, NJ, NM, NS, NT, NV, NY, OH, OK, # ON, OR, PA, PE, PQ, PR, PW, RI, RM, SC, SD, SK, TN, TT, TX, UT, VA, # VI, VT, WA, WI, WV, WY, YT # Try Again: az, pa my $num2 = $ti->get ( name => 'Number Less Than 10 and More than 3', check => , , ] ); # # Resulting Interaction looks like: # # Number Less Than 10 and More than 3: Enter a value. # > f # 'f' is not numeric. # > 1 # '1' is not > 3. # > -1 # '-1' is not > 3. # > 14 # '14' is not less than 10. # > 5 my $grades = $ti->get ( name => 'Letter grade', delimiter => ',', check => , ); # # Resulting Interaction looks like: # # Letter grade: Enter a value or list of values delimited with commas. # > 1 # > s # > X # > a, b # > A, B, C # If multiple checks are specified, the ordering # is preserved. In the example below, the sql_check # will be applied before the regex_check. my $foo = $ti->get ( name => $name, delimiter => $delim, check => , ); # multiple requests in one call to get method my ($foo, $bar) = $ti->get ( , ], # you can use an href if you prefer { name => 'bar', delimiter => ',', check => qr/kermit|der|frosch/, }, ] ); Requirements: · Perl


Term::Interact Related Software