Variable::Strongly::Typed

Variable::Strongly::Typed is a Perl module to let some variables be strongly typed.
Download

Variable::Strongly::Typed Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Mark Ethan Trostler
  • Publisher web site:
  • http://search.cpan.org/~metzzo/Java-4.7/Java.pm

Variable::Strongly::Typed Tags


Variable::Strongly::Typed Description

Variable::Strongly::Typed is a Perl module to let some variables be strongly typed. Variable::Strongly::Typed is a Perl module to let some variables be strongly typed.SYNOPSISuse 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 $int_own_error :TYPE('int', &my_own_error_handler); # Roll my own error handler my @array_of_rgb :TYPE(&red_green_blue); # my enumerated type # For subs!! sub return_an_int :TYPE('int') { # .. do some stuff .. return $something; } # ... 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 = 44; # Groovy $array_of_ints = 'yah'; # croak! $hash_of_floats{pi} = 3.14159; # no problem $hash_of_floats{e} = 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 = 99; # croak! $array_of_my_very_own_types = 'BLUE'; # OK! $int_own_error = 'lksdklwe'; # The sub 'my_own_error_hanlder' # will be # called with the # offending value my $got_it = return_an_int(); # Will 'croak' (or call your error # function) # if this sub doesn't # return an 'int'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. Requirements: · Perl


Variable::Strongly::Typed Related Software