| File | /usr/local/lib/perl/5.10.0/Moose/Meta/Role/Application/ToInstance.pm |
| Statements Executed | 20 |
| Total Time | 0.0004215 seconds |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToInstance::BEGIN |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToInstance::__ANON__[:17] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToInstance::apply |
| Line | Stmts. | Exclusive Time | Avg. | Code |
|---|---|---|---|---|
| 1 | package Moose::Meta::Role::Application::ToInstance; | |||
| 2 | ||||
| 3 | 3 | 25µs | 8µs | use strict; # spent 9µs making 1 call to strict::import |
| 4 | 3 | 28µs | 9µs | use warnings; # spent 36µs making 1 call to warnings::import |
| 5 | 3 | 48µs | 16µs | use metaclass; # spent 843µs making 1 call to metaclass::import |
| 6 | ||||
| 7 | 3 | 74µs | 25µs | use Scalar::Util 'blessed'; # spent 58µs making 1 call to Exporter::import |
| 8 | ||||
| 9 | 1 | 800ns | 800ns | our $VERSION = '1.15'; |
| 10 | 1 | 22µs | 22µs | $VERSION = eval $VERSION; |
| 11 | 1 | 500ns | 500ns | our $AUTHORITY = 'cpan:STEVAN'; |
| 12 | ||||
| 13 | 3 | 192µs | 64µs | use base 'Moose::Meta::Role::Application'; # spent 73µs making 1 call to base::import |
| 14 | ||||
| 15 | __PACKAGE__->meta->add_attribute('rebless_params' => ( | |||
| 16 | reader => 'rebless_params', | |||
| 17 | default => sub { {} } | |||
| 18 | 1 | 21µs | 21µs | )); # spent 587µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 25µs making 1 call to Moose::Meta::Role::Application::ToInstance::meta |
| 19 | ||||
| 20 | sub apply { | |||
| 21 | my ( $self, $role, $object, $args ) = @_; | |||
| 22 | ||||
| 23 | my $obj_meta = Class::MOP::class_of($object) || 'Moose::Meta::Class'; | |||
| 24 | ||||
| 25 | # This is a special case to handle the case where the object's metaclass | |||
| 26 | # is a Class::MOP::Class, but _not_ a Moose::Meta::Class (for example, | |||
| 27 | # when applying a role to a Moose::Meta::Attribute object). | |||
| 28 | $obj_meta = 'Moose::Meta::Class' | |||
| 29 | unless $obj_meta->isa('Moose::Meta::Class'); | |||
| 30 | ||||
| 31 | my $class = $obj_meta->create_anon_class( | |||
| 32 | superclasses => [ blessed($object) ], | |||
| 33 | roles => [ $role, keys(%$args) ? ($args) : () ], | |||
| 34 | cache => 1, | |||
| 35 | ); | |||
| 36 | ||||
| 37 | $class->rebless_instance( $object, %{ $self->rebless_params } ); | |||
| 38 | } | |||
| 39 | ||||
| 40 | 1 | 9µs | 9µs | 1; |
| 41 | ||||
| 42 | __END__ | |||
| 43 | ||||
| 44 | =pod | |||
| 45 | ||||
| 46 | =head1 NAME | |||
| 47 | ||||
| 48 | Moose::Meta::Role::Application::ToInstance - Compose a role into an instance | |||
| 49 | ||||
| 50 | =head1 DESCRIPTION | |||
| 51 | ||||
| 52 | =head2 METHODS | |||
| 53 | ||||
| 54 | =over 4 | |||
| 55 | ||||
| 56 | =item B<new> | |||
| 57 | ||||
| 58 | =item B<meta> | |||
| 59 | ||||
| 60 | =item B<apply> | |||
| 61 | ||||
| 62 | =item B<rebless_params> | |||
| 63 | ||||
| 64 | =back | |||
| 65 | ||||
| 66 | =head1 BUGS | |||
| 67 | ||||
| 68 | See L<Moose/BUGS> for details on reporting bugs. | |||
| 69 | ||||
| 70 | =head1 AUTHOR | |||
| 71 | ||||
| 72 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | |||
| 73 | ||||
| 74 | =head1 COPYRIGHT AND LICENSE | |||
| 75 | ||||
| 76 | Copyright 2006-2010 by Infinity Interactive, Inc. | |||
| 77 | ||||
| 78 | L<http://www.iinteractive.com> | |||
| 79 | ||||
| 80 | This library is free software; you can redistribute it and/or modify | |||
| 81 | it under the same terms as Perl itself. | |||
| 82 | ||||
| 83 | =cut | |||
| 84 |