File | /project/perl/lib/Class/Accessor/Fast.pm |
Statements Executed | 3507 |
Statement Execution Time | 59.2ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3431 | 24 | 5 | 45.0ms | 45.0ms | __ANON__[:41] | Class::Accessor::Fast::
14 | 1 | 1 | 315µs | 315µs | make_accessor | Class::Accessor::Fast::
0 | 0 | 0 | 0s | 0s | BEGIN | Class::Accessor::Fast::
0 | 0 | 0 | 0s | 0s | __ANON__[:53] | Class::Accessor::Fast::
0 | 0 | 0 | 0s | 0s | __ANON__[:70] | Class::Accessor::Fast::
0 | 0 | 0 | 0s | 0s | make_ro_accessor | Class::Accessor::Fast::
0 | 0 | 0 | 0s | 0s | make_wo_accessor | Class::Accessor::Fast::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Class::Accessor::Fast; | ||||
2 | 3 | 92µs | 1 | 0s | use base 'Class::Accessor'; # spent 269µs making 1 call to base::import, recursion: max depth 4, time 269µs |
3 | 3 | 662µs | 1 | 21µs | use strict; # spent 21µs making 1 call to strict::import |
4 | 1 | 6µs | $Class::Accessor::Fast::VERSION = '0.30'; | ||
5 | |||||
6 | =head1 NAME | ||||
7 | |||||
8 | Class::Accessor::Fast - Faster, but less expandable, accessors | ||||
9 | |||||
10 | =head1 SYNOPSIS | ||||
11 | |||||
12 | package Foo; | ||||
13 | use base qw(Class::Accessor::Fast); | ||||
14 | |||||
15 | # The rest is the same as Class::Accessor but without set() and get(). | ||||
16 | |||||
17 | =head1 DESCRIPTION | ||||
18 | |||||
19 | This is a faster but less expandable version of Class::Accessor. | ||||
20 | Class::Accessor's generated accessors require two method calls to accompish | ||||
21 | their task (one for the accessor, another for get() or set()). | ||||
22 | Class::Accessor::Fast eliminates calling set()/get() and does the access itself, | ||||
23 | resulting in a somewhat faster accessor. | ||||
24 | |||||
25 | The downside is that you can't easily alter the behavior of your | ||||
26 | accessors, nor can your subclasses. Of course, should you need this | ||||
27 | later, you can always swap out Class::Accessor::Fast for | ||||
28 | Class::Accessor. | ||||
29 | |||||
30 | Read the documentation for Class::Accessor for more info. | ||||
31 | |||||
32 | =cut | ||||
33 | |||||
34 | # spent 315µs within Class::Accessor::Fast::make_accessor which was called 14 times, avg 23µs/call:
# 14 times (315µs+0s) by Class::Accessor::_mk_accessors at line 166 of Class/Accessor.pm, avg 23µs/call | ||||
35 | 14 | 74µs | my($class, $field) = @_; | ||
36 | |||||
37 | # spent 45.0ms within Class::Accessor::Fast::__ANON__[/project/perl/lib/Class/Accessor/Fast.pm:41] which was called 3431 times, avg 13µs/call:
# 3292 times (42.9ms+0s) by Class::DBI::Column::name_lc at line 64 of Class/DBI/Column.pm, avg 13µs/call
# 15 times (208µs+0s) by Class::DBI::Relationship::_set_up_class_data at line 42 of Class/DBI/Relationship.pm, avg 14µs/call
# 14 times (194µs+0s) by Class::DBI::Relationship::_add_triggers at line 53 of Class/DBI/Relationship.pm, avg 14µs/call
# 12 times (155µs+0s) by Class::DBI::Relationship::HasA::_set_up_class_data at line 94 of Class/DBI/Relationship/HasA.pm, avg 13µs/call
# 10 times (230µs+0s) by Class::DBI::_mk_column_accessors at line 345 of Class/DBI.pm, avg 23µs/call
# 10 times (223µs+0s) by Class::DBI::_mk_column_accessors at line 346 of Class/DBI.pm, avg 22µs/call
# 10 times (157µs+0s) by Class::DBI::mutator_name_for at line 391 of Class/DBI.pm, avg 16µs/call
# 10 times (156µs+0s) by Class::DBI::accessor_name_for at line 382 of Class/DBI.pm, avg 16µs/call
# 10 times (148µs+0s) by Class::DBI::_mk_column_accessors at line 333 of Class/DBI.pm, avg 15µs/call
# 6 times (89µs+0s) by Class::DBI::Relationship::HasMany::_set_up_class_data at line 57 of Class/DBI/Relationship/HasMany.pm, avg 15µs/call
# 6 times (78µs+0s) by Class::DBI::Relationship::HasA::triggers at line 19 of Class/DBI/Relationship/HasA.pm, avg 13µs/call
# 6 times (77µs+0s) by Class::DBI::Relationship::HasA::_deflator at line 82 of Class/DBI/Relationship/HasA.pm, avg 13µs/call
# 6 times (72µs+0s) by Class::DBI::Relationship::HasA::_inflator at line 33 of Class/DBI/Relationship/HasA.pm, avg 12µs/call
# 4 times (48µs+0s) by Class::DBI::Relationship::HasMany::_hm_run_search at line 131 of Class/DBI/Relationship/HasMany.pm, avg 12µs/call
# 3 times (48µs+0s) by Class::DBI::Relationship::HasA::triggers at line 20 of Class/DBI/Relationship/HasA.pm, avg 16µs/call
# 2 times (29µs+0s) by Class::DBI::Relationship::_add_methods at line 62 of Class/DBI/Relationship.pm, avg 14µs/call
# 2 times (29µs+0s) by Class::DBI::Relationship::HasMany::methods at line 80 of Class/DBI/Relationship/HasMany.pm, avg 14µs/call
# 2 times (27µs+0s) by Class::DBI::Relationship::HasMany::triggers at line 71 of Class/DBI/Relationship/HasMany.pm, avg 14µs/call
# 2 times (26µs+0s) by Class::DBI::Relationship::HasMany::triggers at line 64 of Class/DBI/Relationship/HasMany.pm, avg 13µs/call
# 2 times (26µs+0s) by Class::DBI::Relationship::HasMany::_has_many_method at line 119 of Class/DBI/Relationship/HasMany.pm, avg 13µs/call
# 2 times (25µs+0s) by Class::DBI::Relationship::HasA::__ANON__[/project/perl/lib/Class/DBI/Relationship/HasA.pm:77] at line 38 of Class/DBI/Relationship/HasA.pm, avg 12µs/call
# 2 times (24µs+0s) by Class::DBI::Relationship::HasMany::triggers at line 68 of Class/DBI/Relationship/HasMany.pm, avg 12µs/call
# 2 times (24µs+0s) by Class::DBI::Relationship::HasMany::_method_add_to at line 89 of Class/DBI/Relationship/HasMany.pm, avg 12µs/call
# once (15µs+0s) by Class::DBI::Relationship::HasA::__ANON__[/project/perl/lib/Class/DBI/Relationship/HasA.pm:77] at line 37 of Class/DBI/Relationship/HasA.pm | ||||
38 | 3431 | 57.7ms | return $_[0]->{$field} unless @_ > 1; | ||
39 | 20 | 94µs | my $self = shift; | ||
40 | 20 | 303µs | $self->{$field} = (@_ == 1 ? $_[0] : [@_]); | ||
41 | 14 | 287µs | }; | ||
42 | } | ||||
43 | |||||
44 | |||||
45 | sub make_ro_accessor { | ||||
46 | my($class, $field) = @_; | ||||
47 | |||||
48 | return sub { | ||||
49 | return $_[0]->{$field} unless @_ > 1; | ||||
50 | my $self = shift; | ||||
51 | my $caller = caller; | ||||
52 | $self->_croak("'$caller' cannot alter the value of '$field' on objects of class '$class'"); | ||||
53 | }; | ||||
54 | } | ||||
55 | |||||
56 | |||||
57 | sub make_wo_accessor { | ||||
58 | my($class, $field) = @_; | ||||
59 | |||||
60 | return sub { | ||||
61 | my $self = shift; | ||||
62 | |||||
63 | unless (@_) { | ||||
64 | my $caller = caller; | ||||
65 | $self->_croak("'$caller' cannot access the value of '$field' on objects of class '$class'"); | ||||
66 | } | ||||
67 | else { | ||||
68 | return $self->{$field} = (@_ == 1 ? $_[0] : [@_]); | ||||
69 | } | ||||
70 | }; | ||||
71 | } | ||||
72 | |||||
73 | |||||
74 | =head1 EFFICIENCY | ||||
75 | |||||
76 | L<Class::Accessor/EFFICIENCY> for an efficiency comparison. | ||||
77 | |||||
78 | =head1 AUTHORS | ||||
79 | |||||
80 | Copyright 2005 Marty Pauley <marty+perl@kasei.com> | ||||
81 | |||||
82 | This program is free software; you can redistribute it and/or modify it under | ||||
83 | the same terms as Perl itself. That means either (a) the GNU General Public | ||||
84 | License or (b) the Artistic License. | ||||
85 | |||||
86 | =head2 ORIGINAL AUTHOR | ||||
87 | |||||
88 | Michael G Schwern <schwern@pobox.com> | ||||
89 | |||||
90 | =head1 SEE ALSO | ||||
91 | |||||
92 | L<Class::Accessor> | ||||
93 | |||||
94 | =cut | ||||
95 | |||||
96 | 1 | 12µs | 1; |