composition and the role model are now decoupled
[gitmo/Moose.git] / lib / Moose / Meta / Role / Application / ToInstance.pm
index 8a15962..c0ee0e1 100644 (file)
@@ -12,7 +12,29 @@ use Data::Dumper;
 our $VERSION   = '0.01';
 our $AUTHORITY = 'cpan:STEVAN';
 
-use base 'Moose::Meta::Role::Application';
+use base 'Moose::Meta::Role::Application::ToClass';
+
+my $anon_counter = 0;
+
+sub apply {
+    my ($self, $role, $object) = @_;
+
+    # FIXME:
+    # We really should do this better, and
+    # cache the results of our efforts so
+    # that we don't need to repeat them.
+
+    my $pkg_name = __PACKAGE__ . "::__RUNTIME_ROLE_ANON_CLASS__::" . $anon_counter++;
+    eval "package " . $pkg_name . "; our \$VERSION = '0.00';";
+    die $@ if $@;
+
+    my $class = Moose::Meta::Class->initialize($pkg_name);
+    $class->superclasses(blessed($object));
+
+    bless $object => $class->name;   
+    
+    $self->SUPER::apply($role, $class); 
+}
 
 1;
 
@@ -34,6 +56,8 @@ Moose::Meta::Role::Application::ToInstance
 
 =item B<meta>
 
+=item B<apply>
+
 =back
 
 =head1 BUGS