Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Class/MOP/Class/Immutable/Trait.pm |
Statements | Executed 2020 statements in 5.70ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
23 | 1 | 1 | 34µs | 34µs | _get_mutable_metaclass_name | Class::MOP::Class::Immutable::Trait::
1 | 1 | 1 | 10µs | 12µs | BEGIN@4 | Class::MOP::Class::Immutable::Trait::
1 | 1 | 1 | 6µs | 17µs | BEGIN@8 | Class::MOP::Class::Immutable::Trait::
1 | 1 | 1 | 5µs | 11µs | BEGIN@39 | Class::MOP::Class::Immutable::Trait::
1 | 1 | 1 | 5µs | 16µs | BEGIN@29 | Class::MOP::Class::Immutable::Trait::
1 | 1 | 1 | 4µs | 9µs | BEGIN@5 | Class::MOP::Class::Immutable::Trait::
1 | 1 | 1 | 3µs | 3µs | BEGIN@7 | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | __ANON__[:35] | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | __ANON__[:40] | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | __throw_exception | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | _immutable_cannot_call | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | _immutable_metaclass | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | _immutable_read_only | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | _method_map | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | class_precedence_list | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | get_all_attributes | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | get_all_method_names | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | get_all_methods | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | get_meta_instance | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | is_immutable | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | is_mutable | Class::MOP::Class::Immutable::Trait::
0 | 0 | 0 | 0s | 0s | linearized_isa | Class::MOP::Class::Immutable::Trait::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Class::MOP::Class::Immutable::Trait; | ||||
2 | 1 | 300ns | our $VERSION = '2.1605'; | ||
3 | |||||
4 | 2 | 16µs | 2 | 14µs | # spent 12µs (10+2) within Class::MOP::Class::Immutable::Trait::BEGIN@4 which was called:
# once (10µs+2µs) by Module::Runtime::require_module at line 4 # spent 12µs making 1 call to Class::MOP::Class::Immutable::Trait::BEGIN@4
# spent 2µs making 1 call to strict::import |
5 | 2 | 14µs | 2 | 14µs | # spent 9µs (4+5) within Class::MOP::Class::Immutable::Trait::BEGIN@5 which was called:
# once (4µs+5µs) by Module::Runtime::require_module at line 5 # spent 9µs making 1 call to Class::MOP::Class::Immutable::Trait::BEGIN@5
# spent 5µs making 1 call to warnings::import |
6 | |||||
7 | 2 | 14µs | 1 | 3µs | # spent 3µs within Class::MOP::Class::Immutable::Trait::BEGIN@7 which was called:
# once (3µs+0s) by Module::Runtime::require_module at line 7 # spent 3µs making 1 call to Class::MOP::Class::Immutable::Trait::BEGIN@7 |
8 | 2 | 95µs | 2 | 29µs | # spent 17µs (6+12) within Class::MOP::Class::Immutable::Trait::BEGIN@8 which was called:
# once (6µs+12µs) by Module::Runtime::require_module at line 8 # spent 17µs making 1 call to Class::MOP::Class::Immutable::Trait::BEGIN@8
# spent 12µs making 1 call to Module::Runtime::import |
9 | |||||
10 | # the original class of the metaclass instance | ||||
11 | 23 | 48µs | # spent 34µs within Class::MOP::Class::Immutable::Trait::_get_mutable_metaclass_name which was called 23 times, avg 1µs/call:
# 23 times (34µs+0s) by Class::MOP::Class::_real_ref_name at line 122 of Class/MOP/Class.pm, avg 1µs/call | ||
12 | |||||
13 | sub is_mutable { 0 } | ||||
14 | 23 | 26µs | sub is_immutable { 1 } | ||
15 | |||||
16 | sub _immutable_metaclass { ref $_[1] } | ||||
17 | |||||
18 | sub _immutable_read_only { | ||||
19 | my $name = shift; | ||||
20 | __throw_exception( CallingReadOnlyMethodOnAnImmutableInstance => method_name => $name ); | ||||
21 | } | ||||
22 | |||||
23 | sub _immutable_cannot_call { | ||||
24 | my $name = shift; | ||||
25 | __throw_exception( CallingMethodOnAnImmutableInstance => method_name => $name ); | ||||
26 | } | ||||
27 | |||||
28 | 1 | 500ns | for my $name (qw/superclasses/) { | ||
29 | 2 | 61µs | 2 | 27µs | # spent 16µs (5+11) within Class::MOP::Class::Immutable::Trait::BEGIN@29 which was called:
# once (5µs+11µs) by Module::Runtime::require_module at line 29 # spent 16µs making 1 call to Class::MOP::Class::Immutable::Trait::BEGIN@29
# spent 11µs making 1 call to strict::unimport |
30 | *{__PACKAGE__."::$name"} = sub { | ||||
31 | my $orig = shift; | ||||
32 | my $self = shift; | ||||
33 | _immutable_read_only($name) if @_; | ||||
34 | $self->$orig; | ||||
35 | 1 | 4µs | }; | ||
36 | } | ||||
37 | |||||
38 | 1 | 300ns | for my $name (qw/add_method alias_method remove_method add_attribute remove_attribute remove_package_symbol add_package_symbol/) { | ||
39 | 2 | 183µs | 2 | 17µs | # spent 11µs (5+6) within Class::MOP::Class::Immutable::Trait::BEGIN@39 which was called:
# once (5µs+6µs) by Module::Runtime::require_module at line 39 # spent 11µs making 1 call to Class::MOP::Class::Immutable::Trait::BEGIN@39
# spent 6µs making 1 call to strict::unimport |
40 | 7 | 14µs | *{__PACKAGE__."::$name"} = sub { _immutable_cannot_call($name) }; | ||
41 | } | ||||
42 | |||||
43 | sub class_precedence_list { | ||||
44 | my $orig = shift; | ||||
45 | my $self = shift; | ||||
46 | @{ $self->{__immutable}{class_precedence_list} | ||||
47 | ||= [ $self->$orig ] }; | ||||
48 | } | ||||
49 | |||||
50 | sub linearized_isa { | ||||
51 | 67 | 9µs | my $orig = shift; | ||
52 | 67 | 8µs | my $self = shift; | ||
53 | 67 | 124µs | 16 | 71µs | @{ $self->{__immutable}{linearized_isa} ||= [ $self->$orig ] }; # spent 71µs making 16 calls to Class::MOP::Class::linearized_isa, avg 4µs/call |
54 | } | ||||
55 | |||||
56 | sub get_all_methods { | ||||
57 | my $orig = shift; | ||||
58 | my $self = shift; | ||||
59 | @{ $self->{__immutable}{get_all_methods} ||= [ $self->$orig ] }; | ||||
60 | } | ||||
61 | |||||
62 | sub get_all_method_names { | ||||
63 | my $orig = shift; | ||||
64 | my $self = shift; | ||||
65 | @{ $self->{__immutable}{get_all_method_names} ||= [ $self->$orig ] }; | ||||
66 | } | ||||
67 | |||||
68 | sub get_all_attributes { | ||||
69 | 41 | 9µs | my $orig = shift; | ||
70 | 41 | 9µs | my $self = shift; | ||
71 | 41 | 91µs | 16 | 656µs | @{ $self->{__immutable}{get_all_attributes} ||= [ $self->$orig ] }; # spent 656µs making 16 calls to Class::MOP::Class::get_all_attributes, avg 41µs/call |
72 | } | ||||
73 | |||||
74 | sub get_meta_instance { | ||||
75 | 296 | 30µs | my $orig = shift; | ||
76 | 296 | 29µs | my $self = shift; | ||
77 | 296 | 4.49ms | 22 | 1.00ms | $self->{__immutable}{get_meta_instance} ||= $self->$orig; # spent 1.00ms making 22 calls to Class::MOP::Class::get_meta_instance, avg 46µs/call |
78 | } | ||||
79 | |||||
80 | sub _method_map { | ||||
81 | 246 | 27µs | my $orig = shift; | ||
82 | 246 | 28µs | my $self = shift; | ||
83 | 246 | 367µs | 24 | 48µs | $self->{__immutable}{_method_map} ||= $self->$orig; # spent 47µs making 19 calls to Class::MOP::Mixin::HasMethods::_method_map, avg 2µs/call
# spent 1µs making 5 calls to Class::MOP::Method::body, avg 260ns/call |
84 | } | ||||
85 | |||||
86 | # private method, for this file only - | ||||
87 | # if we declare a method here, it will behave differently depending on what | ||||
88 | # class this trait is applied to, so we won't have a reliable parameter list. | ||||
89 | sub __throw_exception { | ||||
90 | my ($exception_type, @args_to_exception) = @_; | ||||
91 | die use_module( "Moose::Exception::$exception_type" )->new( @args_to_exception ); | ||||
92 | } | ||||
93 | |||||
94 | 1 | 4µs | 1; | ||
95 | |||||
96 | # ABSTRACT: Implements immutability for metaclass objects | ||||
97 | |||||
98 | __END__ |