Commit | Line | Data |
62067fd9 |
1 | use strict; |
2 | use warnings; |
4d09d73b |
3 | use Test::More tests => 5; |
62067fd9 |
4 | use Devel::Declare::MethodInstaller::Simple; |
5 | |
6 | BEGIN { |
7 | Devel::Declare::MethodInstaller::Simple->install_methodhandler( |
8 | name => 'method', |
9 | into => 'main', |
10 | ); |
11 | } |
12 | |
13 | BEGIN { |
14 | no warnings 'redefine'; |
15 | Devel::Declare::MethodInstaller::Simple->install_methodhandler( |
16 | name => 'method_quiet', |
17 | into => 'main', |
18 | ); |
19 | } |
20 | |
21 | ok(!main->can('foo'), 'foo() not installed yet'); |
22 | |
23 | method foo { |
24 | $_[0]->method |
25 | } |
26 | |
62067fd9 |
27 | ok(main->can('foo'), 'foo() installed at runtime'); |
28 | |
4d09d73b |
29 | my @warnings; |
30 | $SIG{__WARN__} = sub { push @warnings, $_[0] }; |
31 | |
32 | @warnings = (); |
33 | method foo { |
34 | $_[0]->method; |
35 | } |
36 | is scalar(@warnings), 1; |
37 | like $warnings[0], qr/redefined/; |
38 | |
39 | @warnings = (); |
40 | method_quiet foo { |
41 | $_[0]->method; |
42 | } |
43 | is_deeply \@warnings, []; |