| 1 | package MooX::MouseTypeConstraints; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = "0.01"; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use B::Hooks::EndOfScope; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Mouse::Util::TypeConstraints (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 5 | my $class = shift; | |||||||||||||||||||||||||||
| 13 | 5 | my $target = caller; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | on_scope_end { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 16 | 5 | ▶ | my $has = $target->can('has') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | or die q|Moo's internal DSL keyword `has` is not found. (perhaps you forgot to load "Moo"?)|; | ||||||||||||||||||||||||||||
| 18 | 4 | ▶ | my $code = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.6
| |||||||||||||||||||||||||||||
| 19 | 4 | my ($name, %args) = @_; | |||||||||||||||||||||||||||
| 20 | 4 | ▶ | if (exists $args{isa} && !ref $args{isa}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $args{"isa"} and not ref $args{"isa"}
MC/DC0%0/2
exists $args{"isa"} and not ref $args{"isa"}
exists $args{"isa"}
not ref $args{"isa"}
Truth table33%1/3
A and not(B)
A= exists $args{"isa"}B= not ref $args{"isa"}
| |||||||||||||||||||||||||||||
| 21 | 4 | my $type = Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint($args{isa}); | |||||||||||||||||||||||||||
| 22 | 4 | $args{isa} = _generate_isa($type); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | 4 | @_ = ($name, %args); | |||||||||||||||||||||||||||
| 25 | 4 | goto $has; | |||||||||||||||||||||||||||
| 26 | 4 | }; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 4 | my $glob = "${target}::has"; | |||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||
| 30 | 3 | ▶ | no strict qw/refs/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 3 | ▶ | no warnings qw/prototype redefine/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 4 | *{$glob} = $code; | |||||||||||||||||||||||||||
| 33 | }; | ||||||||||||||||||||||||||||
| 34 | 5 | }; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 4 | ▶ | sub _generate_isa { | ||||||||||||||||||||||||||
|
Subroutine
_generate_isa: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 38 | 4 | my $type = shift; | |||||||||||||||||||||||||||
| 39 | 4 | ▶ | if ($type->has_coercion) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 3 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 41 | 3 | ▶ | die $type->get_message(@_) unless $type->check($type->coerce(@_)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 1 | }; | |||||||||||||||||||||||||||
| 43 | } else { | ||||||||||||||||||||||||||||
| 44 | 8 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 45 | 8 | ▶ | die $type->get_message(@_) unless $type->check(@_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 3 | }; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 3 | 1; | |||||||||||||||||||||||||||
| 51 | __END__ | ||||||||||||||||||||||||||||