Assert-Conditional

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

         If ASSERT_CONDITIONAL contains "handlers", don't block @SIG{__{WARN,DIE}__}.
         Don't let assert_isa die prematurely on an unblessed ref.

0.005    Sun May 20 20:40:25 CDT 2018
         Initial beta release.
	 Reworked the hash key checkers into a simpler set: assert_keys, assert_min_keys, assert_max_keys, assert_minmax_keys.
         Added invocant-specific assertions: assert_{object,class}_{isa,ainta,can,cant}.
         Added assertions for ties, overloads, and locked hashes.
         Made assert_private_method work despite Moose wrappers.
         Added assert_protected_method that works despite Moose wrappers and roles.
         Improved the looks of the uncompiled code for assert_happy_code.
         Improved the reporting of some assertion failures.

0.006    Mon May 21 07:45:43 CDT 2018
         Use hash_{,un}locked not hashref_{,un}locked to support pre-5.16 perls.
         Unhid assert_unblessed_ref swallowed up by stray pod.

0.007    Mon May 21 19:13:58 CDT 2018
         Add missing Hash::Util version requirement for old perls to get hashref_unlock imported.

0.008    Tue May 22 11:51:37 CDT 2018

lib/Assert/Conditional.pm  view on Meta::CPAN


use namespace::autoclean;

use Attribute::Handlers;
use Assert::Conditional::Utils ":all";
use Carp qw(carp croak cluck confess);
use POSIX ":sys_wait_h";

use Scalar::Util qw{
    blessed
    looks_like_number
    openhandle
    refaddr
    reftype
};

use Unicode::Normalize qw{
    NFC    checkNFC
    NFD    checkNFD
    NFKC   checkNFKC
    NFKD   checkNFKD

lib/Assert/Conditional.pm  view on Meta::CPAN

    assert_nonref($_) for $this, $that;
    $this ne $that              || botch "string '$this' should not be '$that'";
}

sub assert_numeric($)
    :Assert( qw[number] )
{
    &assert_defined;
    &assert_nonref;
    my($n) = @_;
    looks_like_number($n)       || botch "'$n' doesn't look like a number";
}

sub assert_nonnumeric($)
    :Assert( qw[number] )
{
    &assert_nonref;
    my($n) = @_;
   !looks_like_number($n)       || botch "'$n' looks like a number";
}

sub assert_positive($)
    :Assert( qw[number] )
{
    &assert_numeric;
    my($n) = @_;
    $n > 0                     || botch "$n should be positive";
}

lib/Assert/Conditional.pm  view on Meta::CPAN

Most of the assertions in this section treat their arguments as numbers.
When called on objects with operator overloads, their evaluation will
therefore trigger a C<0+> nummification overload in preference to a C<"">
stringification overload if the former exists. Otherwise normal fallback
rules apply as documented in the L<overload> pragma.

=over 

=item assert_numeric(I<EXPR>)

The defined non-ref argument looks like a number suitable for implicit
conversion according to the builtin L<Scalar::Util/looks_like_number>
predicate.

=item assert_nonnumeric(I<EXPR>)

The defined non-ref argument does I<not> look like a number suitable for
implicit conversion, again per L<Scalar::Util/looks_like_number>.

=item assert_positive(I<EXPR>)

The defined non-ref argument is numerically greater than zero.

=item assert_nonpositive(I<EXPR>)

The defined non-ref argument is numerically less than or equal to zero.

=item assert_negative(I<EXPR>)

lib/Assert/Conditional.pm  view on Meta::CPAN

        - If ASSERT_CONDITIONAL contains "handlers", don't block @SIG{__{WARN,DIE}__}.
        - Don't let assert_isa die prematurely on an unblessed ref.

 0.005   Sun May 20 20:40:25 CDT 2018
       - Initial beta release.
       - Reworked the hash key checkers into a simpler set: assert_keys, assert_min_keys, assert_max_keys, assert_minmax_keys.
       - Added invocant-specific assertions: assert_{object,class}_{isa,ainta,can,cant}.
       - Added assertions for ties, overloads, and locked hashes.
       - Made assert_private_method work despite Moose wrappers.
       - Added assert_protected_method that works despite Moose wrappers and roles.
       - Improved the looks of the uncompiled code for assert_happy_code.
       - Fixed botch() to identify the most distant stack frame not the nearest for the name of the failed assertion.
       - Improved the reporting of some assertion failures.

 0.006   Mon May 21 07:45:43 CDT 2018
       - Use hash_{,un}locked not hashref_{,un}locked to support pre-5.16 perls.
       - Unhid assert_unblessed_ref swallowed up by stray pod.

 0.007   Mon May 21 19:13:58 CDT 2018
       - Add missing Hash::Util version requirement for old perls to get hashref_unlock imported.



( run in 0.868 second using v1.01-cache-2.11-cpan-64827b87656 )