← Index
NYTProf Performance Profile   « line view »
For fastest.pl
  Run on Fri Jan 31 20:48:16 2014
Reported on Fri Jan 31 20:49:40 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/darwin-thread-multi-2level/Moose/Util/MetaRole.pm
StatementsExecuted 20 statements in 1.01ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11116µs93µsMoose::Util::MetaRole::::BEGIN@15Moose::Util::MetaRole::BEGIN@15
11111µs11µsMoose::Util::MetaRole::::BEGIN@2Moose::Util::MetaRole::BEGIN@2
11110µs17µsMoose::Util::MetaRole::::BEGIN@16Moose::Util::MetaRole::BEGIN@16
1119µs14µsMoose::Util::MetaRole::::BEGIN@10Moose::Util::MetaRole::BEGIN@10
1119µs34µsMoose::Util::MetaRole::::BEGIN@17Moose::Util::MetaRole::BEGIN@17
1119µs34µsMoose::Util::MetaRole::::BEGIN@13Moose::Util::MetaRole::BEGIN@13
1119µs33µsMoose::Util::MetaRole::::BEGIN@14Moose::Util::MetaRole::BEGIN@14
1118µs37µsMoose::Util::MetaRole::::BEGIN@11Moose::Util::MetaRole::BEGIN@11
1118µs27µsMoose::Util::MetaRole::::BEGIN@9Moose::Util::MetaRole::BEGIN@9
0000s0sMoose::Util::MetaRole::::__ANON__[:131]Moose::Util::MetaRole::__ANON__[:131]
0000s0sMoose::Util::MetaRole::::__ANON__[:87]Moose::Util::MetaRole::__ANON__[:87]
0000s0sMoose::Util::MetaRole::::_make_new_classMoose::Util::MetaRole::_make_new_class
0000s0sMoose::Util::MetaRole::::_make_new_metaclassMoose::Util::MetaRole::_make_new_metaclass
0000s0sMoose::Util::MetaRole::::_metathing_forMoose::Util::MetaRole::_metathing_for
0000s0sMoose::Util::MetaRole::::apply_base_class_rolesMoose::Util::MetaRole::apply_base_class_roles
0000s0sMoose::Util::MetaRole::::apply_metarolesMoose::Util::MetaRole::apply_metaroles
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Moose::Util::MetaRole;
2
# spent 11µs within Moose::Util::MetaRole::BEGIN@2 which was called: # once (11µs+0s) by Moose::Exporter::BEGIN@15 at line 4
BEGIN {
316µs $Moose::Util::MetaRole::AUTHORITY = 'cpan:STEVAN';
4140µs111µs}
# spent 11µs making 1 call to Moose::Util::MetaRole::BEGIN@2
5{
621µs $Moose::Util::MetaRole::VERSION = '2.1005';
7}
8
9230µs246µs
# spent 27µs (8+19) within Moose::Util::MetaRole::BEGIN@9 which was called: # once (8µs+19µs) by Moose::Exporter::BEGIN@15 at line 9
use strict;
# spent 27µs making 1 call to Moose::Util::MetaRole::BEGIN@9 # spent 19µs making 1 call to strict::import
10230µs219µs
# spent 14µs (9+5) within Moose::Util::MetaRole::BEGIN@10 which was called: # once (9µs+5µs) by Moose::Exporter::BEGIN@15 at line 10
use warnings;
# spent 14µs making 1 call to Moose::Util::MetaRole::BEGIN@10 # spent 5µs making 1 call to warnings::import
11233µs265µs
# spent 37µs (8+28) within Moose::Util::MetaRole::BEGIN@11 which was called: # once (8µs+28µs) by Moose::Exporter::BEGIN@15 at line 11
use Scalar::Util 'blessed';
# spent 37µs making 1 call to Moose::Util::MetaRole::BEGIN@11 # spent 28µs making 1 call to Exporter::import
12
13233µs259µs
# spent 34µs (9+25) within Moose::Util::MetaRole::BEGIN@13 which was called: # once (9µs+25µs) by Moose::Exporter::BEGIN@15 at line 13
use Carp qw( croak );
# spent 34µs making 1 call to Moose::Util::MetaRole::BEGIN@13 # spent 25µs making 1 call to Exporter::import
14231µs258µs
# spent 33µs (9+24) within Moose::Util::MetaRole::BEGIN@14 which was called: # once (9µs+24µs) by Moose::Exporter::BEGIN@15 at line 14
use List::MoreUtils qw( all );
# spent 33µs making 1 call to Moose::Util::MetaRole::BEGIN@14 # spent 24µs making 1 call to Exporter::import
15234µs2105µs
# spent 93µs (16+78) within Moose::Util::MetaRole::BEGIN@15 which was called: # once (16µs+78µs) by Moose::Exporter::BEGIN@15 at line 15
use List::Util qw( first );
# spent 93µs making 1 call to Moose::Util::MetaRole::BEGIN@15 # spent 11µs making 1 call to List::Util::import
16232µs224µs
# spent 17µs (10+7) within Moose::Util::MetaRole::BEGIN@16 which was called: # once (10µs+7µs) by Moose::Exporter::BEGIN@15 at line 16
use Moose::Deprecated;
172731µs259µs
# spent 34µs (9+25) within Moose::Util::MetaRole::BEGIN@17 which was called: # once (9µs+25µs) by Moose::Exporter::BEGIN@15 at line 17
use Scalar::Util qw( blessed );
# spent 34µs making 1 call to Moose::Util::MetaRole::BEGIN@17 # spent 25µs making 1 call to Exporter::import
18
19sub apply_metaroles {
20 my %args = @_;
21
22 my $for = _metathing_for( $args{for} );
23
24 if ( $for->isa('Moose::Meta::Role') ) {
25 return _make_new_metaclass( $for, $args{role_metaroles}, 'role' );
26 }
27 else {
28 return _make_new_metaclass( $for, $args{class_metaroles}, 'class' );
29 }
30}
31
32sub _metathing_for {
33 my $passed = shift;
34
35 my $found
36 = blessed $passed
37 ? $passed
38 : Class::MOP::class_of($passed);
39
40 return $found
41 if defined $found
42 && blessed $found
43 && ( $found->isa('Moose::Meta::Role')
44 || $found->isa('Moose::Meta::Class') );
45
46 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
47
48 my $error_start
49 = 'When using Moose::Util::MetaRole, you must pass a Moose class name,'
50 . ' role name, metaclass object, or metarole object.';
51
52 if ( defined $found && blessed $found ) {
53 croak $error_start
54 . " You passed $passed, and we resolved this to a "
55 . ( blessed $found )
56 . ' object.';
57 }
58
59 if ( defined $passed && !defined $found ) {
60 croak $error_start
61 . " You passed $passed, and this did not resolve to a metaclass or metarole."
62 . ' Maybe you need to call Moose->init_meta to initialize the metaclass first?';
63 }
64
65 if ( !defined $passed ) {
66 croak $error_start
67 . " You passed an undef."
68 . ' Maybe you need to call Moose->init_meta to initialize the metaclass first?';
69 }
70}
71
72sub _make_new_metaclass {
73 my $for = shift;
74 my $roles = shift;
75 my $primary = shift;
76
77 return $for unless keys %{$roles};
78
79 my $new_metaclass
80 = exists $roles->{$primary}
81 ? _make_new_class( ref $for, $roles->{$primary} )
82 : blessed $for;
83
84 my %classes;
85
86 for my $key ( grep { $_ ne $primary } keys %{$roles} ) {
87 my $attr = first {$_}
88 map { $for->meta->find_attribute_by_name($_) } (
89 $key . '_metaclass',
90 $key . '_class'
91 );
92
93 my $reader = $attr->get_read_method;
94
95 $classes{ $attr->init_arg }
96 = _make_new_class( $for->$reader(), $roles->{$key} );
97 }
98
99 my $new_meta = $new_metaclass->reinitialize( $for, %classes );
100
101 return $new_meta;
102}
103
104sub apply_base_class_roles {
105 my %args = @_;
106
107 my $meta = _metathing_for( $args{for} || $args{for_class} );
108 croak 'You can only apply base class roles to a Moose class, not a role.'
109 if $meta->isa('Moose::Meta::Role');
110
111 my $new_base = _make_new_class(
112 $meta->name,
113 $args{roles},
114 [ $meta->superclasses() ],
115 );
116
117 $meta->superclasses($new_base)
118 if $new_base ne $meta->name();
119}
120
121sub _make_new_class {
122 my $existing_class = shift;
123 my $roles = shift;
124 my $superclasses = shift || [$existing_class];
125
126 return $existing_class unless $roles;
127
128 my $meta = Class::MOP::Class->initialize($existing_class);
129
130 return $existing_class
131 if $meta->can('does_role') && all { $meta->does_role($_) }
132 grep { !ref $_ } @{$roles};
133
134 return Moose::Meta::Class->create_anon_class(
135 superclasses => $superclasses,
136 roles => $roles,
137 cache => 1,
138 )->name();
139}
140
14113µs1;
142
143# ABSTRACT: Apply roles to any metaclass, as well as the object base class
144
145__END__