]>
Dogcows Code - chaz/p5-Return-Type-Lexical/blob - lib/Return/Type/Lexical.pm
a6d58073a0a3c0535a0af10f867c57037df1c507
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;
22 my $level = shift // 0;
23 my $hinthash = (caller($level))[10];
24 my $in_effect = $hinthash->{'Return::Type::Lexical/in_effect'};
25 return !defined $in_effect || $in_effect;
30 $handler = $UNIVERSAL::{ReturnType
};
31 delete $UNIVERSAL::{ReturnType
};
32 delete $UNIVERSAL::{_ATTR_CODE_ReturnType
};
34 sub UNIVERSAL
::ReturnType
:ATTR
(CODE
,BEGIN) {
35 my $in_effect = _in_effect
(4);
36 return if !$in_effect;
38 return $handler->(@_);
46 use Return::Type::Lexical;
47 use Types::Standard qw(Int);
49 sub foo :ReturnType(Int) { return "not an int" }
52 no Return::Type::Lexical;
53 sub bar :ReturnType(Int) { return "not an int" }
56 my $foo = foo(); # throws an error
57 my $bar = bar(); # returns "not an int"
59 # Can also be used with Devel::StrictMode to only perform
60 # type checks in strict mode:
62 use Devel::StrictMode;
63 use Return::Type::Lexical check => STRICT;
67 This module works just like L<Return::Type>, but type-checking can be enabled and disabled within
70 There is no runtime penalty when type-checking is disabled.
74 The C<check> attribute can be used to set whether or not types are checked.
This page took 0.040754 seconds and 4 git commands to generate.