Class::Meta::AccessorBuilder::Affordance - Affordance style accessor generation
package MyApp::TypeDef; use strict; use Class::Meta::Type; use IO::Socket; my $type = Class::Meta::Type->add( key => 'io_socket', builder => 'affordance', desc => 'IO::Socket object', name => 'IO::Socket Object' );
This module provides the an affordance style accessor builder for Class::Meta. Affordance accessors are attribute accessor methods that separate the getting and setting of an attribute value into distinct methods. The approach both eliminates the overhead of checking to see whether an accessor is called as a getter or a setter, which is common for Perl style accessors, while also creating a psychological barrier to accidentally misusing an attribute.
Class::Meta::AccessorBuilder::Affordance create two different types of accessors: getters and setters. The type of accessors created depends on the value of the authz attribute of the Class::Meta::Attribute for which the accessor is being created.
authz
For example, if the authz is Class::Meta::RDWR, then two accessor methods will be created:
my $value = $obj->get_io_socket; $obj->set_io_socket($value);
If the value of authz is Class::Meta::READ, then only the get method will be created:
my $value = $obj->io_socket;
And finally, if the value of authz is Class::Meta::WRITE, then only the set method will be created (why anyone would want this is beyond me, but I provide for the sake of completeness):
Class::Meta::AccessorBuilder::Affordance uses all of the validation checks passed to it to validate new values before assigning them to an attribute. It also checks to see if the attribute is required, and if so, adds a check to ensure that its value is never undefined. It does not currently check to ensure that private and protected methods are used only in their appropriate contexts, but may do so in a future release.
This file was packaged with the Class-Meta-0.11 distribution.
Please report all bugs via the CPAN Request Tracker at http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-Meta.
David Wheeler <david@kineticode.com>
This class contains most of the documentation you need to get started with Class::Meta.
This module generates Perl style accessors.
This class manages the creation of data types.
This class manages Class::Meta class attributes, most of which will have generated accessors.
Copyright (c) 2002-2004, David Wheeler. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Class::Meta, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Meta
CPAN shell
perl -MCPAN -e shell install Class::Meta
For more information on module installation, please visit the detailed CPAN module installation guide.