File | /usr/local/lib/perl5/site_perl/5.10.1/MooseX/AttributeHelpers/MethodProvider/Hash.pm |
Statements Executed | 30 |
Statement Execution Time | 654µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
2 | 1 | 1 | 62µs | 93µs | set | MooseX::AttributeHelpers::MethodProvider::Hash::
2 | 1 | 1 | 30µs | 46µs | delete | MooseX::AttributeHelpers::MethodProvider::Hash::
1 | 1 | 1 | 13µs | 1.46ms | BEGIN@2 | MooseX::AttributeHelpers::MethodProvider::Hash::
0 | 0 | 0 | 0s | 0s | __ANON__[:101] | MooseX::AttributeHelpers::MethodProvider::Hash::
0 | 0 | 0 | 0s | 0s | __ANON__[:32] | MooseX::AttributeHelpers::MethodProvider::Hash::
0 | 0 | 0 | 0s | 0s | __ANON__[:49] | MooseX::AttributeHelpers::MethodProvider::Hash::
0 | 0 | 0 | 0s | 0s | __ANON__[:72] | MooseX::AttributeHelpers::MethodProvider::Hash::
0 | 0 | 0 | 0s | 0s | __ANON__[:87] | MooseX::AttributeHelpers::MethodProvider::Hash::
0 | 0 | 0 | 0s | 0s | __ANON__[:93] | MooseX::AttributeHelpers::MethodProvider::Hash::
0 | 0 | 0 | 0s | 0s | accessor | MooseX::AttributeHelpers::MethodProvider::Hash::
0 | 0 | 0 | 0s | 0s | clear | MooseX::AttributeHelpers::MethodProvider::Hash::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package MooseX::AttributeHelpers::MethodProvider::Hash; | ||||
2 | 3 | 512µs | 2 | 2.91ms | # spent 1.46ms (13µs+1.45) within MooseX::AttributeHelpers::MethodProvider::Hash::BEGIN@2 which was called
# once (13µs+1.45ms) by MooseX::AttributeHelpers::Trait::Collection::Hash::BEGIN@9 at line 2 # spent 1.46ms making 1 call to MooseX::AttributeHelpers::MethodProvider::Hash::BEGIN@2
# spent 1.45ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:389] |
3 | |||||
4 | 1 | 600ns | our $VERSION = '0.23'; | ||
5 | 1 | 14µs | $VERSION = eval $VERSION; | ||
6 | 1 | 300ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
7 | |||||
8 | 1 | 2µs | 1 | 6.03ms | with 'MooseX::AttributeHelpers::MethodProvider::ImmutableHash'; # spent 6.03ms making 1 call to Moose::Role::with |
9 | |||||
10 | # spent 93µs (62+31) within MooseX::AttributeHelpers::MethodProvider::Hash::set which was called 2 times, avg 46µs/call:
# 2 times (62µs+31µs) by Class::MOP::Class:::after at line 181 of MooseX/AttributeHelpers/Trait/Base.pm, avg 46µs/call | ||||
11 | 7 | 51µs | my ($attr, $reader, $writer) = @_; | ||
12 | if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) { # spent 5µs making 2 calls to Moose::Meta::Mixin::AttributeCore::type_constraint, avg 3µs/call
# spent 4µs making 2 calls to UNIVERSAL::isa, avg 2µs/call
# spent 4µs making 2 calls to Moose::Meta::Mixin::AttributeCore::has_type_constraint, avg 2µs/call | ||||
13 | my $container_type_constraint = $attr->type_constraint->type_parameter; # spent 3µs making 1 call to Moose::Meta::TypeConstraint::Parameterized::type_parameter
# spent 900ns making 1 call to Moose::Meta::Mixin::AttributeCore::type_constraint | ||||
14 | return sub { | ||||
15 | 9 | 39µs | my ( $self, @kvp ) = @_; | ||
16 | |||||
17 | my ( @keys, @values ); | ||||
18 | |||||
19 | while ( @kvp ) { | ||||
20 | my ( $key, $value ) = ( shift(@kvp), shift(@kvp) ); | ||||
21 | ($container_type_constraint->check($value)) # spent 43µs making 1 call to Moose::Meta::TypeConstraint::check | ||||
22 | || confess "Value " . ($value||'undef') . " did not pass container type constraint '$container_type_constraint'"; | ||||
23 | push @keys, $key; | ||||
24 | push @values, $value; | ||||
25 | } | ||||
26 | |||||
27 | if ( @values > 1 ) { | ||||
28 | @{ $reader->($self) }{@keys} = @values; | ||||
29 | } else { | ||||
30 | 1 | 2µs | 3 | 25µs | $reader->($self)->{$keys[0]} = $values[0]; # spent 17µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::1::get_class_attribute_map
# spent 8µs making 2 calls to Class::MOP::Method::__ANON__[Class/MOP/Method.pm:19], avg 4µs/call |
31 | } | ||||
32 | }; | ||||
33 | } | ||||
34 | else { | ||||
35 | return sub { | ||||
36 | 1 | 13µs | 3 | 128µs | if ( @_ == 3 ) { # spent 120µs making 1 call to Class::MOP::Class::__ANON__::SERIAL::1::_class_attribute_values
# spent 8µs making 2 calls to Class::MOP::Method::__ANON__[Class/MOP/Method.pm:19], avg 4µs/call |
37 | $reader->($_[0])->{$_[1]} = $_[2] | ||||
38 | } else { | ||||
39 | my ( $self, @kvp ) = @_; | ||||
40 | my ( @keys, @values ); | ||||
41 | |||||
42 | while ( @kvp ) { | ||||
43 | push @keys, shift @kvp; | ||||
44 | push @values, shift @kvp; | ||||
45 | } | ||||
46 | |||||
47 | @{ $reader->($_[0]) }{@keys} = @values; | ||||
48 | } | ||||
49 | }; | ||||
50 | } | ||||
51 | } | ||||
52 | |||||
53 | sub accessor : method { | ||||
54 | my ($attr, $reader, $writer) = @_; | ||||
55 | |||||
56 | if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) { | ||||
57 | my $container_type_constraint = $attr->type_constraint->type_parameter; | ||||
58 | return sub { | ||||
59 | my $self = shift; | ||||
60 | |||||
61 | if (@_ == 1) { # reader | ||||
62 | return $reader->($self)->{$_[0]}; | ||||
63 | } | ||||
64 | elsif (@_ == 2) { # writer | ||||
65 | ($container_type_constraint->check($_[1])) | ||||
66 | || confess "Value " . ($_[1]||'undef') . " did not pass container type constraint '$container_type_constraint'"; | ||||
67 | $reader->($self)->{$_[0]} = $_[1]; | ||||
68 | } | ||||
69 | else { | ||||
70 | confess "One or two arguments expected, not " . @_; | ||||
71 | } | ||||
72 | }; | ||||
73 | } | ||||
74 | else { | ||||
75 | return sub { | ||||
76 | my $self = shift; | ||||
77 | |||||
78 | if (@_ == 1) { # reader | ||||
79 | return $reader->($self)->{$_[0]}; | ||||
80 | } | ||||
81 | elsif (@_ == 2) { # writer | ||||
82 | $reader->($self)->{$_[0]} = $_[1]; | ||||
83 | } | ||||
84 | else { | ||||
85 | confess "One or two arguments expected, not " . @_; | ||||
86 | } | ||||
87 | }; | ||||
88 | } | ||||
89 | } | ||||
90 | |||||
91 | sub clear : method { | ||||
92 | my ($attr, $reader, $writer) = @_; | ||||
93 | return sub { %{$reader->($_[0])} = () }; | ||||
94 | } | ||||
95 | |||||
96 | # spent 46µs (30+16) within MooseX::AttributeHelpers::MethodProvider::Hash::delete which was called 2 times, avg 23µs/call:
# 2 times (30µs+16µs) by Class::MOP::Class:::after at line 181 of MooseX/AttributeHelpers/Trait/Base.pm, avg 23µs/call | ||||
97 | 4 | 13µs | my ($attr, $reader, $writer) = @_; | ||
98 | return sub { | ||||
99 | my $hashref = $reader->(shift); | ||||
100 | CORE::delete @{$hashref}{@_}; | ||||
101 | }; | ||||
102 | } | ||||
103 | |||||
104 | 1 | 6µs | 1; | ||
105 | |||||
106 | __END__ | ||||
107 | |||||
108 | =pod | ||||
109 | |||||
110 | =head1 NAME | ||||
111 | |||||
112 | MooseX::AttributeHelpers::MethodProvider::Hash | ||||
113 | |||||
114 | =head1 DESCRIPTION | ||||
115 | |||||
116 | This is a role which provides the method generators for | ||||
117 | L<MooseX::AttributeHelpers::Collection::Hash>. | ||||
118 | |||||
119 | This role is composed from the | ||||
120 | L<MooseX::AttributeHelpers::Collection::ImmutableHash> role. | ||||
121 | |||||
122 | =head1 METHODS | ||||
123 | |||||
124 | =over 4 | ||||
125 | |||||
126 | =item B<meta> | ||||
127 | |||||
128 | =back | ||||
129 | |||||
130 | =head1 PROVIDED METHODS | ||||
131 | |||||
132 | =over 4 | ||||
133 | |||||
134 | =item B<count> | ||||
135 | |||||
136 | Returns the number of elements in the hash. | ||||
137 | |||||
138 | =item B<delete> | ||||
139 | |||||
140 | Removes the element with the given key | ||||
141 | |||||
142 | =item B<defined> | ||||
143 | |||||
144 | Returns true if the value of a given key is defined | ||||
145 | |||||
146 | =item B<empty> | ||||
147 | |||||
148 | If the list is populated, returns true. Otherwise, returns false. | ||||
149 | |||||
150 | =item B<clear> | ||||
151 | |||||
152 | Unsets the hash entirely. | ||||
153 | |||||
154 | =item B<exists> | ||||
155 | |||||
156 | Returns true if the given key is present in the hash | ||||
157 | |||||
158 | =item B<get> | ||||
159 | |||||
160 | Returns an element of the hash by its key. | ||||
161 | |||||
162 | =item B<keys> | ||||
163 | |||||
164 | Returns the list of keys in the hash. | ||||
165 | |||||
166 | =item B<set> | ||||
167 | |||||
168 | Sets the element in the hash at the given key to the given value. | ||||
169 | |||||
170 | =item B<values> | ||||
171 | |||||
172 | Returns the list of values in the hash. | ||||
173 | |||||
174 | =item B<kv> | ||||
175 | |||||
176 | Returns the key, value pairs in the hash | ||||
177 | |||||
178 | =item B<accessor> | ||||
179 | |||||
180 | If passed one argument, returns the value of the requested key. If passed two | ||||
181 | arguments, sets the value of the requested key. | ||||
182 | |||||
183 | =back | ||||
184 | |||||
185 | =head1 BUGS | ||||
186 | |||||
187 | All complex software has bugs lurking in it, and this module is no | ||||
188 | exception. If you find a bug please either email me, or add the bug | ||||
189 | to cpan-RT. | ||||
190 | |||||
191 | =head1 AUTHOR | ||||
192 | |||||
193 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||
194 | |||||
195 | =head1 COPYRIGHT AND LICENSE | ||||
196 | |||||
197 | Copyright 2007-2009 by Infinity Interactive, Inc. | ||||
198 | |||||
199 | L<http://www.iinteractive.com> | ||||
200 | |||||
201 | This library is free software; you can redistribute it and/or modify | ||||
202 | it under the same terms as Perl itself. | ||||
203 | |||||
204 | =cut | ||||
205 |