File: 22_install2.t

package info (click to toggle)
libdata-util-perl 0.67-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 556 kB
  • sloc: perl: 2,958; ansic: 416; makefile: 8
file content (37 lines) | stat: -rw-r--r-- 702 bytes parent folder | download | duplicates (5)
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
29
30
31
32
33
34
35
36
37
#!perl -w

use strict;
use Test::More tests => 8;
use Test::Exception;

use Data::Util qw(:all);

install_subroutine(__PACKAGE__, { foo => sub{ 42 } });

lives_ok{
	is __PACKAGE__->foo(), 42;
};

uninstall_subroutine(__PACKAGE__, { foo => \&ok });

lives_ok{
	is __PACKAGE__->foo(), 42;
};

uninstall_subroutine(__PACKAGE__, { foo => undef });

throws_ok{
	__PACKAGE__->foo();
} qr/Can't locate object method "foo" via package "main"/;

install_subroutine(__PACKAGE__, { foo => sub{ 3.14 } });

lives_ok{
	is __PACKAGE__->foo(), 3.14;
};

uninstall_subroutine(__PACKAGE__, { foo => __PACKAGE__->can('foo') });

throws_ok{
	__PACKAGE__->foo();
} qr/Can't locate object method "foo" via package "main"/;