s/make_immutable/metaclass->make_immutable/
[gitmo/Moose.git] / t / 000_recipes / 004_recipe.t
index 9e731c7..b5a9af2 100644 (file)
@@ -8,7 +8,7 @@ use Test::More;
 BEGIN {
     eval "use Regexp::Common; use Locale::US;";
     plan skip_all => "Regexp::Common & Locale::US required for this test" if $@;        
-    plan tests => 82;    
+    plan tests => 81;    
 }
 
 use Test::Exception;
@@ -45,7 +45,42 @@ BEGIN {
     has 'state'    => (is => 'rw', isa => 'USState');
     has 'zip_code' => (is => 'rw', isa => 'USZipCode');   
     
-    __PACKAGE__->meta->make_immutable(debug => 0);
+    metaclass->make_immutable(debug => 0);
+}{
+    
+    package Company;
+    use Moose;
+    use Moose::Util::TypeConstraints;    
+    
+    has 'name'      => (is => 'rw', isa => 'Str', required => 1);
+    has 'address'   => (is => 'rw', isa => 'Address'); 
+    has 'employees' => (is => 'rw', isa => 'ArrayRef[Employee]');    
+    
+    sub BUILD {
+        my ($self, $params) = @_;
+        if ($params->{employees}) {
+            foreach my $employee (@{$params->{employees}}) {
+                $employee->company($self);
+            }
+        }
+    }
+    
+    sub get_employee_count { scalar @{(shift)->employees} }
+    
+    after 'employees' => sub {
+        my ($self, $employees) = @_;
+        # if employees is defined, it 
+        # has already been type checked
+        if (defined $employees) {
+            # make sure each gets the 
+            # weak ref to the company
+            foreach my $employee (@{$employees}) {
+                $employee->company($self);
+            }            
+        }
+    };
+    
+    metaclass->make_immutable(debug => 0);
 }{    
     
     package Person;
@@ -63,7 +98,7 @@ BEGIN {
                $self->last_name;
     }
 
-    __PACKAGE__->meta->make_immutable(debug => 0);
+    metaclass->make_immutable(debug => 0);
 }{
       
     package Employee;
@@ -79,41 +114,7 @@ BEGIN {
         super() . ', ' . $self->title
     };
     
-    __PACKAGE__->meta->make_immutable(debug => 0);
-}{
-
-    package Company;
-    use Moose;   
-
-    has 'name'      => (is => 'rw', isa => 'Str', required => 1);
-    has 'address'   => (is => 'rw', isa => 'Address'); 
-    has 'employees' => (is => 'rw', isa => 'ArrayRef[Employee]');    
-
-    sub BUILD {
-        my ($self, $params) = @_;
-        if ($params->{employees}) {
-            foreach my $employee (@{$params->{employees}}) {
-                $employee->company($self);
-            }
-        }
-    }
-
-    sub get_employee_count { scalar @{(shift)->employees} }
-
-    after 'employees' => sub {
-        my ($self, $employees) = @_;
-        # if employees is defined, it 
-        # has already been type checked
-        if (defined $employees) {
-            # make sure each gets the 
-            # weak ref to the company
-            foreach my $employee (@{$employees}) {
-                $employee->company($self);
-            }            
-        }
-    };
-
-    __PACKAGE__->meta->make_immutable(debug => 0);
+    metaclass->make_immutable(debug => 0);
 }
 
 my $ii;
@@ -293,10 +294,6 @@ dies_ok {
     Company->new(name => 'Foo', employees => [ Person->new ]),    
 } '... we die correctly with good args';
 
-dies_ok {
-    Company->new(name => 'Foo', employees => [ Employee->new, Company->new ]),    
-} '... we die correctly with good args';
-
 lives_ok {
     Company->new(name => 'Foo', employees => []),    
 } '... we live correctly with good args';