X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FRole%2FApplication%2FToInstance.pm;h=d3cf68d6bd0f2a3233cd14c09c4e3da251ddcce9;hb=8de5717850eb1f406e5f71d2ccfac33c72cc490b;hp=8a15962686967465e2e4efd97e6f6bad71d0975c;hpb=fb1e11d526a7d3608132ba484525980e9fafcc4f;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Role/Application/ToInstance.pm b/lib/Moose/Meta/Role/Application/ToInstance.pm index 8a15962..d3cf68d 100644 --- a/lib/Moose/Meta/Role/Application/ToInstance.pm +++ b/lib/Moose/Meta/Role/Application/ToInstance.pm @@ -4,15 +4,41 @@ use strict; use warnings; use metaclass; -use Carp 'confess'; -use Scalar::Util 'blessed'; +use Scalar::Util 'blessed'; -use Data::Dumper; - -our $VERSION = '0.01'; +our $VERSION = '0.92'; +$VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; -use base 'Moose::Meta::Role::Application'; +use base 'Moose::Meta::Role::Application::ToClass'; + +__PACKAGE__->meta->add_attribute('rebless_params' => ( + reader => 'rebless_params', + default => sub { {} } +)); + +my %ANON_CLASSES; + +sub apply { + my ($self, $role, $object) = @_; + + my $anon_role_key = (blessed($object) . $role->name); + + my $class; + if (exists $ANON_CLASSES{$anon_role_key} && defined $ANON_CLASSES{$anon_role_key}) { + $class = $ANON_CLASSES{$anon_role_key}; + } + else { + my $obj_meta = Class::MOP::class_of($object) || 'Moose::Meta::Class'; + $class = $obj_meta->create_anon_class( + superclasses => [ blessed($object) ] + ); + $ANON_CLASSES{$anon_role_key} = $class; + $self->SUPER::apply($role, $class); + } + + $class->rebless_instance($object, %{$self->rebless_params}); +} 1; @@ -22,7 +48,7 @@ __END__ =head1 NAME -Moose::Meta::Role::Application::ToInstance +Moose::Meta::Role::Application::ToInstance - Compose a role into an instance =head1 DESCRIPTION @@ -34,6 +60,10 @@ Moose::Meta::Role::Application::ToInstance =item B +=item B + +=item B + =back =head1 BUGS @@ -48,7 +78,7 @@ Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE -Copyright 2006, 2007 by Infinity Interactive, Inc. +Copyright 2006-2009 by Infinity Interactive, Inc. L