This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Filter::Util::Call to CPAN version 1.58
[perl5.git] / cpan / Filter-Util-Call / t / rt_54452-rebless.t
CommitLineData
f686c54e
CBW
1# RT #54452 check that filter_add does not rebless an already blessed
2# given object into the callers class.
3
4if ($] < 5.004_55) {
5 print "1..0\n";
6 exit 0;
7}
8
9use strict;
10use warnings;
0168e427 11BEGIN { unshift @INC, 't'; }
f686c54e 12
0168e427 13require "filter-util.pl" ;
f686c54e
CBW
14
15use vars qw( $Inc $Perl) ;
16
17my $file = "bless.test" ;
18my $module = "Foo";
19my $bless1 = "bless1" ;
20
21writeFile("t/Foo.pm", <<'EOM') ;
22package Foo;
23use strict;
24use warnings;
25our @ISA = ('Foo::Base');
26
27package Foo::Base;
28use Filter::Util::Call;
29sub import {
30 my ($class) = @_;
31 my $self = bless {}, $class;
32 print "before ", ref $self, "\n";
33 filter_add ($self);
34 print "after ", ref $self, "\n";
35}
36sub filter {
37 my ($self) = @_;
38 print "filter ", ref $self, "\n";
39 return 0;
40}
41
421;
43EOM
44
45my $fil1 = <<EOM;
46use lib 't';
47use Foo;
48print "this is filtered out\n";
49EOM
50
51writeFile($file, $fil1);
52
53my $a = `$Perl $Inc $file 2>&1` ;
54print "1..2\n" ;
55
56ok(1, ($? >> 8) == 0) ;
57chomp $a;
58ok(2, $a eq "before Foo
59after Foo
60filter Foo", "RT \#54452 " . $a);
61
62unlink $file or die "Cannot remove $file: $!\n" ;
63unlink "t/Foo.pm" or die "Cannot remove t/Foo.pm: $!\n" ;