Click here to get back home

Variable::Strongly::Typed 1.0.0 released

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Variable::Strongly::Typed 1.0.0 released zzo 09-02-2005
Posted by zzo on September 2, 2005, 4:28 pm
Please log in for more thread options


DESCRIPTION

This modules allow you to strongly type your variables. Also known
as the 'no fun' module - it can greatly enhance you code's quality
and robustness.

By enforcing types on some (or all) of your variables you will
eliminate
a large class of careless (& not so careless) errors.

This could also aid an editor or code-browsing tools to verify code
correctness without having to execute the script.

SYNOPSIS

use Variable::Strongly::Typed;

my $int :TYPE('int'); # must have an 'int' value
my $float :TYPE('float'); # must have a 'float' value
my $string :TYPE('string'); # must not be a reference
my $file :TYPE('IO::File'); # must be an IO::File
my @array_of_ints :TYPE('int'); # Each slot must contain an
int
my %hash_of_floats :TYPE('float'); # Each value must be a
float

my @array_of_rgb :TYPE(\&red_green_blue); # my enumerated type

# ... and later ...

$int = 23; # All is well
$int = 'howdy!'; # This line will croak with a good error
message

$float = 3.23; # All is well, nothing to see here
$float = new XML::Parser; # croak!

$array_of_ints[23] = 44; # Groovy
$array_of_ints[12] = 'yah '; # croak!

$hash_of_floats = 3.14159; # no problem
$hash_of_floats = new IO::File; # croak!

# Return 1 if this val is RED, BLUE, or GREEN
# 0 otherwise
sub red_green_blue {
local $_ = shift;

/\A RED \z/xms || /\A BLUE \z/xms || /\A GREEN \z/xms;
}

$array_of_my_very_own_types[23] = 99; # croak!
$array_of_my_very_own_types[2] = 'BLUE'; # OK!


Available at a CPAN near you!




Similar ThreadsPosted
modulespath via environment-variable ? February 21, 2005, 2:19 am
Mod_perl conflict with PHP on HTTP_REFERER variable November 16, 2005, 6:04 pm
Annoying 'Variable ... will not stay shared' messages January 20, 2008, 5:32 am
Parallel::ForkManager pass a variable to global scope? September 1, 2006, 2:44 pm
[ANN] Archive::Zip 1.12 released July 12, 2004, 8:21 pm
[ANN] Archive::Zip 1.14 released October 22, 2004, 4:04 pm
[ANN] Archive::Zip 1.14 released October 22, 2004, 11:03 pm
ANNOUNCEMENT: POE 0.31 Released April 19, 2005, 4:40 pm
Device::Gsm v1.34 released to CPAN August 18, 2004, 8:53 am
MP4::Info 1.00 released to CPAN August 22, 2004, 12:45 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap