← Index
NYTProf Performance Profile   « block view • line view • sub view »
For 05.Domain_and_Item.t
  Run on Tue May 4 17:21:41 2010
Reported on Tue May 4 17:22:46 2010

File /usr/local/lib/perl5/site_perl/5.10.1/MooseX/AttributeHelpers/MethodProvider/Hash.pm
Statements Executed 30
Statement Execution Time 654µs
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
21162µs93µsMooseX::AttributeHelpers::MethodProvider::Hash::::setMooseX::AttributeHelpers::MethodProvider::Hash::set
21130µs46µsMooseX::AttributeHelpers::MethodProvider::Hash::::deleteMooseX::AttributeHelpers::MethodProvider::Hash::delete
11113µs1.46msMooseX::AttributeHelpers::MethodProvider::Hash::::BEGIN@2MooseX::AttributeHelpers::MethodProvider::Hash::BEGIN@2
0000s0sMooseX::AttributeHelpers::MethodProvider::Hash::::__ANON__[:101]MooseX::AttributeHelpers::MethodProvider::Hash::__ANON__[:101]
0000s0sMooseX::AttributeHelpers::MethodProvider::Hash::::__ANON__[:32]MooseX::AttributeHelpers::MethodProvider::Hash::__ANON__[:32]
0000s0sMooseX::AttributeHelpers::MethodProvider::Hash::::__ANON__[:49]MooseX::AttributeHelpers::MethodProvider::Hash::__ANON__[:49]
0000s0sMooseX::AttributeHelpers::MethodProvider::Hash::::__ANON__[:72]MooseX::AttributeHelpers::MethodProvider::Hash::__ANON__[:72]
0000s0sMooseX::AttributeHelpers::MethodProvider::Hash::::__ANON__[:87]MooseX::AttributeHelpers::MethodProvider::Hash::__ANON__[:87]
0000s0sMooseX::AttributeHelpers::MethodProvider::Hash::::__ANON__[:93]MooseX::AttributeHelpers::MethodProvider::Hash::__ANON__[:93]
0000s0sMooseX::AttributeHelpers::MethodProvider::Hash::::accessorMooseX::AttributeHelpers::MethodProvider::Hash::accessor
0000s0sMooseX::AttributeHelpers::MethodProvider::Hash::::clearMooseX::AttributeHelpers::MethodProvider::Hash::clear
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package MooseX::AttributeHelpers::MethodProvider::Hash;
23512µs22.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
use Moose::Role;
3
41600nsour $VERSION = '0.23';
5114µs$VERSION = eval $VERSION;
61300nsour $AUTHORITY = 'cpan:STEVAN';
7
812µs16.03mswith '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
sub set : method {
11419µs my ($attr, $reader, $writer) = @_;
12332µs614µs 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;
14 return sub {
15418µs my ( $self, @kvp ) = @_;
16
17 my ( @keys, @values );
18
19 while ( @kvp ) {
20417µs 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
2714µs if ( @values > 1 ) {
28 @{ $reader->($self) }{@keys} = @values;
29 } else {
3012µs325µ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 {
36113µs3128µ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
53sub 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
91sub 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
sub delete : method {
97413µs my ($attr, $reader, $writer) = @_;
98 return sub {
99 my $hashref = $reader->(shift);
100 CORE::delete @{$hashref}{@_};
101 };
102}
103
10416µs1;
105
106__END__
107
108=pod
109
110=head1 NAME
111
112MooseX::AttributeHelpers::MethodProvider::Hash
113
114=head1 DESCRIPTION
115
116This is a role which provides the method generators for
117L<MooseX::AttributeHelpers::Collection::Hash>.
118
119This role is composed from the
120L<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
136Returns the number of elements in the hash.
137
138=item B<delete>
139
140Removes the element with the given key
141
142=item B<defined>
143
144Returns true if the value of a given key is defined
145
146=item B<empty>
147
148If the list is populated, returns true. Otherwise, returns false.
149
150=item B<clear>
151
152Unsets the hash entirely.
153
154=item B<exists>
155
156Returns true if the given key is present in the hash
157
158=item B<get>
159
160Returns an element of the hash by its key.
161
162=item B<keys>
163
164Returns the list of keys in the hash.
165
166=item B<set>
167
168Sets the element in the hash at the given key to the given value.
169
170=item B<values>
171
172Returns the list of values in the hash.
173
174=item B<kv>
175
176Returns the key, value pairs in the hash
177
178=item B<accessor>
179
180If passed one argument, returns the value of the requested key. If passed two
181arguments, sets the value of the requested key.
182
183=back
184
185=head1 BUGS
186
187All complex software has bugs lurking in it, and this module is no
188exception. If you find a bug please either email me, or add the bug
189to cpan-RT.
190
191=head1 AUTHOR
192
193Stevan Little E<lt>stevan@iinteractive.comE<gt>
194
195=head1 COPYRIGHT AND LICENSE
196
197Copyright 2007-2009 by Infinity Interactive, Inc.
198
199L<http://www.iinteractive.com>
200
201This library is free software; you can redistribute it and/or modify
202it under the same terms as Perl itself.
203
204=cut
205