1 package Class::Accessor::Faster;
2 use base 'Class::Accessor';
4 $Class::Accessor::Faster::VERSION = '0.34';
8 my($class, $field) = @_;
9 my $n = $slot{$class}->{$field};
10 return $n if defined $n;
11 $n = keys %{$slot{$class}};
12 $slot{$class}->{$field} = $n;
17 my($proto, $fields) = @_;
18 my($class) = ref $proto || $proto;
19 my $self = bless [], $class;
21 $fields = {} unless defined $fields;
22 for my $k (keys %$fields) {
23 my $n = $class->_slot($k);
24 $self->[$n] = $fields->{$k};
30 my($class, $field) = @_;
31 my $n = $class->_slot($field);
33 return $_[0]->[$n] if scalar(@_) == 1;
34 return $_[0]->[$n] = scalar(@_) == 2 ? $_[1] : [@_[1..$#_]];
38 sub make_ro_accessor {
39 my($class, $field) = @_;
40 my $n = $class->_slot($field);
42 return $_[0]->[$n] if @_ == 1;
44 $_[0]->_croak("'$caller' cannot alter the value of '$field' on objects of class '$class'");
48 sub make_wo_accessor {
49 my($class, $field) = @_;
50 my $n = $class->_slot($field);
54 $_[0]->_croak("'$caller' cannot access the value of '$field' on objects of class '$class'");
56 return $_[0]->[$n] = $_[1] if @_ == 2;
57 return (shift)->[$n] = \@_;
68 Class::Accessor::Faster - Even faster, but less expandable, accessors
73 use base qw(Class::Accessor::Faster);
77 This is a faster but less expandable version of Class::Accessor::Fast.
79 Class::Accessor's generated accessors require two method calls to accompish
80 their task (one for the accessor, another for get() or set()).
82 Class::Accessor::Fast eliminates calling set()/get() and does the access itself,
83 resulting in a somewhat faster accessor.
85 Class::Accessor::Faster uses an array reference underneath to be faster.
87 Read the documentation for Class::Accessor for more info.
91 Copyright 2007 Marty Pauley <marty+perl@kasei.com>
93 This program is free software; you can redistribute it and/or modify it under
94 the same terms as Perl itself. That means either (a) the GNU General Public
95 License or (b) the Artistic License.