Attribute::Types

Attributes that confer type on variables
Download

Attribute::Types Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Publisher Name:
  • Damian Conway
  • Publisher web site:
  • http://search.cpan.org/~dconway/

Attribute::Types Tags


Attribute::Types Description

Attributes that confer type on variables The Attribute::Types is a Perl module that provides 10 universally accessible attributes that can be used to create variables that accept assignments of only specific types of data.SYNOPSIS 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; $_%2 } my $guarded : Type(&odd); # Can only store values for which # odd($value) returns true $date = 23; # okay $date = 32; # KABOOM! $rain = 121.7; # okay $rain = "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! Requirements: · Perl


Attribute::Types Related Software