| 1 | 1 | ▶ | use 5.006; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | package isa; | ||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||
| 7 | 1 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '2.000'; | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | BEGIN { | ||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | *HAS_XS = eval { require Type::Tiny::XS; 1 } ? sub(){!!1} : sub(){!!0}; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=4 SCAR=15.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | *HAS_NATIVE = ($] ge '5.032') ? sub(){!!1} : sub(){!!0}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | *perlstring = eval { require B; 'B'->can('perlstring') } || sub { sprintf '"%s"', quotemeta($_[0]) }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.8
Condition33%1/3
eval {
do {
require B;
'B'->can('perlstring')
}
} || sub {
sprintf '"%s"', quotemeta $_[0];
}
MC/DC0%0/2
eval {
do {
require B;
'B'->can('perlstring')
}
} || sub {
sprintf '"%s"', quotemeta $_[0];
}
eval {
do {
require B;
'B'->can('perlstring')
}
}
sub {
sprintf '"%s"', quotemeta $_[0];
}
Truth table33%1/3
A || B
A= eval {
do {
require B;
'B'->can('perlstring')
}
}B= sub {
sprintf '"%s"', quotemeta $_[0];
}
| |||||||||||||||||||||||||||||||
| 14 | }; | ||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | sub import { | ||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | my ( $caller, $me ) = ( scalar(caller), shift ); | ||||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||
| 19 | 1 | my $imports; | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | if ( @_==1 and ref($_[0]) eq 'HASH' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||
| 21 | 0 | $imports = $_[0]; | |||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||
| 23 | else { | ||||||||||||||||||||||||||||||
| 24 | 1 | my %imports = map { $me->subname_for($_) => $_ } @_; | |||||||||||||||||||||||||||||
| 25 | 1 | $imports = \%imports; | |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | 1 | $me->setup_for($caller, $imports); | |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||
| 31 | sub subname_for { | ||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | my ( $me, $class ) = ( shift, @_ ); | ||||||||||||||||||||||||||||
|
Subroutine
subname_for: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 33 | 2 | $class =~ s/\W+/_/g; | |||||||||||||||||||||||||||||
| 34 | 2 | 'isa_' . $class; | |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||
| 37 | 1 | my %cache; | |||||||||||||||||||||||||||||
| 38 | sub setup_for { | ||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | my ( $me, $caller, $imports ) = ( shift, @_ ); | ||||||||||||||||||||||||||||
|
Subroutine
setup_for: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | while ( my ($subname, $class) = each %$imports ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 44 | 2 | *{"$caller\::$subname"} = ( | |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | $cache{$class} ||= $me->generate_coderef($class) | ||||||||||||||||||||||||||||
|
Condition40%2/5
($cache{$class} ||= $me->generate_coderef($class)) || die("Problem generating coderef for $class")
$cache{$class} ||= $me->generate_coderef($class)
MC/DC0%0/1
($cache{$class} ||= $me->generate_coderef($class)) || die("Problem generating coderef for $class")
($cache{$class} ||= $me->generate_coderef($class))
MC/DC0%0/2
$cache{$class} ||= $me->generate_coderef($class)
$cache{$class}
$me->generate_coderef($class)
Truth table50%1/2
A
A= ($cache{$class} ||= $me->generate_coderef($class))
Truth table33%1/3
A ||= B
A= $cache{$class}B= $me->generate_coderef($class)
| |||||||||||||||||||||||||||||||
| 46 | or die("Problem generating coderef for $class") | ||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||
| 51 | sub generate_coderef { | ||||||||||||||||||||||||||||||
| 52 | 2 | ▶ | my ( $me, $class ) = ( shift, @_ ); | ||||||||||||||||||||||||||||
|
Subroutine
generate_coderef: called CC=6 SCAR=22.2
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | 2 | my $coderef; | |||||||||||||||||||||||||||||
| 55 | 2 | if ( HAS_XS ) { | |||||||||||||||||||||||||||||
| 56 | 2 | my $native_will_be_faster = 0; | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | 2 | if ( HAS_NATIVE ) { | |||||||||||||||||||||||||||||
| 59 | 2 | my $class_isa = eval { $class->can('isa') }; | |||||||||||||||||||||||||||||
| 60 | 2 | ▶ | if ( $class_isa and $class_isa != \&UNIVERSAL::isa ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$class_isa and $class_isa != \&UNIVERSAL::isa
MC/DC0%0/2
$class_isa and $class_isa != \&UNIVERSAL::isa
$class_isa
$class_isa != \&UNIVERSAL::isa
Truth table33%1/3
A and B
A= $class_isaB= $class_isa != \&UNIVERSAL::isa
| |||||||||||||||||||||||||||||||
| 61 | 0 | $native_will_be_faster = 1; | |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | 2 | ▶ | unless ($native_will_be_faster) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 66 | 2 | my $typename = sprintf('InstanceOf[%s]', $class); | |||||||||||||||||||||||||||||
| 67 | 2 | $coderef = Type::Tiny::XS::get_coderef_for($typename); | |||||||||||||||||||||||||||||
| 68 | 2 | ▶ | return $coderef if $coderef; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||
| 72 | 0 | my $code; | |||||||||||||||||||||||||||||
| 73 | 0 | if ( HAS_NATIVE ) { | |||||||||||||||||||||||||||||
| 74 | 0 | $code = sprintf( | |||||||||||||||||||||||||||||
| 75 | q{ package isa::__NATIVE__; use feature q[isa]; no warnings q[experimental::isa]; sub { $_[0] isa %s } }, | ||||||||||||||||||||||||||||||
| 76 | perlstring($class), | ||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||||
| 80 | require Scalar::Util; | ||||||||||||||||||||||||||||||
| 81 | $code = sprintf( | ||||||||||||||||||||||||||||||
| 82 | q{ package isa::__LEGACY__; sub { Scalar::Util::blessed($_[0]) and $_[0]->isa(%s) } }, | ||||||||||||||||||||||||||||||
| 83 | perlstring($class), | ||||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||
| 87 | 0 | $coderef = eval $code; | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | ref($coderef) ? $coderef : (); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||
| 91 | 1 | 1; | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||||