Tie::AssertEnforces restrictions on variables' contents | |
Download |
Tie::Assert Ranking & Summary
Advertisement
- License:
- Perl Artistic License
- Publisher Name:
- Paul Golds
- Publisher web site:
- http://search.cpan.org/~molt/
Tie::Assert Tags
Tie::Assert Description
Enforces restrictions on variables' contents Tie::Assert is a Perl module designed to fill the niche when Perl developers need to guarantee that a variable obeys certain rules at all times, times when users of others languages would rely on assert() and type-checking.This module is intended to be as flexible as possible, allowing the developer to use it to do things as basic as ensuring a variable is numeric and dying with an error message if not, up to ensuring a string contains a valid and existing account number, and mailing a support account if it's ever invalid.Flexibility is the primary goal here, this module's useful for working out where a program's setting it's variables to invalid values, to providing a certain added level of security by ensuring variables cannot be changed to out-of-range values.Anywhere a value has to remain within a particular range this module could potentially be useful.SYNOPSIS # Tie a few scalars... my $dna; tie ($dna, 'Tie::Assert::Scalar', sequenceCheck => Tie::Assert::CheckFactory->regex(qr/^*$/i), ); $dna = 'gattaca'; # Fine, it matches the regex. $dna = 'wibble'; # Doesn't match regex, will cause an error. my $percentage_score; tie ($percentage_score, 'Tie::Assert::Scalar', rangeCheck => Tie::Assert::CheckFactory->range(0 => 100), ); $percentage_score = 23; # Fine, well within the range provided. $percentage_score = 201; # An invalid percentage score, more errors. my $positive_integer; tie ($positive_integer, 'Tie::Assert::Scalar', positiveCheck => Tie::Assert::CheckFactory->min(0), integerCheck => Tie::Assert::CheckFactory->integer_ok(), ); $positive_number = 23; # A valid positive number $positive_number = -1; # Invalid, another error. Requirements: · Perl
Tie::Assert Related Software