blib/lib/Moove.pm

filter: Statementstmt 87.6% 71 / 81 Branchbran 75.0% 18 / 24 Conditioncond 63.1% 12 / 19 MC/DCmcdc 36.3% 4 / 11 Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 79.7% 118 / 148 CC 23 SCAR 20.4
CC
23
Cov
81%
import
13.9
__ANON__
7.1
_reify_type
6.9
CRAP 7.7
↑ Summary
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} ||= {}
l!l
08
MC/DC0%0/1
$OPTIONS{$caller} ||= {}
$OPTIONS{$caller}
Truth table50%1/2
A
A= $OPTIONS{$caller}
Aresult
11
00
34  
35 8 ▶ if (my $types = delete $opts->{types}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $types = delete $opts->{"types"}) 1 7 8
36 1 ▶ if (ref $types eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $types eq 'ARRAY') { } 0 1 1
elsif (ref $types eq 'SCALAR') { } 1 0 1
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
BranchTrueFalseTotal
if (my $classes = delete $opts->{"classes"}) 0 8 8
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
BranchTrueFalseTotal
if (my $types = delete $opts->{"type"}) 0 8 8
51 0 foreach my $type (@$types) {
52 0 $registry->add_type($type);
53 }
54 }
55  
56 8 ▶ unless (exists $opts->{-nostdtypes}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"-nostdtypes"}) 8 0 8
57 8 $registry->add_types(-Standard);
58 }
59  
60 8 ▶ if (exists $opts->{-autoclass}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"-autoclass"}) 2 6 8
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
BranchTrueFalseTotal
if (exists $opts->{"-trycatch"}) 2 6 8
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
BranchTrueFalseTotal
if ($options->{'autoclass'} and $typedef =~ /^\w+(::\w+)+$/) { } 6 3 9
Condition66%2/3
$options->{"autoclass"} and $typedef =~ /^\w+(::\w+)+$/
!ll&&!rl&&r
306
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+)+$/
ABresult
0X0
100
111
83 6 ▶ if ($typedef->can('caught')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($typedef->can('caught')) { } 4 2 6
84 4 ▶ return $typedef->caught($exception) || undef;
Condition100%2/2
$typedef->caught($exception) || undef
l!l
22
MC/DC100%1/1
$typedef->caught($exception) || undef
$typedef->caught($exception)
Truth table100%2/2
A
A= $typedef->caught($exception)
Aresult
11
00
85 } else {
86 2 ▶ return class_type($typedef)->check($exception) || undef;
Condition50%1/2
class_type($typedef)->check($exception) || undef
l!l
10
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)
Aresult
11
00
87 }
88 } else {
89 3 ▶ return $registry->lookup($typedef)->check($exception) || undef;
Condition100%2/2
$registry->lookup($typedef)->check($exception) || undef
l!l
21
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)
Aresult
11
00
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
l!l&&r!l&&!r
050
MC/DC0%0/2
$package //= $caller
$package $caller
Truth table33%1/3
A //= B
A= $packageB= $caller
ABresult
1X1
011
000
102 5 ▶ my $options = $OPTIONS{$package} || {};
Condition50%1/2
$OPTIONS{$package} || {}
l!l
50
MC/DC0%0/1
$OPTIONS{$package} || {}
$OPTIONS{$package}
Truth table50%1/2
A
A= $OPTIONS{$package}
Aresult
11
00
103 5 my $type;
104 5 eval {
105 5 ▶ if ($options->{autoclass} and $typedef =~ PKGRE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{'autoclass'} and $typedef =~ /^\w+(::\w+)+$/) { } 1 4 5
Condition66%2/3
$options->{"autoclass"} and $typedef =~ /^\w+(::\w+)+$/
!ll&&!rl&&r
401
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+)+$/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (my $e = $@) { } 0 5 5
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__
↑ Summary