← Index
NYTProf Performance Profile   « block view • line view • sub view »
For bin/pan_genome_post_analysis
  Run on Fri Mar 27 11:43:32 2015
Reported on Fri Mar 27 11:45:36 2015

Filename/Users/ap13/perl5/lib/perl5/darwin-2level/Moose/Util/MetaRole.pm
StatementsExecuted 15 statements in 1.35ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1115.17ms6.77msMoose::Util::MetaRole::::BEGIN@10Moose::Util::MetaRole::BEGIN@10
11132µs116µsMoose::Util::MetaRole::::BEGIN@8Moose::Util::MetaRole::BEGIN@8
11127µs56µsMoose::Util::MetaRole::::BEGIN@4Moose::Util::MetaRole::BEGIN@4
11116µs28µsMoose::Util::MetaRole::::BEGIN@5Moose::Util::MetaRole::BEGIN@5
11116µs29µsMoose::Util::MetaRole::::BEGIN@9Moose::Util::MetaRole::BEGIN@9
11116µs63µsMoose::Util::MetaRole::::BEGIN@6Moose::Util::MetaRole::BEGIN@6
0000s0sMoose::Util::MetaRole::::__ANON__[:105]Moose::Util::MetaRole::__ANON__[:105]
0000s0sMoose::Util::MetaRole::::__ANON__[:59]Moose::Util::MetaRole::__ANON__[:59]
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;
211µsour $VERSION = '2.1403';
3
4246µs286µs
# spent 56µs (27+29) within Moose::Util::MetaRole::BEGIN@4 which was called: # once (27µs+29µs) by Moose::Exporter::BEGIN@10 at line 4
use strict;
# spent 56µs making 1 call to Moose::Util::MetaRole::BEGIN@4 # spent 29µs making 1 call to strict::import
5245µs239µs
# spent 28µs (16+11) within Moose::Util::MetaRole::BEGIN@5 which was called: # once (16µs+11µs) by Moose::Exporter::BEGIN@10 at line 5
use warnings;
# spent 28µs making 1 call to Moose::Util::MetaRole::BEGIN@5 # spent 11µs making 1 call to warnings::import
6255µs2110µs
# spent 63µs (16+47) within Moose::Util::MetaRole::BEGIN@6 which was called: # once (16µs+47µs) by Moose::Exporter::BEGIN@10 at line 6
use Scalar::Util 'blessed';
# spent 63µs making 1 call to Moose::Util::MetaRole::BEGIN@6 # spent 47µs making 1 call to Exporter::import
7
8382µs3157µs
# spent 116µs (32+85) within Moose::Util::MetaRole::BEGIN@8 which was called: # once (32µs+85µs) by Moose::Exporter::BEGIN@10 at line 8
use List::Util 1.33 qw( first all );
# spent 116µs making 1 call to Moose::Util::MetaRole::BEGIN@8 # spent 24µs making 1 call to UNIVERSAL::VERSION # spent 17µs making 1 call to List::Util::import
9244µs241µs
# spent 29µs (16+12) within Moose::Util::MetaRole::BEGIN@9 which was called: # once (16µs+12µs) by Moose::Exporter::BEGIN@10 at line 9
use Moose::Deprecated;
1021.07ms27.04ms
# spent 6.77ms (5.17+1.60) within Moose::Util::MetaRole::BEGIN@10 which was called: # once (5.17ms+1.60ms) by Moose::Exporter::BEGIN@10 at line 10
use Moose::Util 'throw_exception';
# spent 6.77ms making 1 call to Moose::Util::MetaRole::BEGIN@10 # spent 271µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337]
11
12sub apply_metaroles {
13 my %args = @_;
14
15 my $for = _metathing_for( $args{for} );
16
17 if ( $for->isa('Moose::Meta::Role') ) {
18 return _make_new_metaclass( $for, $args{role_metaroles}, 'role' );
19 }
20 else {
21 return _make_new_metaclass( $for, $args{class_metaroles}, 'class' );
22 }
23}
24
25sub _metathing_for {
26 my $passed = shift;
27
28 my $found
29 = blessed $passed
30 ? $passed
31 : Class::MOP::class_of($passed);
32
33 return $found
34 if defined $found
35 && blessed $found
36 && ( $found->isa('Moose::Meta::Role')
37 || $found->isa('Moose::Meta::Class') );
38
39 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
40
41 throw_exception( InvalidArgPassedToMooseUtilMetaRole => argument => $passed );
42}
43
44sub _make_new_metaclass {
45 my $for = shift;
46 my $roles = shift;
47 my $primary = shift;
48
49 return $for unless keys %{$roles};
50
51 my $new_metaclass
52 = exists $roles->{$primary}
53 ? _make_new_class( ref $for, $roles->{$primary} )
54 : blessed $for;
55
56 my %classes;
57
58 for my $key ( grep { $_ ne $primary } keys %{$roles} ) {
59 my $attr = first {$_}
60 map { $for->meta->find_attribute_by_name($_) } (
61 $key . '_metaclass',
62 $key . '_class'
63 );
64
65 my $reader = $attr->get_read_method;
66
67 $classes{ $attr->init_arg }
68 = _make_new_class( $for->$reader(), $roles->{$key} );
69 }
70
71 my $new_meta = $new_metaclass->reinitialize( $for, %classes );
72
73 return $new_meta;
74}
75
76sub apply_base_class_roles {
77 my %args = @_;
78
79 my $meta = _metathing_for( $args{for} || $args{for_class} );
80 throw_exception( CannotApplyBaseClassRolesToRole => params => \%args,
81 role_name => $meta->name,
82 )
83 if $meta->isa('Moose::Meta::Role');
84
85 my $new_base = _make_new_class(
86 $meta->name,
87 $args{roles},
88 [ $meta->superclasses() ],
89 );
90
91 $meta->superclasses($new_base)
92 if $new_base ne $meta->name();
93}
94
95sub _make_new_class {
96 my $existing_class = shift;
97 my $roles = shift;
98 my $superclasses = shift || [$existing_class];
99
100 return $existing_class unless $roles;
101
102 my $meta = Class::MOP::Class->initialize($existing_class);
103
104 return $existing_class
105 if $meta->can('does_role') && all { $meta->does_role($_) }
106 grep { !ref $_ } @{$roles};
107
108 return Moose::Meta::Class->create_anon_class(
109 superclasses => $superclasses,
110 roles => $roles,
111 cache => 1,
112 )->name();
113}
114
11517µs1;
116
117# ABSTRACT: Apply roles to any metaclass, as well as the object base class
118
119__END__