diff options
author | Jesse Luehrs <doy@tozt.net> | 2009-12-19 14:05:25 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2009-12-19 14:05:25 -0600 |
commit | 129e7fac6fc245bf498a8bbea34a74edb2147784 (patch) | |
tree | 01f80d6d673e7fee1a9482b86b0e77af06053100 /t/001-basic.t | |
parent | c34ffdfa73ddf5d1982f368b1e30364b17960f07 (diff) | |
download | moosex-module-refresh-129e7fac6fc245bf498a8bbea34a74edb2147784.tar.gz moosex-module-refresh-129e7fac6fc245bf498a8bbea34a74edb2147784.zip |
initial implementation
Diffstat (limited to 't/001-basic.t')
-rw-r--r-- | t/001-basic.t | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/t/001-basic.t b/t/001-basic.t new file mode 100644 index 0000000..05984d5 --- /dev/null +++ b/t/001-basic.t @@ -0,0 +1,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; |