#!/usr/bin/perl -w
my
$tmp
= tempdir(
CLEANUP
=> 1 );
my
$file
=
$tmp
.
"/"
.
'FooBar.pm'
;
push
@INC
,
$tmp
;
write_out(
<<".");
package Foo::Bar;
sub foo { 'bar' }
1;
.
use_ok(
'Module::Refresh'
);
use_ok(
'FooBar'
,
"Required our dummy module"
);
my
$r
= Module::Refresh->new();
can_ok(
'Foo::Bar'
,
'not_in_foobarpm'
);
is(Foo::Bar->foo,
'bar'
,
"We got the right result"
);
write_out(
<<".");
package Foo::Bar;
sub foo { 'baz' }
1;
.
is(Foo::Bar->foo,
'bar'
,
"We got the right result, still"
);
$r
->refresh;
is(Foo::Bar->foo,
'baz'
,
"We got the right new result,"
);
can_ok(
'Foo::Bar'
,
'not_in_foobarpm'
);
$r
->unload_subs(
$file
);
ok(!
defined
(
&Foo::Bar::foo
),
"We cleaned out the 'foo' method'"
);
sub
write_out {
local
*FH
;
open
FH,
"> $file"
or
die
"Cannot open $file: $!"
;
print
FH
$_
[0];
close
FH;
}
END {
unlink
$file
;
}
sub
not_in_foobarpm {
return
"woo"
;
}
1;