NAME
accessors::rw::explicit - RW object attribute accessors, with explicit semantics
VERSION
Version 0.01
SYNOPSIS
package Foo;
use accessors::rw::explicit qw(foo bar baz);
my $obj = bless {}, 'Foo';
# always return the current value, even on set:
$obj->set_foo( 'hello ' ) if $obj->bar( 'world' ) eq 'world';
print $obj->foo, $obj->bar, $obj->set_baz( "!\n" );
...
DESCRIPTION
ceci n'est pas un Moose
The purpose of this module is to provide very basic object instance attribute accessors for basic perl5 blessed hash-reference objects.
That is a mouthful. Essentially is is just an exercise in codifying convention, and sensible code reuse. It is not an attempt at a complete object system, with flexible attribute definitions. If you want that, you want Moose, end of.
This module will set up attribute accessors for you though, and allow you to specify a prefix on your getters and setters. It denotes itself as explicit, as it defaults to different names for the getters and setters, namely prepending "set_" to setters.
so for foo you would get:
$obj->set_foo( $foo );
and
my $foo = $obj->foo;
These prefixes can be changed by providing options on import.
eg:
use accessors::rw::explicit ({get_prefix => 'you_tell_me_', set_prefix => 'I_tell_you_'}, 'foo');
would provide:
$obj->I_tell_you_foo( $foo )
and
my $foo = $obj->you_tell_me_foo();
METHODS
GetPrefix
returns the prefix prepended to getters. Defaults to the empty string.
SetPrefix
returns the prefix prepended to setters. Defaults to "set_".
import
As with other accessors modules, this takes a list of the attributes you want setting up:
use accessors::rw::explicit qw(foo bar baz);
It can also change the default get and set prefixes by providing an optional options hash:
use accessors::rw::explicit ({get_prefix => 'get_'}, qw/foo bar baz/);
The above would produce accessors that conform to the Perl Best Practice book's recommendations.
create_accessors_for
Creates a get accessor of the form GetPrefix + AttributeName and a set accessor of the form SetPrefix + AttributeName
See import for how to define the prefixes and the attribute names.
This overrides a method in the accessors.pm package, and should never need to be called directly.
create_explicit_accessors
The routine that actually creates the accessors. The body of a getter looks like:
my $getter = sub {
return $_[0]->{$property};
}
and a setter is defined as:
my $setter = sub {
$_[0]->{$property} = $_[1];
return $_[0]->{$property};
}
Where $property is defined to be
"-" . $attribute_name</code>.
AUTHOR
Alex Kalderimis, <alex dot kalderimis at gmail dot com>
BUGS
Please report any bugs or feature requests to bug-accessors-rw-explicit at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=accessors-rw-explicit. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc accessors::rw::explicit
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=accessors-rw-explicit
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
Steve Purkis for writing accessors.pm http://search.cpan.org/dist/accessors/
LICENSE AND COPYRIGHT
Copyright 2011 Alex Kalderimis.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.