| 1 | package Return::Type::Lexical; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Same thing as Return::Type, but lexical | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use parent 'Return::Type'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.002'; # VERSION | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 13 | 2 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 14 | 2 | ▶ | $^H{'Return::Type::Lexical/in_effect'} = exists $args{check} && !$args{check} ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $args{"check"} and not $args{"check"}
MC/DC50%1/2
exists $args{"check"} and not $args{"check"}
exists $args{"check"}
not $args{"check"}
Truth table66%2/3
A and not(B)
A= exists $args{"check"}B= not $args{"check"}
| |||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | sub unimport { | ||||||||||||||||||||||||||
|
Subroutine
unimport: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | $^H{'Return::Type::Lexical/in_effect'} = 0; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 4 | ▶ | sub _in_effect { | ||||||||||||||||||||||||||
|
Subroutine
_in_effect: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 22 | 4 | my ($level) = @_; | |||||||||||||||||||||||||||
| 23 | 4 | ▶ | $level = 0 if !defined $level; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 4 | my $hinthash = (caller($level))[10]; | |||||||||||||||||||||||||||
| 25 | 4 | my $in_effect = $hinthash->{'Return::Type::Lexical/in_effect'}; | |||||||||||||||||||||||||||
| 26 | 4 | ▶ | return !defined $in_effect || $in_effect; | ||||||||||||||||||||||||||
|
Condition100%3/3
!defined($in_effect) || $in_effect
MC/DC100%2/2
!defined($in_effect) || $in_effect
!defined($in_effect)
$in_effect
Truth table100%3/3
not(A) || B
A= !defined($in_effect)B= $in_effect
| |||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # XXX This is kind of janky. It relies upon Return::Type using Attribute::Handlers, and it assumes | ||||||||||||||||||||||||||||
| 30 | # some internal Attribute::Handlers behavior. If it proves to be too fragile, we may need to copy | ||||||||||||||||||||||||||||
| 31 | # the Return::Type code to here. Or make Return::Type lexical if that can be done without breaking | ||||||||||||||||||||||||||||
| 32 | # backward-compatibility. | ||||||||||||||||||||||||||||
| 33 | 2 | my $handler; | |||||||||||||||||||||||||||
| 34 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 2 | $handler = $UNIVERSAL::{ReturnType}; | |||||||||||||||||||||||||||
| 36 | 2 | delete $UNIVERSAL::{ReturnType}; | |||||||||||||||||||||||||||
| 37 | 2 | delete $UNIVERSAL::{_ATTR_CODE_ReturnType}; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 4 | ▶ | sub UNIVERSAL::ReturnType :ATTR(CODE,BEGIN) { | ||||||||||||||||||||||||||
|
Subroutine
ReturnType: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 4 | my $in_effect = _in_effect(4); | |||||||||||||||||||||||||||
| 41 | 4 | ▶ | return if !$in_effect; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | return $handler->(@_); | |||||||||||||||||||||||||||
| 44 | 2 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 2 | 1; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | __END__ | ||||||||||||||||||||||||||||