7 use Test::More tests => 3;
8 use Test::Builder; # Not loaded by default in modern mode
9 my $orig = Test::Builder->can('note');
12 package MyModernTester;
17 no warnings 'redefine';
18 local *Test::Builder::note = sub {
20 return $self->$orig(__PACKAGE__ . ": ", @_);
25 # Line number is tricky, just use what B says The sub may not actually think it
26 # is on the line it is may be off by 1.
27 my $line = B::svref_2object(\&Test::Builder::note)->START->line;
31 local $SIG{__WARN__} = sub { push @warnings => @_ };
38 qr{The new sub is 'MyModernTester::__ANON__' defined in $file around line $line},
39 undef, #Only 1 warning
41 "Found expected warning, just the one"
46 package MyModernTester2;
51 no warnings 'redefine';
52 local *Test::Builder::note = sub {
54 return $self->$orig(__PACKAGE__ . ": ", @_);
59 # Line number is tricky, just use what B says The sub may not actually think it
60 # is on the line it is may be off by 1.
61 my $line = B::svref_2object(\&Test::Builder::note)->START->line;
65 local $SIG{__WARN__} = sub { push @warnings => @_ };
72 qr{The new sub is 'MyModernTester2::__ANON__' defined in $file around line $line},
73 undef, #Only 1 warning
75 "new override, new warning"
80 package MyLegacyTester;
83 no warnings 'redefine';
84 local *Test::Builder::note = sub {
86 return $self->$orig(__PACKAGE__ . ": ", @_);
92 local $SIG{__WARN__} = sub { push @warnings => @_ };
96 is(@warnings, 0, "no warnings for a legacy tester");