Blame lib/Class/Accessor/Chained/Fast.pm
|
Packit |
647083 |
use strict;
|
|
Packit |
647083 |
package Class::Accessor::Chained::Fast;
|
|
Packit |
647083 |
use base 'Class::Accessor::Fast';
|
|
Packit |
647083 |
|
|
Packit |
647083 |
sub make_accessor {
|
|
Packit |
647083 |
my($class, $field) = @_;
|
|
Packit |
647083 |
|
|
Packit |
647083 |
return sub {
|
|
Packit |
647083 |
my $self = shift;
|
|
Packit |
647083 |
if(@_) {
|
|
Packit |
647083 |
$self->{$field} = (@_ == 1 ? $_[0] : [@_]);
|
|
Packit |
647083 |
return $self;
|
|
Packit |
647083 |
}
|
|
Packit |
647083 |
return $self->{$field};
|
|
Packit |
647083 |
};
|
|
Packit |
647083 |
}
|
|
Packit |
647083 |
|
|
Packit |
647083 |
sub make_wo_accessor {
|
|
Packit |
647083 |
my($class, $field) = @_;
|
|
Packit |
647083 |
|
|
Packit |
647083 |
return sub {
|
|
Packit |
647083 |
my($self) = shift;
|
|
Packit |
647083 |
|
|
Packit |
647083 |
unless (@_) {
|
|
Packit |
647083 |
my $caller = caller;
|
|
Packit |
647083 |
require Carp;
|
|
Packit |
647083 |
Carp::croak("'$caller' cannot access the value of '$field' on ".
|
|
Packit |
647083 |
"objects of class '$class'");
|
|
Packit |
647083 |
}
|
|
Packit |
647083 |
else {
|
|
Packit |
647083 |
$self->{$field} = (@_ == 1 ? $_[0] : [@_]);
|
|
Packit |
647083 |
return $self;
|
|
Packit |
647083 |
}
|
|
Packit |
647083 |
};
|
|
Packit |
647083 |
}
|
|
Packit |
647083 |
|
|
Packit |
647083 |
1;
|
|
Packit |
647083 |
|
|
Packit |
647083 |
=head1 NAME
|
|
Packit |
647083 |
|
|
Packit |
647083 |
Class::Accessor::Chained::Fast - Faster, but less expandable, chained accessors
|
|
Packit |
647083 |
|
|
Packit |
647083 |
=head1 SYNOPSIS
|
|
Packit |
647083 |
|
|
Packit |
647083 |
package Foo;
|
|
Packit |
647083 |
use base qw(Class::Accessor::Chained::Fast);
|
|
Packit |
647083 |
|
|
Packit |
647083 |
# The rest as Class::Accessor::Chained except no set() or get().
|
|
Packit |
647083 |
|
|
Packit |
647083 |
=head1 DESCRIPTION
|
|
Packit |
647083 |
|
|
Packit |
647083 |
By analogue to Class::Accessor and Class::Accessor::Fast this module
|
|
Packit |
647083 |
provides a faster less-flexible chained accessor maker.
|
|
Packit |
647083 |
|
|
Packit |
647083 |
=head1 AUTHOR
|
|
Packit |
647083 |
|
|
Packit |
647083 |
Richard Clamp <richardc@unixbeard.net>
|
|
Packit |
647083 |
|
|
Packit |
647083 |
=head1 COPYRIGHT
|
|
Packit |
647083 |
|
|
Packit |
647083 |
Copyright (C) 2003 Richard Clamp. All Rights Reserved.
|
|
Packit |
647083 |
|
|
Packit |
647083 |
This module is free software; you can redistribute it and/or modify it
|
|
Packit |
647083 |
under the same terms as Perl itself.
|
|
Packit |
647083 |
|
|
Packit |
647083 |
=head1 SEE ALSO
|
|
Packit |
647083 |
|
|
Packit |
647083 |
L<Class::Accessor::Fast>, L<Class::Accessor::Chained>
|
|
Packit |
647083 |
|
|
Packit |
647083 |
=cut
|