summaryrefslogtreecommitdiffstats
path: root/t/001-basic.t
blob: 05984d58a21da7dba28c12d0d9f3d6b164ca2955 (plain) (blame)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 7;

use MooseX::Module::Refresh;

use File::Temp 'tempdir';
my $tmp = tempdir( CLEANUP => 1 );

my $file = $tmp."/".'FooBar.pm';
push @INC, $tmp;

write_out(<<".");
package Foo::Bar;
sub foo { 'bar' }
1;
.

use_ok('FooBar', "Required our dummy module");

my $r = MooseX::Module::Refresh->new();

# is our non-file-based method available?

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,");

# After a refresh, did we blow away our non-file-based comp?
can_ok('Foo::Bar', 'not_in_foobarpm');

$r->unload_subs($file);
ok(!defined(&Foo::Bar::foo), "We cleaned out the 'foo' method'");

#ok(!UNIVERSAL::can('Foo::Bar', 'foo'), "We cleaned out the 'foo' method'");
#require "FooBar.pm";
#is(Foo::Bar->foo, 'baz', "We got the right new result,");

sub write_out {
    local *FH;
    open FH, "> $file" or die "Cannot open $file: $!";
    print FH $_[0];
    close FH;
}

END {
    unlink $file;
}


package Foo::Bar;

sub not_in_foobarpm {
    return "woo";
}

1;