]>
Dogcows Code - chaz/p5-Return-Type-Lexical/blob - lib/Return/Type/Lexical.pm
1 package Return
::Type
::Lexical
;
2 # ABSTRACT: Same thing as Return::Type, but lexical
8 use parent
'Return::Type';
10 our $VERSION = '999.999'; # VERSION
13 my ($class, %args) = @_;
14 $^H{'Return::Type::Lexical/in_effect'} = exists $args{check
} && !$args{check
} ? 0 : 1;
18 $^H{'Return::Type::Lexical/in_effect'} = 0;
23 $level = 0 if !defined $level;
24 my $hinthash = (caller($level))[10];
25 my $in_effect = $hinthash->{'Return::Type::Lexical/in_effect'};
26 return !defined $in_effect || $in_effect;
31 $handler = $UNIVERSAL::{ReturnType
};
32 delete $UNIVERSAL::{ReturnType
};
33 delete $UNIVERSAL::{_ATTR_CODE_ReturnType
};
35 sub UNIVERSAL
::ReturnType
:ATTR
(CODE
,BEGIN) {
36 my $in_effect = _in_effect
(4);
37 return if !$in_effect;
39 return $handler->(@_);
47 use Return::Type::Lexical;
48 use Types::Standard qw(Int);
50 sub foo :ReturnType(Int) { return "not an int" }
53 no Return::Type::Lexical;
54 sub bar :ReturnType(Int) { return "not an int" }
57 my $foo = foo(); # throws an error
58 my $bar = bar(); # returns "not an int"
60 # Can also be used with Devel::StrictMode to only perform
61 # type checks in strict mode:
63 use Devel::StrictMode;
64 use Return::Type::Lexical check => STRICT;
68 This module works just like L<Return::Type>, but type-checking can be enabled and disabled within
71 There is no runtime penalty when type-checking is disabled.
75 The C<check> attribute can be used to set whether or not types are checked.
This page took 0.03481 seconds and 5 git commands to generate.