← Index
NYTProf Performance Profile   « block view • line view • sub view »
For xt/tapper-mcp-scheduler-with-db-longrun.t
  Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:23:36 2012

Filename/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/Attribute/Native.pm
StatementsExecuted 37 statements in 322µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11110µs10µsMoose::Meta::Attribute::Native::::BEGIN@2Moose::Meta::Attribute::Native::BEGIN@2
11110µs45µsMoose::Meta::Attribute::Native::::BEGIN@9Moose::Meta::Attribute::Native::BEGIN@9
0000s0sMoose::Meta::Attribute::Native::::__ANON__[:30]Moose::Meta::Attribute::Native::__ANON__[:30]
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Moose::Meta::Attribute::Native;
2
# spent 10µs within Moose::Meta::Attribute::Native::BEGIN@2 which was called: # once (10µs+0s) by Moose::BEGIN@47 at line 4
BEGIN {
314µs $Moose::Meta::Attribute::Native::AUTHORITY = 'cpan:STEVAN';
4126µs110µs}
# spent 10µs making 1 call to Moose::Meta::Attribute::Native::BEGIN@2
5{
621µs $Moose::Meta::Attribute::Native::VERSION = '2.0602';
7}
8
93230µs280µs
# spent 45µs (10+35) within Moose::Meta::Attribute::Native::BEGIN@9 which was called: # once (10µs+35µs) by Moose::BEGIN@47 at line 9
use Class::Load qw(load_class);
# spent 45µs making 1 call to Moose::Meta::Attribute::Native::BEGIN@9 # spent 35µs making 1 call to Exporter::import
10
1112µsmy @trait_names = qw(Bool Counter Number String Array Hash Code);
12
131700nsfor my $trait_name (@trait_names) {
1474µs my $trait_class = "Moose::Meta::Attribute::Native::Trait::$trait_name";
15713µs7530µs my $meta = Class::MOP::Class->initialize(
# spent 530µs making 7 calls to Class::MOP::Class::initialize, avg 76µs/call
16 "Moose::Meta::Attribute::Custom::Trait::$trait_name"
17 );
1879µs7504µs if ($meta->find_method_by_name('register_implementation')) {
# spent 504µs making 7 calls to Class::MOP::Class::find_method_by_name, avg 72µs/call
19 my $class = $meta->name->register_implementation;
20 Moose->throw_error(
21 "An implementation for $trait_name already exists " .
22 "(found '$class' when trying to register '$trait_class')"
23 );
24 }
25 $meta->add_method(register_implementation => sub {
26 # resolve_metatrait_alias will load classes anyway, but throws away
27 # their error message; we WANT to die if there's a problem
28 load_class($trait_class);
29 return $trait_class;
30721µs7335µs });
# spent 335µs making 7 calls to Class::MOP::Mixin::HasMethods::add_method, avg 48µs/call
31}
32
33111µs1;
34
35# ABSTRACT: Delegate to native Perl types
36
- -
39=pod
40
41=head1 NAME
42
43Moose::Meta::Attribute::Native - Delegate to native Perl types
44
45=head1 VERSION
46
47version 2.0602
48
49=head1 SYNOPSIS
50
51 package MyClass;
52 use Moose;
53
54 has 'mapping' => (
55 traits => ['Hash'],
56 is => 'rw',
57 isa => 'HashRef[Str]',
58 default => sub { {} },
59 handles => {
60 exists_in_mapping => 'exists',
61 ids_in_mapping => 'keys',
62 get_mapping => 'get',
63 set_mapping => 'set',
64 set_quantity => [ set => 'quantity' ],
65 },
66 );
67
68 my $obj = MyClass->new;
69 $obj->set_quantity(10); # quantity => 10
70 $obj->set_mapping('foo', 4); # foo => 4
71 $obj->set_mapping('bar', 5); # bar => 5
72 $obj->set_mapping('baz', 6); # baz => 6
73
74 # prints 5
75 print $obj->get_mapping('bar') if $obj->exists_in_mapping('bar');
76
77 # prints 'quantity, foo, bar, baz'
78 print join ', ', $obj->ids_in_mapping;
79
80=head1 DESCRIPTION
81
82Native delegations allow you to delegate to native Perl data
83structures as if they were objects. For example, in the L</SYNOPSIS> you can
84see a hash reference being treated as if it has methods named C<exists()>,
85C<keys()>, C<get()>, and C<set()>.
86
87The delegation methods (mostly) map to Perl builtins and operators. The return
88values of these delegations should be the same as the corresponding Perl
89operation. Any deviations will be explicitly documented.
90
91=head1 API
92
93Native delegations are enabled by passing certain options to C<has> when
94creating an attribute.
95
96=head2 traits
97
98To enable this feature, pass the appropriate name in the C<traits> array
99reference for the attribute. For example, to enable this feature for hash
100reference, we include C<'Hash'> in the list of traits.
101
102=head2 isa
103
104You will need to make sure that the attribute has an appropriate type. For
105example, to use this with a Hash you must specify that your attribute is some
106sort of C<HashRef>.
107
108=head2 handles
109
110This is just like any other delegation, but only a hash reference is allowed
111when defining native delegations. The keys are the methods to be created in
112the class which contains the attribute. The values are the methods provided by
113the associated trait. Currying works the same way as it does with any other
114delegation.
115
116See the docs for each native trait for details on what methods are available.
117
118=head2 is
119
120Some traits provide a default C<is> for historical reasons. This behavior is
121deprecated, and you are strongly encouraged to provide a value. If you don't
122plan to read and write the attribute value directly, not passing the C<is>
123option will prevent standard accessor generation.
124
125=head2 default or builder
126
127Some traits provide a default C<default> for historical reasons. This behavior
128is deprecated, and you are strongly encouraged to provide a default value or
129make the attribute required.
130
131=head1 TRAITS FOR NATIVE DELEGATIONS
132
133=over
134
135=item L<Array|Moose::Meta::Attribute::Native::Trait::Array>
136
137 has 'queue' => (
138 traits => ['Array'],
139 is => 'ro',
140 isa => 'ArrayRef[Str]',
141 default => sub { [] },
142 handles => {
143 add_item => 'push',
144 next_item => 'shift',
145 # ...
146 }
147 );
148
149=item L<Bool|Moose::Meta::Attribute::Native::Trait::Bool>
150
151 has 'is_lit' => (
152 traits => ['Bool'],
153 is => 'ro',
154 isa => 'Bool',
155 default => 0,
156 handles => {
157 illuminate => 'set',
158 darken => 'unset',
159 flip_switch => 'toggle',
160 is_dark => 'not',
161 # ...
162 }
163 );
164
165=item L<Code|Moose::Meta::Attribute::Native::Trait::Code>
166
167 has 'callback' => (
168 traits => ['Code'],
169 is => 'ro',
170 isa => 'CodeRef',
171 default => sub {
172 sub {'called'}
173 },
174 handles => {
175 call => 'execute',
176 # ...
177 }
178 );
179
180=item L<Counter|Moose::Meta::Attribute::Native::Trait::Counter>
181
182 has 'counter' => (
183 traits => ['Counter'],
184 is => 'ro',
185 isa => 'Num',
186 default => 0,
187 handles => {
188 inc_counter => 'inc',
189 dec_counter => 'dec',
190 reset_counter => 'reset',
191 # ...
192 }
193 );
194
195=item L<Hash|Moose::Meta::Attribute::Native::Trait::Hash>
196
197 has 'options' => (
198 traits => ['Hash'],
199 is => 'ro',
200 isa => 'HashRef[Str]',
201 default => sub { {} },
202 handles => {
203 set_option => 'set',
204 get_option => 'get',
205 has_option => 'exists',
206 # ...
207 }
208 );
209
210=item L<Number|Moose::Meta::Attribute::Native::Trait::Number>
211
212 has 'integer' => (
213 traits => ['Number'],
214 is => 'ro',
215 isa => 'Int',
216 default => 5,
217 handles => {
218 set => 'set',
219 add => 'add',
220 sub => 'sub',
221 mul => 'mul',
222 div => 'div',
223 mod => 'mod',
224 abs => 'abs',
225 # ...
226 }
227 );
228
229=item L<String|Moose::Meta::Attribute::Native::Trait::String>
230
231 has 'text' => (
232 traits => ['String'],
233 is => 'ro',
234 isa => 'Str',
235 default => q{},
236 handles => {
237 add_text => 'append',
238 replace_text => 'replace',
239 # ...
240 }
241 );
242
243=back
244
245=head1 COMPATIBILITY WITH MooseX::AttributeHelpers
246
247This feature used to be a separated CPAN distribution called
248L<MooseX::AttributeHelpers>.
249
250When the feature was incorporated into the Moose core, some of the API details
251were changed. The underlying capabilities are the same, but some details of
252the API were changed.
253
254=head1 BUGS
255
256See L<Moose/BUGS> for details on reporting bugs.
257
258=head1 AUTHOR
259
260Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details.
261
262=head1 COPYRIGHT AND LICENSE
263
264This software is copyright (c) 2012 by Infinity Interactive, Inc..
265
266This is free software; you can redistribute it and/or modify it under
267the same terms as the Perl 5 programming language system itself.
268
269=cut
270
271
272__END__