]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - config/mpfire/perl/Accessor/Fast.pm
kernel: disable FW_LOADER_USER_HELPER_FALLBACK
[people/pmueller/ipfire-2.x.git] / config / mpfire / perl / Accessor / Fast.pm
CommitLineData
83d20a45
CS
1package Class::Accessor::Fast;
2use base 'Class::Accessor';
3use strict;
4$Class::Accessor::Fast::VERSION = '0.31';
5
6=head1 NAME
7
8Class::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
19This is a faster but less expandable version of Class::Accessor.
20Class::Accessor's generated accessors require two method calls to accompish
21their task (one for the accessor, another for get() or set()).
22Class::Accessor::Fast eliminates calling set()/get() and does the access itself,
23resulting in a somewhat faster accessor.
24
25The downside is that you can't easily alter the behavior of your
26accessors, nor can your subclasses. Of course, should you need this
27later, you can always swap out Class::Accessor::Fast for
28Class::Accessor.
29
30Read the documentation for Class::Accessor for more info.
31
32=cut
33
34sub make_accessor {
35 my($class, $field) = @_;
36
37 return sub {
38 return $_[0]->{$field} if @_ == 1;
39 return $_[0]->{$field} = $_[1] if @_ == 2;
40 return (shift)->{$field} = \@_;
41 };
42}
43
44
45sub make_ro_accessor {
46 my($class, $field) = @_;
47
48 return sub {
49 return $_[0]->{$field} if @_ == 1;
50 my $caller = caller;
51 $_[0]->_croak("'$caller' cannot alter the value of '$field' on objects of class '$class'");
52 };
53}
54
55
56sub make_wo_accessor {
57 my($class, $field) = @_;
58
59 return sub {
60 if (@_ == 1) {
61 my $caller = caller;
62 $_[0]->_croak("'$caller' cannot access the value of '$field' on objects of class '$class'");
63 }
64 else {
65 return $_[0]->{$field} = $_[1] if @_ == 2;
66 return (shift)->{$field} = \@_;
67 }
68 };
69}
70
71
72=head1 EFFICIENCY
73
74L<Class::Accessor/EFFICIENCY> for an efficiency comparison.
75
76=head1 AUTHORS
77
78Copyright 2007 Marty Pauley <marty+perl@kasei.com>
79
80This program is free software; you can redistribute it and/or modify it under
81the same terms as Perl itself. That means either (a) the GNU General Public
82License or (b) the Artistic License.
83
84=head2 ORIGINAL AUTHOR
85
86Michael G Schwern <schwern@pobox.com>
87
88=head1 SEE ALSO
89
90L<Class::Accessor>
91
92=cut
93
941;