types - Perl pragma for strict type checking


types documentation  | view source Contained in the types distribution.

Index


NAME

Top

types - Perl pragma for strict type checking

SYNOPSIS

Top

  use types;
  my int $int;
  my float $float;
  $int = $float; # BOOM compile time error!

ABSTRACT

Top

This pragma uses the optimzie module to analyze the optree and turn on compile time type checking

SYNOPSIS

Top

    my float $foo = "string"; #compile time error
    sub foo (int $foo) { my ($foo) = @_ };
    foo("hi"); #compile time error   

    my int $int;
    sub foo { my float $foo; return $foo }
    $int = $foo; # compile time error

DESCRIPTION

Top

This pragma uses the optimzie module to analyze the optree and turn on compile time type checking

Currently we support int, float, number ,string and user defined classes, the implict casting rules are as follows.

    


    int    < > number
    int      > float
    float  < > number
    number   > string




Normall type casting is allowed both up and down the inheritance tree, so in theory user defined classes should work already, requires one to do use base or set @ISA at compileitme in a BEGIN block.

Return values

Return values are implicitly figerd out by the subroutine, this includes both falling of the end or by expliticly calling return, if two return values of the same sub differ you will get an error message.

Arguments

Arguments are declared with prototype syntax, they can either be named or just typed, if typed only the calling convertions are checked, if named then that named lexical will get that type without the need for expliticty typing it, thus allowing list assignment from @_

EXPORT

None.

BUGS

Top

Please report bugs and submit patches using http://rt.cpan.org/

SEE ALSO

Top

optimize B::Generate optimizer

AUTHOR

Top

Arthur Bergman, <ABERGMAN@CPAN.ORG>

COPYRIGHT AND LICENSE

Top


types documentation  | view source Contained in the types distribution.