From: Stevan Little Date: Wed, 21 Mar 2007 04:01:21 +0000 (+0000) Subject: module refresh test X-Git-Tag: 0_19~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a05c504e2afdd5b9b3934d36b8ce2b5e15f052ef;p=gitmo%2FMoose.git module refresh test --- diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 583861f..6d486dd 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -71,10 +71,14 @@ sub unimport { $optimized = $_->{optimized} if exists $_->{optimized}; } - my $pkg_defined_in = scalar(caller(1)); + my $pkg_defined_in = scalar(caller(0)); + ($TYPES{$name}->[0] eq $pkg_defined_in) - || confess "The type constraint '$name' has already been created " - if defined $name && exists $TYPES{$name}; + || confess ("The type constraint '$name' has already been created in " + . $TYPES{$name}->[0] . " and cannot be created again in " + . $pkg_defined_in) + if defined $name && exists $TYPES{$name}; + $parent = find_type_constraint($parent) if defined $parent; my $constraint = Moose::Meta::TypeConstraint->new( name => $name || '__ANON__', diff --git a/t/105_module_refresh_bug.t b/t/105_module_refresh_bug.t index 088db05..8cbb31a 100644 --- a/t/105_module_refresh_bug.t +++ b/t/105_module_refresh_bug.t @@ -11,12 +11,74 @@ use Test::Exception; BEGIN { eval "use Module::Refresh;"; plan skip_all => "Module::Refresh is required for this test" if $@; - plan no_plan => 1; + plan tests => 18; } -use_ok('Bar'); +=pod + +First lets test some of our simple example modules ... + +=cut + +my @modules = qw[Foo Bar MyMooseA MyMooseB MyMooseObject]; + +do { + use_ok($_); + + is($_->meta->name, $_, '... initialized the meta correctly'); + + lives_ok { + Module::Refresh->new->refresh_module($_ . '.pm') + } '... successfully refreshed ' . $_; +} foreach @modules; + +=pod + +Now, lets try something a little trickier ... + +=cut + +my $test_module_file = 'TestBaz.pm'; + +my $test_module_source_1 = q| +package TestBaz; +use Moose; +has 'foo' => (is => 'ro', isa => 'Int'); +1; +|; + +my $test_module_source_2 = q| +package TestBaz; +use Moose; +extends 'Foo'; +has 'foo' => (is => 'rw', isa => 'Int'); +1; +|; + +{ + open FILE, ">", $test_module_file + || die "Could not open $test_module_file because $!"; + print FILE $test_module_source_1; + close FILE; +} + +use_ok('TestBaz'); +is(TestBaz->meta->name, 'TestBaz', '... initialized the meta correctly'); + +{ + open FILE, ">", $test_module_file + || die "Could not open $test_module_file because $!"; + print FILE $test_module_source_2; + close FILE; +} lives_ok { - Module::Refresh->new->refresh_module('Bar.pm') -} '... successfully refreshed Bar'; + Module::Refresh->new->refresh_module($test_module_file) +} '... successfully refreshed ' . $test_module_file; + +unlink $test_module_file; + + + +