NAME

Magic::Check - Add type/value checks to variables

VERSION

version 0.003

SYNOPSIS

use Magic::Check;
use Types::Standard 'Int';

check_variable(my $var = 1, Int);

$var = "abc"; # this will throw

DESCRIPTION

FUNCTIONS

check_variable

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.

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.

AUTHOR

Leon Timmermans <leont@cpan.org>

COPYRIGHT AND LICENSE

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.