Paranoid::Input(3pm)

πŸ“¦
version 2.10 Β· 3 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– Paranoid::Input β€” like, the actual manual page, bestie πŸ’–

okay so this is Paranoid::Input(3pm), part of the user-contributed Perl docs, and it's literally just paranoid input functions and I'm obsessed ✨


πŸŽ€ NAME πŸŽ€

Paranoid::Input β€” paranoid input functions. that's it. that's the name. πŸ’…


🌸 VERSION 🌸

$Id: lib/Paranoid/Input.pm, 2.10 2022/03/08 00:01:04 acorliss $

✨ SYNOPSIS ✨

here's the whole vibe, copy-paste ready:

use Paranoid::Input;

$rv = detaint($userInput, "login", $detainted);
$rv = detaint(@userInput, "login", @detainted);
$rv = detaint(%userInput, "login", %detainted);

$rv = detaint($input, qr#\w+\s+\d+#s);
$rv = detaint(@input, qr#\w+\s+\d+#s);
$rv = detaint(%input, qr#\w+\s+\d+#s);

$rv = stringMatch($input, @strings);

$Paranoid::Input::regexes{'new_type"} = qr/\w\s+\d+/s;

$rv = pchomp($lines);
$rv = pchomp(@lines);
$rv = pchomp(%dict);

# Chomp $_
$rv = pchomp();

πŸ¦‹ DESCRIPTION πŸ¦‹

so this module is a lil collection of generic functions for working with text-based input, no cap. the main benefit (the original says "benefirst" which is a typo, we love her anyway 🫢) is that it gives you a pretty simple way to validate and detaint formatted text, plus it does platform-agnostic chomps. that's the whole serve. πŸ’–


🌈 IMPORT LISTS 🌈

by default this module exports these symbols, like automatically, no asking:

detaint stringMatch pchomp

and then there are these specialized import lists too:

List        Members
--------------------------------------------------------
all         @defaults NEWLINE_REGEX

⭐ VARIABLES ⭐

πŸŒ™ NEWLINE_REGEX

this one returns a regular expression that matches against DOS, UNIX, and legacy Mac line terminators. it's the exact regex pchomp uses internally to do its platform-agnostic chomping. iconic behavior honestly.

heads up bestie: this is only exported if you explicitly request it, or if you use an import target of :all. don't come for me when it's not just there, okay? πŸ™ˆ

πŸ’… SUBROUTINES/METHODS πŸ’…

πŸ’– detaint

$rv = detaint($userInput, "login", $val);

okay so this function populates the data object you pass in with the detainted input from the first argument. the second argument tells it what type of data the first argument is, and it uses that to validate the input before detainting. and if you don't wanna use one of the built-in regular expressions? you can just pass your own custom regex instead. periodt.

the third argument is optional, but if you do use it, it must match the first argument's data type. if you skip it, all the detainted values get used to overwrite the contents of the first argument. and if detaint fails for literally any reason, undef gets used instead. 😭

if the first argument doesn't match against those regexes, the function returns 0. if the string you passed is either undefined or a zero-length string, it also returns 0. and finally, if you try to use an unknown (or unregistered) data type it also returns 0 and logs an error message in Paranoid::ERROR. three strikes, all zeroes.

here are the regular expressions it knows by name:

  • alphabetic β€” Alphabetic characters
  • alphanumeric β€” Alphabetic/numeric characters
  • alphawhite β€” Alphabetic/whitespace characters
  • alnumwhite β€” Alphabetic/numeric/whitespace characters
  • email β€” RFC 822 Email address format
  • filename β€” Essentially no-metacharacters
  • fileglob β€” Same as filename, but with glob meta-character support
  • hostname β€” Alphanumeric/hyphenated host names
  • ipv4addr β€” IPv4 address
  • ipv4netaddr β€” IPv4 network address (CIDR/dotted quad)
  • ipv6addr β€” IPv6 address
  • ipv6netaddr β€” IPv6 network address (CIDR)
  • login β€” UNIX login format
  • nometa β€” Everything but meta-characters
  • number β€” Integer/float/signed/unsigned
  • int β€” Integer/signed/unsigned
  • uint β€” Integer/unsigned
  • float β€” Float/signed/unsigned
  • ufloat β€” Float/unsigned
  • bin β€” binary
  • octal β€” octal
  • hex β€” hexadecimal

🧚 stringMatch

$rv = stringMatch($input, @strings);

this one does a multiline, case insensitive regex match against the input, once for every string you passed in to match. it does safe quoted matches (\Q$string\E) for all the strings β€” unless the string is a perl Regexp (defined with qr//) or it begins and ends with /. iykyk. πŸ’œ

NOTE: this performs a study in hopes that for a large number of regexes it'll be performed faster. this may not always be the case. lowkey honest of them to say that.

πŸ“ pchomp

$rv = pchomp(@lines);

pchomp is meant to be a drop-in replacement for chomp, mainly for when you want it to work as a platform-agnostic line chomper. if $/ has been altered in any manner at all (slurp mode, fixed record length, whatever), it assumes that's not important and automatically calls chomp instead. so like, it should be safe to call it in all the instances where you'd call chomp itself. no cap. 🫢

in a nutshell: this function is trying to avoid the assumption that chomp makes, which is that all the input it works on was authored on the same system using the same input record separators. using pchomp instead of chomp lets you treat DOS, UNIX, and Mac-authored files identically with zero extra coding. the way that just... works. ✨

and because it's assumed pchomp will be used in potentially high-frequency scenarios, there are no pdebug calls made inside it β€” they wanted to avoid exercising the stack any more than necessary. the hope is that the relative simplicity of the subroutine makes debug use unnecessary. it's giving minimalism. it's giving efficiency. πŸ’€


πŸ”₯ DEPENDENCIES πŸ”₯

  • Carp
  • Paranoid
  • Paranoid::Debug

πŸ’€ BUGS AND LIMITATIONS πŸ’€

...nothing here. the section exists and it is empty. truly a flex. πŸ™ˆ


πŸ‘‘ AUTHOR πŸ‘‘

Arthur Corliss (corliss@digitalmages.com)


this software is free software. similar to Perl, you can redistribute it and/or modify it under the terms of either:

  1. the GNU General Public License <https://www.gnu.org/licenses/gpl-1.0.html> as published by the Free Software Foundation <http://www.fsf.org/>; either version 1 <https://www.gnu.org/licenses/gpl-1.0.html>, or any later version <https://www.gnu.org/licenses/license-list.html#GNUGPL>, or
  2. the Artistic License 2.0 <https://opensource.org/licenses/Artistic-2.0>,

subject to the following additional term: No trademark rights to "Paranoid" have been or are conveyed under any of the above licenses. However, "Paranoid" may be used fairly to describe this unmodified software, in good faith, but not as a trademark.

(c) 2005 - 2020, Arthur Corliss (corliss@digitalmages.com) (tm) 2008 - 2020, Paranoid Inc. (www.paranoid.com)


and that's the whole page bestie!! πŸ’–βœ¨ this was Paranoid::Input(3pm) from perl v5.38.2, dated 2024-03-07, and it was generated as part of the User Contributed Perl Documentation. go forth and detaint responsibly, mwah πŸŽ€πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from