Profile of /usr/local/lib/perl5/site_perl/5.10.1/MooseX/AttributeHelpers/Trait/Counter.pm

← 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:23:24 2010

File | /usr/local/lib/perl5/site_perl/5.10.1/MooseX/AttributeHelpers/Trait/Counter.pm
Statements Executed | 17
Statement Execution Time | 457µs

Subroutines — ordered by exclusive time
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 404µs | 1.86ms | MooseX::AttributeHelpers::Trait::Counter::::BEGIN@9MooseX::AttributeHelpers::Trait::Counter::BEGIN@9
1 | 1 | 1 | 15µs | 1.95ms | MooseX::AttributeHelpers::Trait::Counter::::BEGIN@3MooseX::AttributeHelpers::Trait::Counter::BEGIN@3
1 | 1 | 1 | 9µs | 127µs | MooseX::AttributeHelpers::Trait::Counter::::BEGIN@48MooseX::AttributeHelpers::Trait::Counter::BEGIN@48
0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Counter::::__ANON__[:32]MooseX::AttributeHelpers::Trait::Counter::__ANON__[:32]
0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Counter::::__ANON__[:46]MooseX::AttributeHelpers::Trait::Counter::__ANON__[:46]
0 | 0 | 0 | 0s | 0s | MooseX::AttributeHelpers::Trait::Counter::::helper_typeMooseX::AttributeHelpers::Trait::Counter::helper_type

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  |
2 |  |  |  |  | package MooseX::AttributeHelpers::Trait::Counter;
3 | 3 | 61µs | 2 | 3.89ms | # spent 1.95ms (15µs+1.94) within MooseX::AttributeHelpers::Trait::Counter::BEGIN@3 which was called # once (15µs+1.94ms) by MooseX::AttributeHelpers::BEGIN@14 at line 3 use Moose::Role; # spent 1.95ms making 1 call to MooseX::AttributeHelpers::Trait::Counter::BEGIN@3 # spent 1.94ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:389]
4 |  |  |  |  |
5 | 1 | 700ns |  |  | our $VERSION = '0.23';
6 | 1 | 15µs |  |  | $VERSION = eval $VERSION;
7 | 1 | 400ns |  |  | our $AUTHORITY = 'cpan:STEVAN';
8 |  |  |  |  |
9 | 3 | 290µs | 1 | 1.86ms | # spent 1.86ms (404µs+1.46) within MooseX::AttributeHelpers::Trait::Counter::BEGIN@9 which was called # once (404µs+1.46ms) by MooseX::AttributeHelpers::BEGIN@14 at line 9 use MooseX::AttributeHelpers::MethodProvider::Counter; # spent 1.86ms making 1 call to MooseX::AttributeHelpers::Trait::Counter::BEGIN@9
10 |  |  |  |  |
11 | 1 | 3µs | 1 | 2.46ms | with 'MooseX::AttributeHelpers::Trait::Base'; # spent 2.46ms making 1 call to Moose::Role::with
12 |  |  |  |  |
13 | 1 | 4µs | 1 | 121µs | has 'method_provider' => ( # spent 121µs making 1 call to Moose::Role::has
14 |  |  |  |  | is => 'ro',
15 |  |  |  |  | isa => 'ClassName',
16 |  |  |  |  | predicate => 'has_method_provider',
17 |  |  |  |  | default => 'MooseX::AttributeHelpers::MethodProvider::Counter',
18 |  |  |  |  | );
19 |  |  |  |  |
20 |  |  |  |  | sub helper_type { 'Num' }
21 |  |  |  |  |
22 |  |  |  |  | before 'process_options_for_provides' => sub {
23 |  |  |  |  | my ($self, $options, $name) = @_;
24 |  |  |  |  |
25 |  |  |  |  | # Set some default attribute options here unless already defined
26 |  |  |  |  | if ((my $type = $self->helper_type) && !exists $options->{isa}){
27 |  |  |  |  | $options->{isa} = $type;
28 |  |  |  |  | }
29 |  |  |  |  |
30 |  |  |  |  | $options->{is} = 'ro' unless exists $options->{is};
31 |  |  |  |  | $options->{default} = 0 unless exists $options->{default};
32 | 1 | 6µs | 1 | 42µs | }; # spent 42µs making 1 call to Moose::Role::before
33 |  |  |  |  |
34 |  |  |  |  | after 'check_provides_values' => sub {
35 |  |  |  |  | my $self = shift;
36 |  |  |  |  | my $provides = $self->provides;
37 |  |  |  |  |
38 |  |  |  |  | unless (scalar keys %$provides) {
39 |  |  |  |  | my $method_constructors = $self->method_constructors;
40 |  |  |  |  | my $attr_name = $self->name;
41 |  |  |  |  |
42 |  |  |  |  | foreach my $method (keys %$method_constructors) {
43 |  |  |  |  | $provides->{$method} = ($method . '_' . $attr_name);
44 |  |  |  |  | }
45 |  |  |  |  | }
46 | 1 | 5µs | 1 | 36µs | }; # spent 36µs making 1 call to Moose::Role::after
47 |  |  |  |  |
48 | 3 | 38µs | 2 | 246µs | # spent 127µs (9+118) within MooseX::AttributeHelpers::Trait::Counter::BEGIN@48 which was called # once (9µs+118µs) by MooseX::AttributeHelpers::BEGIN@14 at line 48 no Moose::Role; # spent 127µs making 1 call to MooseX::AttributeHelpers::Trait::Counter::BEGIN@48 # spent 118µs making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:478]
49 |  |  |  |  |
50 | 1 | 34µs |  |  | 1;
51 |  |  |  |  |
52 |  |  |  |  | __END__
53 |  |  |  |  |
54 |  |  |  |  | =pod
55 |  |  |  |  |
56 |  |  |  |  | =head1 NAME
57 |  |  |  |  |
58 |  |  |  |  | MooseX::AttributeHelpers::Counter
59 |  |  |  |  |
60 |  |  |  |  | =head1 SYNOPSIS
61 |  |  |  |  |
62 |  |  |  |  | package MyHomePage;
63 |  |  |  |  | use Moose;
64 |  |  |  |  | use MooseX::AttributeHelpers;
65 |  |  |  |  |
66 |  |  |  |  | has 'counter' => (
67 |  |  |  |  | metaclass => 'Counter',
68 |  |  |  |  | is => 'ro',
69 |  |  |  |  | isa => 'Num',
70 |  |  |  |  | default => sub { 0 },
71 |  |  |  |  | provides => {
72 |  |  |  |  | inc => 'inc_counter',
73 |  |  |  |  | dec => 'dec_counter',
74 |  |  |  |  | reset => 'reset_counter',
75 |  |  |  |  | }
76 |  |  |  |  | );
77 |  |  |  |  |
78 |  |  |  |  | my $page = MyHomePage->new();
79 |  |  |  |  | $page->inc_counter; # same as $page->counter($page->counter + 1);
80 |  |  |  |  | $page->dec_counter; # same as $page->counter($page->counter - 1);
81 |  |  |  |  |
82 |  |  |  |  | =head1 DESCRIPTION
83 |  |  |  |  |
84 |  |  |  |  | This module provides a simple counter attribute, which can be
85 |  |  |  |  | incremented and decremeneted.
86 |  |  |  |  |
87 |  |  |  |  | If your attribute definition does not include any of I<is>, I<isa>,
88 |  |  |  |  | I<default> or I<provides> but does use the C<Counter> metaclass,
89 |  |  |  |  | then this module applies defaults as in the L</SYNOPSIS>
90 |  |  |  |  | above. This allows for a very basic counter definition:
91 |  |  |  |  |
92 |  |  |  |  | has 'foo' => (metaclass => 'Counter');
93 |  |  |  |  | $obj->inc_foo;
94 |  |  |  |  |
95 |  |  |  |  | =head1 METHODS
96 |  |  |  |  |
97 |  |  |  |  | =over 4
98 |  |  |  |  |
99 |  |  |  |  | =item B<meta>
100 |  |  |  |  |
101 |  |  |  |  | =item B<method_provider>
102 |  |  |  |  |
103 |  |  |  |  | =item B<has_method_provider>
104 |  |  |  |  |
105 |  |  |  |  | =item B<helper_type>
106 |  |  |  |  |
107 |  |  |  |  | =item B<process_options_for_provides>
108 |  |  |  |  |
109 |  |  |  |  | Run before its superclass method.
110 |  |  |  |  |
111 |  |  |  |  | =item B<check_provides_values>
112 |  |  |  |  |
113 |  |  |  |  | Run after its superclass method.
114 |  |  |  |  |
115 |  |  |  |  | =back
116 |  |  |  |  |
117 |  |  |  |  | =head1 PROVIDED METHODS
118 |  |  |  |  |
119 |  |  |  |  | It is important to note that all those methods do in place
120 |  |  |  |  | modification of the value stored in the attribute.
121 |  |  |  |  |
122 |  |  |  |  | =over 4
123 |  |  |  |  |
124 |  |  |  |  | =item I<set>
125 |  |  |  |  |
126 |  |  |  |  | Set the counter to the specified value.
127 |  |  |  |  |
128 |  |  |  |  | =item I<inc>
129 |  |  |  |  |
130 |  |  |  |  | Increments the value stored in this slot by 1. Providing an argument will
131 |  |  |  |  | cause the counter to be increased by specified amount.
132 |  |  |  |  |
133 |  |  |  |  | =item I<dec>
134 |  |  |  |  |
135 |  |  |  |  | Decrements the value stored in this slot by 1. Providing an argument will
136 |  |  |  |  | cause the counter to be increased by specified amount.
137 |  |  |  |  |
138 |  |  |  |  | =item I<reset>
139 |  |  |  |  |
140 |  |  |  |  | Resets the value stored in this slot to it's default value.
141 |  |  |  |  |
142 |  |  |  |  | =back
143 |  |  |  |  |
144 |  |  |  |  | =head1 BUGS
145 |  |  |  |  |
146 |  |  |  |  | All complex software has bugs lurking in it, and this module is no
147 |  |  |  |  | exception. If you find a bug please either email me, or add the bug
148 |  |  |  |  | to cpan-RT.
149 |  |  |  |  |
150 |  |  |  |  | =head1 AUTHOR
151 |  |  |  |  |
152 |  |  |  |  | Stevan Little E<lt>stevan@iinteractive.comE<gt>
153 |  |  |  |  |
154 |  |  |  |  | =head1 COPYRIGHT AND LICENSE
155 |  |  |  |  |
156 |  |  |  |  | Copyright 2007-2009 by Infinity Interactive, Inc.
157 |  |  |  |  |
158 |  |  |  |  | L<http://www.iinteractive.com>
159 |  |  |  |  |
160 |  |  |  |  | This library is free software; you can redistribute it and/or modify
161 |  |  |  |  | it under the same terms as Perl itself.
162 |  |  |  |  |
163 |  |  |  |  | =cut