2 package Class::Accessor::Chained;
3 use base 'Class::Accessor';
7 my($class, $field) = @_;
9 # Build a closure around $field.
14 $self->set($field, @_);
18 return $self->get($field);
23 sub make_wo_accessor {
24 my($class, $field) = @_;
32 Carp::croak("'$caller' cannot access the value of '$field' on ".
33 "objects of class '$class'");
36 $self->set($field, @_);
47 Class::Accessor::Chained - make chained accessors
52 use base qw( Class::Accessor::Chained );
53 __PACKAGE__->mk_accessors(qw( foo bar baz ));
55 my $foo = Foo->new->foo(1)->bar(2)->baz(4);
56 print $foo->bar; # prints 2
60 A chained accessor is one that always returns the object when called
61 with parameters (to set), and the value of the field when called with
64 This module subclasses Class::Accessor in order to provide the same
65 mk_accessors interface.
69 Richard Clamp <richardc@unixbeard.net>
73 Copyright (C) 2003 Richard Clamp. All Rights Reserved.
75 This module is free software; you can redistribute it and/or modify it
76 under the same terms as Perl itself.
80 L<Class::Accessor>, L<Class::Accessor::Chained::Fast>