1#!perl -Tw 2 3package Foo; 4 5sub new { my $class = shift; return bless sub {}, $class; } 6 7package main; 8 9use warnings; 10use strict; 11 12use Test::More tests => 7; 13 14use Carp::Assert::More; 15 16local $@; 17$@ = ''; 18 19# {} is not a coderef 20eval { 21 assert_coderef( {} ); 22}; 23like( $@, qr/Assertion.*failed/ ); 24 25# a ref to a hash with stuff in it is not a coderef 26my $ref = { foo => 'foo', bar => 'bar' }; 27eval { 28 assert_coderef( $ref ); 29}; 30like( $@, qr/Assertion.*failed/ ); 31 32# 3 is not a coderef 33eval { 34 assert_coderef( 3 ); 35}; 36like( $@, qr/Assertion.*failed/ ); 37 38# [] is not a coderef 39eval { 40 assert_coderef( [] ); 41}; 42like( $@, qr/Assertion.*failed/ ); 43 44# a ref to a list with stuff in it is not a coderef 45my @ary = ('foo', 'bar', 'baaz'); 46eval { 47 assert_coderef( \@ary ); 48}; 49like( $@, qr/Assertion.*failed/ ); 50 51# sub {} is a coderef 52eval { 53 assert_coderef( sub {} ); 54}; 55is( $@, '' ); 56 57# Foo->new->isa("CODE") returns true, so do we 58eval { 59 assert_coderef( Foo->new ); 60}; 61is( $@, '' ); 62