Add IPC-AnyEvent-Gearman to the skip list
[gitmo/Moose.git] / t / compat / module_refresh_compat.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use lib 't/lib', 'lib';
7
8 use Test::More;
9 use Test::Fatal;
10
11 use File::Spec;
12 use File::Temp 'tempdir';
13
14 use Test::Requires {
15     'Module::Refresh' => '0.01', # skip all if not installed
16 };
17
18 =pod
19
20 First lets test some of our simple example modules ...
21
22 =cut
23
24 my @modules = qw[Foo Bar MyMooseA MyMooseB MyMooseObject];
25
26 do {
27     use_ok($_);
28
29     is($_->meta->name, $_, '... initialized the meta correctly');
30
31     is( exception {
32         Module::Refresh->new->refresh_module($_ . '.pm')
33     }, undef, '... successfully refreshed ' );
34 } foreach @modules;
35
36 =pod
37
38 Now, lets try something a little trickier
39 and actually change the module itself.
40
41 =cut
42
43 my $dir = tempdir( "MooseTest-XXXXX", CLEANUP => 1, TMPDIR => 1 );
44 push @INC, $dir;
45
46 my $test_module_file = File::Spec->catdir($dir, 'TestBaz.pm');
47
48 my $test_module_source_1 = q|
49 package TestBaz;
50 use Moose;
51 has 'foo' => (is => 'ro', isa => 'Int');
52 1;
53 |;
54
55 my $test_module_source_2 = q|
56 package TestBaz;
57 use Moose;
58 extends 'Foo';
59 has 'foo' => (is => 'rw', isa => 'Int');
60 1;
61 |;
62
63 {
64     open FILE, ">", $test_module_file
65         || die "Could not open $test_module_file because $!";
66     print FILE $test_module_source_1;
67     close FILE;
68 }
69
70 use_ok('TestBaz');
71 is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
72 ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
73 ok(!TestBaz->isa('Foo'), '... TestBaz is not a Foo');
74
75 {
76     open FILE, ">", $test_module_file
77         || die "Could not open $test_module_file because $!";
78     print FILE $test_module_source_2;
79     close FILE;
80 }
81
82 is( exception {
83     Module::Refresh->new->refresh_module('TestBaz.pm')
84 }, undef, '... successfully refreshed ' );
85
86 is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly');
87 ok(TestBaz->meta->has_attribute('foo'), '... it has the foo attribute as well');
88 ok(TestBaz->isa('Foo'), '... TestBaz is a Foo');
89
90 unlink $test_module_file;
91
92 done_testing;