|
NAMEParanoid::Input - Paranoid input functionsVERSION$Id: lib/Paranoid/Input.pm, 2.08 2020/12/31 12:10:06 acorliss Exp $SYNOPSISuse 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(); DESCRIPTIONThis provides some generic functions for working with text-based input. The main benefirst of this module is a relatively simple way of validating and detainting formatted text and performing platform-agnostic chomps.IMPORT LISTSThis module exports the following symbols by default:detaint stringMatch pchomp The following specialized import lists also exist: List Members -------------------------------------------------------- all @defaults NEWLINE_REGEX VARIABLESNEWLINE_REGEXThis returns regular expression that matches against DOS, UNIX, and legacy Mac line terminators. This is the regular expression used internally by pchomp to perform platform-agnostic chomps.This is only exported if explicity requested, or under an import target of :all. SUBROUTINES/METHODSdetaint$rv = detaint($userInput, "login", $val); This function populates the passed data object with the detainted input from the first argument. The second argument specifies the type of data in the first argument, and is used to validate the input before detainting. If you don't want to use one of the built-in regular expressions you can, instead, pass your own custom regular expression. The third argument is optional, but if used, must match the first argument's data type. If it is omitted all detainted values are used to overwrite the contents of the first argument. If detaint fails for any reason undef is used instead. If the first argument fails to match against these regular expressions the function will return 0. If the string passed is either undefined or a zero-length string it will also return 0. And finally, if you attempt to use an unknown (or unregistered) data type it will also return 0, and log an error message in Paranoid::ERROR. The following regular expressions are known by name: Name Description ========================================================= 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 function does a multiline case insensitive regex match against the input for every string passed for matching. This does safe quoted matches (\Q$string\E) for all the strings, unless the string is a perl Regexp (defined with qr//) or begins and ends with /. NOTE: this performs a study in hopes that for a large number of regexes will be performed faster. This may not always be the case. pchomp$rv = pchomp(@lines); pchomp is meant to be a drop-in replacement for chomp, primarily where you want it to work as a platform-agnostic line chomper. If $/ is altered in any manner (slurp mode, fixed record length, etc.) it will assume that's not important and automatically call chomp instead. It should, then, be safe to be called in all instances in which you'd call chomp itself. In a nutshell, this function attempts to avoid the assumption that chomp makes in that the latter assumes that all input it works upon was authored on the same system, using the same input record separators. Using pchomp in lieu of chomp will allow you to treat DOS, UNIX, and Mac-authored files identically with no additional coding. Because it is assumed that pchomp will be used in potentially high frequency scenarios no pdebug calls are made within it to avoid exercising the stack any more than necessary. It is hoped that the relative simplicity of the subroutine should make debug use unnecessary. DEPENDENCIES
BUGS AND LIMITATIONSAUTHORArthur Corliss (corliss@digitalmages.com)LICENSE AND COPYRIGHTThis software is free software. Similar to Perl, you can redistribute it and/or modify it under the terms of either:a) 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 b) 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)
Visit the GSP FreeBSD Man Page Interface. |