Release of version 0.10 of Attribute::Types
NAME
Attribute::Types - Attributes that confer type on variables
VERSION
This document describes version 0.10 of Attribute::Types released May 10, 2001
DESCRIPTION
The Attribute::Types module provides 10 universally accessible attributes that can be used to create variables that accept assignments of only specific types of data.
EXAMPLES
use Attribute::Types;
my $count : INTEGER; # Can only store an integer
my $date : INTEGER(1..31); # Can only store an int between 1..31
my $value : NUMBER; # Can only store a number
my $score : NUMBER(0.1..9.9); # Can only store a num between 0.1..9.9
my @rain : NUMBER; # Elements can only store numbers
my %vars : SCALAR; # Entries can only store scalar refs
my %handler : CODE; # Entries can only store sub refs
my $arr : ARRAY; # Can only store array ref
my @hashes : HASH; # Elements can only store hash refs
my $glob : GLOB; # Can only store a typeglob ref
my $pattern : REGEX; # Can only store a qr'd regex
my $ref2 : REF; # Can only store a meta-reference
my $obj : Type(My::Class); # Can only store objects of (or
# derived from) the specified class
my $x : Type(/good|bad|ugly/); # Can only store strings matching
# the specified regex
sub odd { no warnings; $_[0]%2 }
my $guarded : Type(&odd); # Can only store values for which
# odd($value) returns true
$date = 23; # okay
$date = 32; # KABOOM!
$rain[1] = 121.7; # okay
$rain[1] = "lots"; # KABOOM!
$x = 'very good'; # okay
$x = 'excellent'; # KABOOM!
package My::Class::Der;
use base 'My::Class';
$obj = My::Class->new(); # okay
$obj = My::Class::Der->new(); # okay
$obj = Other::Class->new(); # KABOOM!
$guarded = 1; # okay
$guarded = 2; # KABOOM!
AUTHOR
Damian Conway (damian@conway.org)
COPYRIGHT
Copyright (c) 2001, Damian Conway. All Rights Reserved.
This module is free software. It may be used, redistributed
and/or modified under the terms of the Perl Artistic License
(see http://www.perl.com/perl/misc/Artistic.html)
CHANGES IN VERSION 0.10
(No changes have been documented for this version)
AVAILABILITY
Attribute::Types has been uploaded to the CPAN and is also available from:
http://www.csse.monash.edu.au/~damian/CPAN/Attribute-Types.tar.gz