File Coverage

blib/lib/Return/Type/Lexical.pm
Criterion Covered Total %
statement 27 27 100.0
branch 4 4 100.0
condition 6 8 75.0
subroutine 10 10 100.0
pod 0 1 0.0
total 47 50 94.0


line stmt bran cond sub pod time code
1             package Return::Type::Lexical;
2             # ABSTRACT: Same thing as Return::Type, but lexical
3              
4 1     1   155909 use 5.008;
  1         7  
5 1     1   6 use warnings;
  1         2  
  1         24  
6 1     1   5 use strict;
  1         2  
  1         22  
7              
8 1     1   413 use parent 'Return::Type';
  1         280  
  1         5  
9              
10             our $VERSION = '0.001'; # VERSION
11              
12             sub import {
13 2     2   159 my ($class, %args) = @_;
14 2 100 66     94 $^H{'Return::Type::Lexical/in_effect'} = exists $args{check} && !$args{check} ? 0 : 1;
15             }
16              
17             sub unimport {
18 1     1   5346 $^H{'Return::Type::Lexical/in_effect'} = 0;
19             }
20              
21             sub _in_effect {
22 4   50 4   18 my $level = shift // 0;
23 4         13 my $hinthash = (caller($level))[10];
24 4         83 my $in_effect = $hinthash->{'Return::Type::Lexical/in_effect'};
25 4   100     19 return !defined $in_effect || $in_effect;
26             }
27              
28             my $handler;
29             BEGIN {
30 1     1   9238 $handler = $UNIVERSAL::{ReturnType};
31 1         2 delete $UNIVERSAL::{ReturnType};
32 1         67 delete $UNIVERSAL::{_ATTR_CODE_ReturnType};
33             }
34             sub UNIVERSAL::ReturnType :ATTR(CODE,BEGIN) {
35 4     4 0 5187 my $in_effect = _in_effect(4);
36 4 100       11 return if !$in_effect;
37              
38 2         6 return $handler->(@_);
39 1     1   8 }
  1         3  
  1         11  
40              
41             1;
42              
43             __END__