-
-
12 Feb 2019 21:56:29 UTC
- Distribution: Class-Field
- Module version: 0.24
- Source (raw)
- Pod Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (2)
- Testers (760 / 0 / 0)
- Kwalitee
Bus factor: 1- 82.29% Coverage
- License: perl_5
- Perl: v5.8.1
- Activity
24 month- Tools
- Download (12.67KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
++ed by:1 non-PAUSE user- Dependencies
- none
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Class::Field - Class Field Accessor Generator
VERSION
This document describes Class::Field version 0.24.
SYNOPSIS
package Thing; use Class::Field qw'field const'; field 'this'; field 'list' => []; field 'map' => {}; field 'that', -init => '$self->setup_that'; field 'circular_ref' => -weaken; const 'answer' => 42;
DESCRIPTION
Class::Field exports two subroutines,
field
andconst
. These functions are used to declare fields and constants in your class.Class::Field generates custom code for each accessor that is optimized for speed.
FUNCTIONS
field
-
Defines accessor methods for a field of your class:
package Example; use base 'Parent'; use Class::Field qw'field const'; field 'foo'; field bar => []; sub lalala { my $self = shift; $self->foo(42); push @{$self->{bar}}, $self->foo; }
The first parameter passed to
field
is the name of the attribute being defined. Accessors can be given an optional default value. This value will be returned if no value for the field has been set in the object. const
-
const bar => 42;
The
const
function is similar to <field> except that it is immutable. It also does not store data in the object. You probably always want to give aconst
a default value, otherwise the generated method will be somewhat useless.
NOTE
This code was taken directly out the Spiffy module for those people who just want this functionality without using the rest of Spiffy.
AUTHOR
Ingy döt Net <ingy@cpan.org>
COPYRIGHT AND LICENSE
Copyright 2006-2019. Ingy döt Net.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install Class::Field, copy and paste the appropriate command in to your terminal.
cpanm Class::Field
perl -MCPAN -e shell install Class::Field
For more information on module installation, please visit the detailed CPAN module installation guide.