File: 08-isa-coderef.t

package info (click to toggle)
libtest-lwp-useragent-perl 0.036-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 428 kB
  • sloc: perl: 530; makefile: 10
file content (28 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use strict;
use warnings;

use Test::More 0.88;
use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';

use Test::LWP::UserAgent;

{
    package CodeRefOverload;
    use overload '&{}' => sub { sub { ::fail 'sub should not be called' } };
    sub new { bless {}, 'CodeRefOverload' }
}

my $string = 'ohhai';
my $scalarref = \$string;
my $coderef = sub { fail 'sub should not be called' };
my $nota_coderef = bless {}, 'NotaCodeRef';
my $isa_coderef = bless sub { fail 'sub should not be called' }, 'IsaCodeRef';

ok(!Test::LWP::UserAgent::__isa_coderef($string), 'string is not callable as a coderef');
ok(!Test::LWP::UserAgent::__isa_coderef($scalarref), 'scalarref is not callable as a coderef');
ok(Test::LWP::UserAgent::__isa_coderef($coderef), 'coderef is callable as a coderef');
ok(!Test::LWP::UserAgent::__isa_coderef($nota_coderef), 'blessed hash is not callable as a coderef');
ok(Test::LWP::UserAgent::__isa_coderef($isa_coderef), 'blessed coderef is callable as a coderef');
ok(Test::LWP::UserAgent::__isa_coderef(CodeRefOverload->new), 'object with code overload is callable as a coderef');

done_testing;