]>
Dogcows Code - chaz/p5-Return-Type-Lexical/blob - lib/Return/Type/Lexical.pm
83d4ec1d3bc9eb7c4c27d31635249121123e5b24
1 package Return
::Type
::Lexical
;
2 # ABSTRACT: Same thing as Return::Type, but lexical
8 use parent
'Return::Type';
10 our $VERSION = '0.001'; # 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->(@_);
51 Return::Type::Lexical - Same thing as Return::Type, but lexical
59 use Return::Type::Lexical;
60 use Types::Standard qw(Int);
62 sub foo :ReturnType(Int) { return "not an int" }
65 no Return::Type::Lexical;
66 sub bar :ReturnType(Int) { return "not an int" }
69 my $foo = foo(); # throws an error
70 my $bar = bar(); # returns "not an int"
72 # Can also be used with Devel::StrictMode to only perform
73 # type checks in strict mode:
75 use Devel::StrictMode;
76 use Return::Type::Lexical check => STRICT;
80 This module works just like L<Return::Type>, but type-checking can be enabled and disabled within
83 There is no runtime penalty when type-checking is disabled.
89 The C<check> attribute can be used to set whether or not types are checked.
93 Please report any bugs or feature requests on the bugtracker website
94 L<https://github.com/chazmcgarvey/Return-Type-Lexical/issues>
96 When submitting a bug or request, please include a test-file or a
97 patch to an existing test-file that illustrates the bug or desired
102 Charles McGarvey <chazmcgarvey@brokenzipper.com>
104 =head1 COPYRIGHT AND LICENSE
106 This software is copyright (c) 2020 by Charles McGarvey.
108 This is free software; you can redistribute it and/or modify it under
109 the same terms as the Perl 5 programming language system itself.
This page took 0.042023 seconds and 3 git commands to generate.