NAME
Class::Meta::AccessorBuilder - Perl style accessor generation
SYNOPSIS
package MyApp::TypeDef;
use strict;
use Class::Meta::Type;
use IO::Socket;
my $type = Class::Meta::Type->add( key => 'io_socket',
builder => 'default',
desc => 'IO::Socket object',
name => 'IO::Socket Object' );
DESCRIPTION
This module provides the default accessor builder for Class::Meta. It builds standard Perl-style accessors. For example, an attribute named "io_socket" would have a single accessor method, io_socket
.
Accessors
Class::Meta::AccessorBuilder create three different types of accessors: read-only, write-only, and read/write. The type of accessor created depends on the value of the authz
attribute of the Class::Meta::Attribute for which the accessor is being created.
For example, if the authz
is Class::Meta::RDWR, then the method will be able to both read and write the attribute.
my $value = $obj->io_socket;
$obj->io_socket($value);
If the value of authz
is Class::Meta::READ, then the method will not be able to change the value of the attribute:
my $value = $obj->io_socket;
$obj->io_socket($value); # Has no effect.
And finally, if the value of authz
is Class::Meta::WRITE, then the method will not return the value of the attribute (why anyone would want this is beyond me, but I provide for the sake of completeness):
$obj->io_socket($value);
my $value = $obj->io_socket; # Always returns undef.
Data Type Validation
Class::Meta::AccessorBuilder 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.
AUTHOR
David Wheeler <david@kineticode.com>
SEE ALSO
- Class::Meta
-
This class contains most of the documentation you need to get started with Class::Meta.
- Class::Meta::AccessorBuilder::Affordance
-
This module generates affordance style accessors.
- Class::Meta::Type
-
This class manages the creation of data types.
- Class::Meta::Attribute
-
This class manages Class::Meta class attributes, most of which will have generated accessors.
COPYRIGHT AND LICENSE
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.