Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/Role/Attribute.pm |
Statements | Executed 20 statements in 407µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 14µs | 52µs | BEGIN@7 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 8µs | 10µs | BEGIN@4 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 6µs | 154µs | BEGIN@12 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 5µs | 23µs | BEGIN@8 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 5µs | 33µs | BEGIN@10 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 4µs | 7µs | BEGIN@5 | Moose::Meta::Role::Attribute::
0 | 0 | 0 | 0s | 0s | __ANON__[:119] | Moose::Meta::Role::Attribute::
0 | 0 | 0 | 0s | 0s | attach_to_role | Moose::Meta::Role::Attribute::
0 | 0 | 0 | 0s | 0s | attribute_for_class | Moose::Meta::Role::Attribute::
0 | 0 | 0 | 0s | 0s | clone | Moose::Meta::Role::Attribute::
0 | 0 | 0 | 0s | 0s | is_same_as | Moose::Meta::Role::Attribute::
0 | 0 | 0 | 0s | 0s | new | Moose::Meta::Role::Attribute::
0 | 0 | 0 | 0s | 0s | original_role | Moose::Meta::Role::Attribute::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Moose::Meta::Role::Attribute; | ||||
2 | 1 | 300ns | our $VERSION = '2.1605'; | ||
3 | |||||
4 | 2 | 15µs | 2 | 11µs | # spent 10µs (8+2) within Moose::Meta::Role::Attribute::BEGIN@4 which was called:
# once (8µs+2µs) by Moose::Meta::Role::BEGIN@11 at line 4 # spent 10µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@4
# spent 2µs making 1 call to strict::import |
5 | 2 | 18µs | 2 | 11µs | # spent 7µs (4+3) within Moose::Meta::Role::Attribute::BEGIN@5 which was called:
# once (4µs+3µs) by Moose::Meta::Role::BEGIN@11 at line 5 # spent 7µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@5
# spent 3µs making 1 call to warnings::import |
6 | |||||
7 | 3 | 36µs | 3 | 71µs | # spent 52µs (14+37) within Moose::Meta::Role::Attribute::BEGIN@7 which was called:
# once (14µs+37µs) by Moose::Meta::Role::BEGIN@11 at line 7 # spent 52µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@7
# spent 10µs making 1 call to UNIVERSAL::VERSION
# spent 9µs making 1 call to List::Util::import |
8 | 2 | 18µs | 2 | 40µs | # spent 23µs (5+17) within Moose::Meta::Role::Attribute::BEGIN@8 which was called:
# once (5µs+17µs) by Moose::Meta::Role::BEGIN@11 at line 8 # spent 23µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@8
# spent 17µs making 1 call to Exporter::import |
9 | |||||
10 | 2 | 16µs | 2 | 60µs | # spent 33µs (5+28) within Moose::Meta::Role::Attribute::BEGIN@10 which was called:
# once (5µs+28µs) by Moose::Meta::Role::BEGIN@11 at line 10 # spent 33µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@10
# spent 28µs making 1 call to parent::import |
11 | |||||
12 | 2 | 285µs | 2 | 302µs | # spent 154µs (6+148) within Moose::Meta::Role::Attribute::BEGIN@12 which was called:
# once (6µs+148µs) by Moose::Meta::Role::BEGIN@11 at line 12 # spent 154µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@12
# spent 148µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
13 | |||||
14 | 1 | 6µs | 3 | 568µs | __PACKAGE__->meta->add_attribute( # spent 296µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 266µs making 1 call to Class::MOP::Mixin::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
15 | 'metaclass' => ( | ||||
16 | reader => 'metaclass', | ||||
17 | Class::MOP::_definition_context(), | ||||
18 | ) | ||||
19 | ); | ||||
20 | |||||
21 | 1 | 2µs | 3 | 253µs | __PACKAGE__->meta->add_attribute( # spent 244µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 6µs making 1 call to Class::MOP::Mixin::meta
# spent 3µs making 1 call to Class::MOP::_definition_context |
22 | 'associated_role' => ( | ||||
23 | reader => 'associated_role', | ||||
24 | Class::MOP::_definition_context(), | ||||
25 | ) | ||||
26 | ); | ||||
27 | |||||
28 | 1 | 2µs | 3 | 191µs | __PACKAGE__->meta->add_attribute( # spent 181µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 7µs making 1 call to Class::MOP::Mixin::meta
# spent 4µs making 1 call to Class::MOP::_definition_context |
29 | '_original_role' => ( | ||||
30 | reader => '_original_role', | ||||
31 | Class::MOP::_definition_context(), | ||||
32 | ) | ||||
33 | ); | ||||
34 | |||||
35 | 1 | 2µs | 3 | 180µs | __PACKAGE__->meta->add_attribute( # spent 171µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 6µs making 1 call to Class::MOP::Mixin::meta
# spent 3µs making 1 call to Class::MOP::_definition_context |
36 | 'is' => ( | ||||
37 | reader => 'is', | ||||
38 | Class::MOP::_definition_context(), | ||||
39 | ) | ||||
40 | ); | ||||
41 | |||||
42 | 1 | 2µs | 3 | 174µs | __PACKAGE__->meta->add_attribute( # spent 166µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 6µs making 1 call to Class::MOP::Mixin::meta
# spent 3µs making 1 call to Class::MOP::_definition_context |
43 | 'original_options' => ( | ||||
44 | reader => 'original_options', | ||||
45 | Class::MOP::_definition_context(), | ||||
46 | ) | ||||
47 | ); | ||||
48 | |||||
49 | sub new { | ||||
50 | my ( $class, $name, %options ) = @_; | ||||
51 | |||||
52 | (defined $name) | ||||
53 | || throw_exception( MustProvideANameForTheAttribute => params => \%options, | ||||
54 | class => $class | ||||
55 | ); | ||||
56 | |||||
57 | my $role = delete $options{_original_role}; | ||||
58 | |||||
59 | return bless { | ||||
60 | name => $name, | ||||
61 | original_options => \%options, | ||||
62 | _original_role => $role, | ||||
63 | %options, | ||||
64 | }, $class; | ||||
65 | } | ||||
66 | |||||
67 | sub attach_to_role { | ||||
68 | my ( $self, $role ) = @_; | ||||
69 | |||||
70 | ( blessed($role) && $role->isa('Moose::Meta::Role') ) | ||||
71 | || throw_exception( MustPassAMooseMetaRoleInstanceOrSubclass => class => $self, | ||||
72 | role => $role | ||||
73 | ); | ||||
74 | |||||
75 | weaken( $self->{'associated_role'} = $role ); | ||||
76 | } | ||||
77 | |||||
78 | sub original_role { | ||||
79 | my $self = shift; | ||||
80 | |||||
81 | return $self->_original_role || $self->associated_role; | ||||
82 | } | ||||
83 | |||||
84 | sub attribute_for_class { | ||||
85 | my $self = shift; | ||||
86 | |||||
87 | my $metaclass = $self->original_role->applied_attribute_metaclass; | ||||
88 | |||||
89 | return $metaclass->interpolate_class_and_new( | ||||
90 | $self->name => %{ $self->original_options } ); | ||||
91 | } | ||||
92 | |||||
93 | sub clone { | ||||
94 | my $self = shift; | ||||
95 | |||||
96 | my $role = $self->original_role; | ||||
97 | |||||
98 | return ( ref $self )->new( | ||||
99 | $self->name, | ||||
100 | %{ $self->original_options }, | ||||
101 | _original_role => $role, | ||||
102 | ); | ||||
103 | } | ||||
104 | |||||
105 | sub is_same_as { | ||||
106 | my $self = shift; | ||||
107 | my $attr = shift; | ||||
108 | |||||
109 | my $self_options = $self->original_options; | ||||
110 | my $other_options = $attr->original_options; | ||||
111 | |||||
112 | return 0 | ||||
113 | unless ( join q{|}, sort keys %{$self_options} ) eq ( join q{|}, sort keys %{$other_options} ); | ||||
114 | |||||
115 | for my $key ( keys %{$self_options} ) { | ||||
116 | return 0 if defined $self_options->{$key} && ! defined $other_options->{$key}; | ||||
117 | return 0 if ! defined $self_options->{$key} && defined $other_options->{$key}; | ||||
118 | |||||
119 | next if all { ! defined } $self_options->{$key}, $other_options->{$key}; | ||||
120 | |||||
121 | return 0 unless $self_options->{$key} eq $other_options->{$key}; | ||||
122 | } | ||||
123 | |||||
124 | return 1; | ||||
125 | } | ||||
126 | |||||
127 | 1 | 6µs | 1; | ||
128 | |||||
129 | # ABSTRACT: The Moose attribute metaclass for Roles | ||||
130 | |||||
131 | __END__ |