| 1 | 5 | ▶ | use strictures 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Moove; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # ABSTRACT: functions and methods with parameter lists and type constraints | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Type::Tiny 1.000006 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Type::Registry (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Type::Utils qw(class_type); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Function::Parameters 1.0703 qw(:lax); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Import::Into 1.002004 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Syntax::Feature::Try 1.003 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Data::OptList 0.109 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use Carp qw(croak confess); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 5 | our @EXPORT; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 5 | our $VERSION = '0.006'; # VERSION | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 5 | my %OPTIONS; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 5 | ▶ | use constant PKGRE => qr{^\w+(::\w+)+$}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 8 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=12 SCAR=26.4
| |||||||||||||||||||||||||||||
| 27 | 8 | my $caller = scalar caller; | |||||||||||||||||||||||||||
| 28 | 8 | my $class = shift; | |||||||||||||||||||||||||||
| 29 | 8 | my $opts = Data::OptList::mkopt_hash(\@_); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 8 | my $registry = Type::Registry->for_class($caller); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 8 | ▶ | my $options = $OPTIONS{$caller} ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$OPTIONS{$caller} ||= {}
MC/DC0%0/1
$OPTIONS{$caller} ||= {}
$OPTIONS{$caller}
Truth table50%1/2
A
A= $OPTIONS{$caller}
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 8 | ▶ | if (my $types = delete $opts->{types}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | if (ref $types eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 37 | 0 | $registry->add_types(@$types); | |||||||||||||||||||||||||||
| 38 | } elsif (ref $types eq 'SCALAR') { | ||||||||||||||||||||||||||||
| 39 | 1 | $registry->add_types($$types); | |||||||||||||||||||||||||||
| 40 | } else { | ||||||||||||||||||||||||||||
| 41 | 0 | croak "unknown value for argument 'types': $types"; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 8 | ▶ | if (my $classes = delete $opts->{classes}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | foreach my $class (@$classes) { | |||||||||||||||||||||||||||
| 46 | 0 | my $type = class_type($class); | |||||||||||||||||||||||||||
| 47 | 0 | $registry->add_type($type); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 8 | ▶ | if (my $types = delete $opts->{type}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | foreach my $type (@$types) { | |||||||||||||||||||||||||||
| 52 | 0 | $registry->add_type($type); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 8 | ▶ | unless (exists $opts->{-nostdtypes}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 8 | $registry->add_types(-Standard); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 8 | ▶ | if (exists $opts->{-autoclass}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 2 | $options->{autoclass} = 1; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 8 | Function::Parameters->import::into($caller, { | |||||||||||||||||||||||||||
| 65 | method => { | ||||||||||||||||||||||||||||
| 66 | defaults => 'method', | ||||||||||||||||||||||||||||
| 67 | runtime => 0, | ||||||||||||||||||||||||||||
| 68 | strict => 1, | ||||||||||||||||||||||||||||
| 69 | reify_type => \&_reify_type, | ||||||||||||||||||||||||||||
| 70 | }, | ||||||||||||||||||||||||||||
| 71 | func => { | ||||||||||||||||||||||||||||
| 72 | defaults => 'function', | ||||||||||||||||||||||||||||
| 73 | runtime => 0, | ||||||||||||||||||||||||||||
| 74 | strict => 1, | ||||||||||||||||||||||||||||
| 75 | reify_type => \&_reify_type, | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | }); | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 8 | ▶ | if (exists $opts->{-trycatch}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 9 | ▶ | Syntax::Feature::Try::register_exception_matcher(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 81 | 9 | my ($exception, $typedef) = @_; | |||||||||||||||||||||||||||
| 82 | 9 | ▶ | if ($options->{autoclass} and $typedef =~ PKGRE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$options->{"autoclass"} and $typedef =~ /^\w+(::\w+)+$/
MC/DC50%1/2
$options->{"autoclass"} and $typedef =~ /^\w+(::\w+)+$/
$options->{"autoclass"}
$typedef =~ /^\w+(::\w+)+$/
Truth table66%2/3
A and B
A= $options->{"autoclass"}B= $typedef =~ /^\w+(::\w+)+$/
| |||||||||||||||||||||||||||||
| 83 | 6 | ▶ | if ($typedef->can('caught')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 4 | ▶ | return $typedef->caught($exception) || undef; | ||||||||||||||||||||||||||
|
Condition100%2/2
$typedef->caught($exception) || undef
MC/DC100%1/1
$typedef->caught($exception) || undef
$typedef->caught($exception)
Truth table100%2/2
A
A= $typedef->caught($exception)
| |||||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||
| 86 | 2 | ▶ | return class_type($typedef)->check($exception) || undef; | ||||||||||||||||||||||||||
|
Condition50%1/2
class_type($typedef)->check($exception) || undef
MC/DC0%0/1
class_type($typedef)->check($exception) || undef
class_type($typedef)->check($exception)
Truth table50%1/2
A
A= class_type($typedef)->check($exception)
| |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||
| 89 | 3 | ▶ | return $registry->lookup($typedef)->check($exception) || undef; | ||||||||||||||||||||||||||
|
Condition100%2/2
$registry->lookup($typedef)->check($exception) || undef
MC/DC100%1/1
$registry->lookup($typedef)->check($exception) || undef
$registry->lookup($typedef)->check($exception)
Truth table100%2/2
A
A= $registry->lookup($typedef)->check($exception)
| |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 2 | }); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 2 | require syntax; | |||||||||||||||||||||||||||
| 94 | 2 | syntax->import_into($caller, 'try'); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 5 | ▶ | sub _reify_type { | ||||||||||||||||||||||||||
|
Subroutine
_reify_type: called CC=6 SCAR=19.4
| |||||||||||||||||||||||||||||
| 99 | 5 | my ($typedef, $package) = @_; | |||||||||||||||||||||||||||
| 100 | 5 | my ($caller, $file, $line) = caller; | |||||||||||||||||||||||||||
| 101 | 5 | ▶ | $package //= $caller; | ||||||||||||||||||||||||||
|
Condition33%1/3
$package //= $caller
MC/DC0%0/2
$package //= $caller
$package
$caller
Truth table33%1/3
A //= B
A= $packageB= $caller
| |||||||||||||||||||||||||||||
| 102 | 5 | ▶ | my $options = $OPTIONS{$package} || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$OPTIONS{$package} || {}
MC/DC0%0/1
$OPTIONS{$package} || {}
$OPTIONS{$package}
Truth table50%1/2
A
A= $OPTIONS{$package}
| |||||||||||||||||||||||||||||
| 103 | 5 | my $type; | |||||||||||||||||||||||||||
| 104 | 5 | eval { | |||||||||||||||||||||||||||
| 105 | 5 | ▶ | if ($options->{autoclass} and $typedef =~ PKGRE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$options->{"autoclass"} and $typedef =~ /^\w+(::\w+)+$/
MC/DC50%1/2
$options->{"autoclass"} and $typedef =~ /^\w+(::\w+)+$/
$options->{"autoclass"}
$typedef =~ /^\w+(::\w+)+$/
Truth table66%2/3
A and B
A= $options->{"autoclass"}B= $typedef =~ /^\w+(::\w+)+$/
| |||||||||||||||||||||||||||||
| 106 | 1 | $type = class_type($typedef); | |||||||||||||||||||||||||||
| 107 | } else { | ||||||||||||||||||||||||||||
| 108 | 4 | my $registry = Type::Registry->for_class($package); | |||||||||||||||||||||||||||
| 109 | 4 | $type = $registry->lookup($typedef); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | }; | ||||||||||||||||||||||||||||
| 112 | 5 | ▶ | if (my $e = $@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | $e =~ s{\s+ at \s+ \S+ \s+ line \s+ \S+ \s*$}{}xs; | |||||||||||||||||||||||||||
| 114 | 0 | warn "$e at $file line $line\n"; | |||||||||||||||||||||||||||
| 115 | 0 | exit 255; | |||||||||||||||||||||||||||
| 116 | } else { | ||||||||||||||||||||||||||||
| 117 | 5 | return $type; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 5 | 1; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||||||||||