]>
git.ipfire.org Git - ipfire-2.x.git/blob - config/mpfire/perl/Accessor/Faster.pm
1 package Class
::Accessor
::Faster
;
2 use base
'Class::Accessor';
4 $Class::Accessor
::Faster
::VERSION
= '0.31';
8 Class::Accessor::Faster - Even faster, but less expandable, accessors
13 use base qw(Class::Accessor::Faster);
17 This is a faster but less expandable version of Class::Accessor::Fast.
19 Class::Accessor's generated accessors require two method calls to accompish
20 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.
25 Class::Accessor::Faster uses an array reference underneath to be faster.
27 Read the documentation for Class::Accessor for more info.
33 my($class, $field) = @_;
34 my $n = $slot{$class}->{$field};
35 return $n if defined $n;
36 $n = keys %{$slot{$class}};
37 $slot{$class}->{$field} = $n;
42 my($proto, $fields) = @_;
43 my($class) = ref $proto || $proto;
44 my $self = bless [], $class;
46 $fields = {} unless defined $fields;
47 for my $k (keys %$fields) {
48 my $n = $class->_slot($k);
49 $self->[$n] = $fields->{$k};
55 my($class, $field) = @_;
56 my $n = $class->_slot($field);
58 return $_[0]->[$n] if @_ == 1;
59 return $_[0]->[$n] = $_[1] if @_ == 2;
60 return (shift)->[$n] = \
@_;
65 sub make_ro_accessor
{
66 my($class, $field) = @_;
67 my $n = $class->_slot($field);
69 return $_[0]->[$n] if @_ == 1;
71 $_[0]->_croak("'$caller' cannot alter the value of '$field' on objects of class '$class'");
76 sub make_wo_accessor
{
77 my($class, $field) = @_;
78 my $n = $class->_slot($field);
82 $_[0]->_croak("'$caller' cannot access the value of '$field' on objects of class '$class'");
84 return $_[0]->[$n] = $_[1] if @_ == 2;
85 return (shift)->[$n] = \
@_;
93 Copyright 2007 Marty Pauley <marty+perl@kasei.com>
95 This program is free software; you can redistribute it and/or modify it under
96 the same terms as Perl itself. That means either (a) the GNU General Public
97 License or (b) the Artistic License.