summaryrefslogtreecommitdiffstats
path: root/t/002-moose.t
blob: 9141edaf443d98e4071c4fb11f431e62b1d19ec3 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 14;

use MooseX::Module::Refresh;

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

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

write_out(<<".");
package FooBar;
use Moose;
has foo => (is => 'ro', clearer => 'clear_foo');
sub bar { 'bar' }
1;
.

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

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

# is our non-file-based method available?

can_ok('FooBar', 'not_in_foobarpm');

can_ok('FooBar', 'new');
my $foobar = FooBar->new(foo => 'FOO');
is($foobar->bar, 'bar', "We got the right result");
is($foobar->foo, 'FOO', "We got the right result");
can_ok($foobar, 'clear_foo');

write_out(<<".");
package FooBar; 
has baz => (is => 'ro', predicate => 'foo');
sub quux { 'baz' }
1;
.

$foobar = FooBar->new(foo => 'FOO');
is($foobar->bar, 'bar', "We got the right result, still");
is($foobar->foo, 'FOO', "We got the right result, still");

$r->refresh;

$foobar = FooBar->new(baz => 'FOO');
is($foobar->quux, 'baz', "We got the right new result");
is($foobar->baz, 'FOO', "We got the right new result");
is($foobar->foo, 1, "We got the right new result");
ok(!$foobar->can('bar'), "the bar method was removed");
ok(!$foobar->can('clear_foo'), "the clear_foo method was removed");

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

# XXX: figure out what to do about unload_subs
#$r->unload_subs($file);
#ok(!defined(&FooBar::foo), "We cleaned out the 'foo' method'");

#ok(!UNIVERSAL::can('FooBar', 'foo'), "We cleaned out the 'foo' method'");
#require "FooBar.pm";
#is(FooBar->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 FooBar;
use Moose;

sub not_in_foobarpm {
    return "woo";
}

1;