Magic::Check - Add type/value checks to variables
version 0.003
use Magic::Check; use Types::Standard 'Int'; check_variable(my $var = 1, Int); $var = "abc"; # this will throw
check_variable($variable, $checker, $non_fatal = false)
This function takes a variable and adds set magic to check if the variable matches. This callback must be an object with a validate like provided by Type::Tiny: in must have a validate method that returns undef on success and an error message on failure.
validate
undef
If $non-fatal is not set and the new value does not match, the old value is restored and the message is thrown as an exception. If $non_fatal is set then it will warn with the same message but proceed as usual.
$non-fatal
$non_fatal
Leon Timmermans <leont@cpan.org>
This software is copyright (c) 2023 by Leon Timmermans.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Magic::Check, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Magic::Check
CPAN shell
perl -MCPAN -e shell install Magic::Check
For more information on module installation, please visit the detailed CPAN module installation guide.