Filename | /usr/local/lib/perl/5.14.2/Moose/Meta/Role/Attribute.pm |
Statements | Executed 21 statements in 627µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 8µs | 8µs | BEGIN@2 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 8µs | 11µs | BEGIN@9 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 7µs | 27µs | BEGIN@13 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 7µs | 15µs | BEGIN@10 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 7µs | 30µs | BEGIN@12 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 6µs | 78µs | BEGIN@16 | Moose::Meta::Role::Attribute::
1 | 1 | 1 | 6µs | 35µs | BEGIN@14 | Moose::Meta::Role::Attribute::
0 | 0 | 0 | 0s | 0s | __ANON__[:120] | 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 | # spent 8µs within Moose::Meta::Role::Attribute::BEGIN@2 which was called:
# once (8µs+0s) by Moose::Meta::Role::BEGIN@19 at line 4 | ||||
3 | 1 | 5µs | $Moose::Meta::Role::Attribute::AUTHORITY = 'cpan:STEVAN'; | ||
4 | 1 | 34µs | 1 | 8µs | } # spent 8µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@2 |
5 | { | ||||
6 | 2 | 1µs | $Moose::Meta::Role::Attribute::VERSION = '2.1005'; | ||
7 | } | ||||
8 | |||||
9 | 2 | 21µs | 2 | 13µs | # spent 11µs (8+3) within Moose::Meta::Role::Attribute::BEGIN@9 which was called:
# once (8µs+3µs) by Moose::Meta::Role::BEGIN@19 at line 9 # spent 11µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@9
# spent 3µs making 1 call to strict::import |
10 | 2 | 22µs | 2 | 23µs | # spent 15µs (7+8) within Moose::Meta::Role::Attribute::BEGIN@10 which was called:
# once (7µs+8µs) by Moose::Meta::Role::BEGIN@19 at line 10 # spent 15µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@10
# spent 8µs making 1 call to warnings::import |
11 | |||||
12 | 2 | 24µs | 2 | 54µs | # spent 30µs (7+24) within Moose::Meta::Role::Attribute::BEGIN@12 which was called:
# once (7µs+24µs) by Moose::Meta::Role::BEGIN@19 at line 12 # spent 30µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@12
# spent 24µs making 1 call to Exporter::import |
13 | 2 | 24µs | 2 | 47µs | # spent 27µs (7+20) within Moose::Meta::Role::Attribute::BEGIN@13 which was called:
# once (7µs+20µs) by Moose::Meta::Role::BEGIN@19 at line 13 # spent 27µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@13
# spent 20µs making 1 call to Exporter::import |
14 | 2 | 24µs | 2 | 64µs | # spent 35µs (6+29) within Moose::Meta::Role::Attribute::BEGIN@14 which was called:
# once (6µs+29µs) by Moose::Meta::Role::BEGIN@19 at line 14 # spent 35µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@14
# spent 29µs making 1 call to Exporter::import |
15 | |||||
16 | 2 | 428µs | 2 | 150µs | # spent 78µs (6+72) within Moose::Meta::Role::Attribute::BEGIN@16 which was called:
# once (6µs+72µs) by Moose::Meta::Role::BEGIN@19 at line 16 # spent 78µs making 1 call to Moose::Meta::Role::Attribute::BEGIN@16
# spent 72µs making 1 call to base::import |
17 | |||||
18 | 1 | 8µs | 3 | 741µs | __PACKAGE__->meta->add_attribute( # spent 424µs making 1 call to Class::MOP::Mixin::meta
# spent 311µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 6µs making 1 call to Class::MOP::_definition_context |
19 | 'metaclass' => ( | ||||
20 | reader => 'metaclass', | ||||
21 | Class::MOP::_definition_context(), | ||||
22 | ) | ||||
23 | ); | ||||
24 | |||||
25 | 1 | 3µs | 3 | 314µs | __PACKAGE__->meta->add_attribute( # spent 298µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 12µs making 1 call to Class::MOP::Mixin::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
26 | 'associated_role' => ( | ||||
27 | reader => 'associated_role', | ||||
28 | Class::MOP::_definition_context(), | ||||
29 | ) | ||||
30 | ); | ||||
31 | |||||
32 | 1 | 4µs | 3 | 309µs | __PACKAGE__->meta->add_attribute( # spent 293µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 11µs making 1 call to Class::MOP::Mixin::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
33 | '_original_role' => ( | ||||
34 | reader => '_original_role', | ||||
35 | Class::MOP::_definition_context(), | ||||
36 | ) | ||||
37 | ); | ||||
38 | |||||
39 | 1 | 4µs | 3 | 314µs | __PACKAGE__->meta->add_attribute( # spent 294µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 11µs making 1 call to Class::MOP::Mixin::meta
# spent 9µs making 1 call to Class::MOP::_definition_context |
40 | 'is' => ( | ||||
41 | reader => 'is', | ||||
42 | Class::MOP::_definition_context(), | ||||
43 | ) | ||||
44 | ); | ||||
45 | |||||
46 | 1 | 3µs | 3 | 355µs | __PACKAGE__->meta->add_attribute( # spent 339µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 11µs making 1 call to Class::MOP::Mixin::meta
# spent 5µs making 1 call to Class::MOP::_definition_context |
47 | 'original_options' => ( | ||||
48 | reader => 'original_options', | ||||
49 | Class::MOP::_definition_context(), | ||||
50 | ) | ||||
51 | ); | ||||
52 | |||||
53 | sub new { | ||||
54 | my ( $class, $name, %options ) = @_; | ||||
55 | |||||
56 | (defined $name) | ||||
57 | || confess "You must provide a name for the attribute"; | ||||
58 | |||||
59 | my $role = delete $options{_original_role}; | ||||
60 | |||||
61 | return bless { | ||||
62 | name => $name, | ||||
63 | original_options => \%options, | ||||
64 | _original_role => $role, | ||||
65 | %options, | ||||
66 | }, $class; | ||||
67 | } | ||||
68 | |||||
69 | sub attach_to_role { | ||||
70 | my ( $self, $role ) = @_; | ||||
71 | |||||
72 | ( blessed($role) && $role->isa('Moose::Meta::Role') ) | ||||
73 | || confess | ||||
74 | "You must pass a Moose::Meta::Role instance (or a subclass)"; | ||||
75 | |||||
76 | weaken( $self->{'associated_role'} = $role ); | ||||
77 | } | ||||
78 | |||||
79 | sub original_role { | ||||
80 | my $self = shift; | ||||
81 | |||||
82 | return $self->_original_role || $self->associated_role; | ||||
83 | } | ||||
84 | |||||
85 | sub attribute_for_class { | ||||
86 | my $self = shift; | ||||
87 | |||||
88 | my $metaclass = $self->original_role->applied_attribute_metaclass; | ||||
89 | |||||
90 | return $metaclass->interpolate_class_and_new( | ||||
91 | $self->name => %{ $self->original_options } ); | ||||
92 | } | ||||
93 | |||||
94 | sub clone { | ||||
95 | my $self = shift; | ||||
96 | |||||
97 | my $role = $self->original_role; | ||||
98 | |||||
99 | return ( ref $self )->new( | ||||
100 | $self->name, | ||||
101 | %{ $self->original_options }, | ||||
102 | _original_role => $role, | ||||
103 | ); | ||||
104 | } | ||||
105 | |||||
106 | sub is_same_as { | ||||
107 | my $self = shift; | ||||
108 | my $attr = shift; | ||||
109 | |||||
110 | my $self_options = $self->original_options; | ||||
111 | my $other_options = $attr->original_options; | ||||
112 | |||||
113 | return 0 | ||||
114 | unless ( join q{|}, sort keys %{$self_options} ) eq ( join q{|}, sort keys %{$other_options} ); | ||||
115 | |||||
116 | for my $key ( keys %{$self_options} ) { | ||||
117 | return 0 if defined $self_options->{$key} && ! defined $other_options->{$key}; | ||||
118 | return 0 if ! defined $self_options->{$key} && defined $other_options->{$key}; | ||||
119 | |||||
120 | next if all { ! defined } $self_options->{$key}, $other_options->{$key}; | ||||
121 | |||||
122 | return 0 unless $self_options->{$key} eq $other_options->{$key}; | ||||
123 | } | ||||
124 | |||||
125 | return 1; | ||||
126 | } | ||||
127 | |||||
128 | 1 | 21µs | 1; | ||
129 | |||||
130 | # ABSTRACT: The Moose attribute metaclass for Roles | ||||
131 | |||||
132 | __END__ |