Package DE_EPAGES::Core::API::TestParameter
Use this module to test function parameters. Different functions are
available for testing different types of parameters. Range checks are
available where appropriate.
All functions throw an error if any test condition fails.
Example |
sub SetProductQuantity { my ($Basket, $ProductNo, $Quantity) = @_; TestObject( 'Basket', $Basket, 'DE_EPAGES::Order::API::Object::Basket' ); TestString( 'ProductNo', $ProductNo ); TestInteger( 'Quantity', $Quantity, 1, 100 ); ... } |
@EXPORT_OK |
Functions
- CheckDomainFormat
- CheckEMailAddrFormat
- ExtractAddrSpec
- TestArray
- TestDateTime
- TestDomain
- TestEMailAddress
- TestFloat
- TestHash
- TestInteger
- TestIpAddress
- TestLoop
- TestMultipleEMailAddresses
- TestObject
- TestPackage
- TestString
- TestUrl
CheckDomainFormat
Tests if the parameter $Domain is a valid domain name according to RFC1035. To test international domain names use DE_EPAGES::Core::API::IDN::IsValidIDN instead.
Syntax |
$ErrorCode = CheckDomainFormat($Domain); |
Example |
$ErrorCode = CheckDomainFormat('epages.de'); # ok $ErrorCode = CheckDomainFormat('müller.de'); # fail |
Input |
|
Output |
|
CheckEMailAddrFormat
Tests if the parameter $EMailAddress is an valid e-mail address according to RFC $Rfc (see http://tools.ietf.org/html/rfc5322 etc.). Use one of the following values for $Rfc: 2821 - Simple Mail Transfer Protocol; excludes contrary to RFC: folding white space, \n, comments in addr-spec, [IP in brackets] 2822 - Internet Message Format; excludes contrary to RFC: folding white space, \n, comments in addr-spec, [IP in brackets] 5321 - Simple Mail Transfer Protocol 5322 - Internet Message Format Default is RFC2822. *2 support angle-addr (<wolf@epages.de>); *1 do not.
Syntax |
CheckEMailAddrFormat($EMailAddress, $Rfc, $Debug); |
Example |
CheckEMailAddrFormat('max.mustermann@epages.de'); |
Input |
|
Output |
|
ExtractAddrSpec
Shortens $Address from angle-addr to addr-spec according to $Rfc. (see http://tools.ietf.org/html/rfc5322) Use one of the following values for $Rfc: 2822 - as defined by Mail::Address->parse($$Address) 5322 - RFC5322 Internet Message Format Default is RFC2822.
Syntax |
($ErrorCode, $ErrorMsg) = ExtractAddrSpec(\$Address, $Rfc); |
Example |
my $Address = '"Wolf Filss" <wfilss@epages.de>'; ($ErrorCode, $ErrorMsg) = ExtractAddrSpec( \$Address ); die "Error $ErrorCode ($ErrorMsg)" if defined $ErrorCode; print "Email: $Address"; # wfilss@epages.de |
Input |
|
Return |
|
TestArray
Tests if $aValue is an array reference.
Syntax |
TestArray($Name, $aValue); |
Example |
TestArray( 'Lines', $aLines ); |
Input |
|
TestDateTime
Tests if a string parameter is defined and contains at least one non - whitespace character. The function currently does not check the actual date or time format. Instead it maps directly to TestString.
Syntax |
TestDateTime($Name, $DateTime); |
Example |
TestDateTime('TestDate', '2004-04-05 18:09:10'); |
Input |
|
TestDomain
Tests if the parameter $Domain is a valid domain name according to RFC1035. This function accepts domain names starting with a digit, which would be forbidden according to RFC1035. To test international domain names use DE_EPAGES::Core::API::IDN::IsValidIDN instead.
Syntax |
TestDomain($Name, $Domain); |
Example |
TestDomain('Domain', 'epages.de'); # ok TestDomain('Domain', 'müller.de'); # fail |
Input |
|
TestEMailAddress
Tests if the parameter $EMailAddress is an valid e-mail address according to RFC $Rfc (see http://tools.ietf.org/html/rfc5322 etc.). Use one of the following values for $Rfc: 2821 - Simple Mail Transfer Protocol; excludes contrary to RFC: unquoted or folding white space, \n, comments in addr-spec, [IP in brackets] 2822 - Internet Message Format; excludes contrary to RFC: unquoted or folding white space, \n, comments in addr-spec, [IP in brackets] 5321 - Simple Mail Transfer Protocol 5322 - Internet Message Format Default is RFC2822. *2 support angle-addr (<wolf@epages.de>); *1 do not.
Syntax |
TestEMailAddress($Name, $EMailAddress, $Rfc); |
Example |
TestEMailAddress('PrivateEMail', 'max.mustermann@epages.de'); |
Input |
|
TestFloat
Tests if the parameter $Float is a floating point number.
Syntax |
TestFloat( $Name, $Float, $MinValue, $MaxValue); |
Example |
TestFloat('TestFloat', -1.12E-34); |
Input |
|
TestHash
Tests if the parameter is a hash and tests if all parameters have correct values.
Syntax |
$result = TestHash($Name, $hParameter, $hParameterKeys, $NonUsedKeys); |
Example |
TestHash('hParameter', $hParameter, {'Number'=>'Integer;NotNull'}); |
Input |
|
TestInteger
Tests if the parameter $Integer is an integer number. Tests the value range ($MinValue..$MaxValue) if not defined use default range (-2147483648..2147483647)
Syntax |
TestInteger($Name, $Integer); TestInteger($Name, $Integer, $MinValue, $MaxValue); |
Example |
TestInteger('TestNumber', 1233); |
Input |
|
TestIpAddress
Tests if the parameter $IpAddress is an IpAddress.
Syntax |
TestIpAddress($Name, $IpAddress); |
Example |
TestIpAddress('ClientIP', '123.120.34.254'); |
Input |
|
TestLoop
Tests if each item of the loop has the correct keys. Tests array with TestArray and each item with TestHash.
Syntax |
$result = TestLoop($ParameterName, $rhParameterKeys, $rahParameter, $NonUsedKeys); |
Input |
|
TestMultipleEMailAddresses
Tests if the parameter $EMailAddresses contains only valid email addresses.
Syntax |
TestMultipleEMailAddresses($Name, $EMailAddresses); |
Example |
TestMultipleEMailAddresses('PrivateEMailAddresses', 'max.mustermann@epages.de; maria.musterfrau@epages.de'); |
Input |
|
TestObject
Tests if the parameter $Object is defined and is a blessed object. Also tests if $Object is an instance of the class $ClassPackage using UNIVERSAL::isa().
Syntax |
TestObject($Name, $Object); TestObject($Name, $Object, $ClassPackage); |
Input |
|
TestPackage
Tests if the package exists in @INC.
Syntax |
TestPackage($PackageName); |
Example |
TestPackage('SharedLib::Error'); |
Input |
|
TestString
Tests if a string parameter is defined and contains at least one non-space character. Optionally checks the minimum and/or maximum string length in characters. Throws an error if the parameter is not correct.
Syntax |
TestString($Name, $String ); TestString($Name, $String ,$MinLength ); TestString($Name, $String ,$MinLength, $MaxLength ); |
Example |
TestString('Keyword', $Keyword); TestString('Keyword', $Keyword, 1, 30); |
Input |
|
TestUrl
Tests if the parameter $Url is a url.
Syntax |
TestUrl($Name, $Url); |
Example |
TestUrl('SubmitUrl', 'http://www.epages.de/index.html'); |
Input |
|