blib/lib/Type/Params.pm

filter: Statementstmt 99.0% 215 / 217 Branchbran 81.5% 62 / 76 Conditioncond 57.7% 41 / 71 MC/DCmcdc 15.9% 7 / 44 Subroutinesub 95.8% 46 / 48 Podpod 100% 14 / 14 totaltotal 81.9% 385 / 470 CC 66 SCAR 21.0
CC
66
Cov
87%
signature_for
24.3
signature
10.0
_wrap_subs
9.0
CRAP 8.1
« blib/lib/Type/Coercion.pm ↑ Summary blib/lib/Type/Coercion/FromMoose.pm »
1 package Type::Params;
2  
3 66 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 66 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 66 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 66 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 66 $Type::Params::AUTHORITY = 'cpan:TOBYINK';
9 66 $Type::Params::VERSION = '2.010001';
10 }
11  
12 66 $Type::Params::VERSION =~ tr/_//d;
13  
14 66 ▶use B qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 66 ▶use Eval::TypeTiny qw( eval_closure set_subname );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 66 ▶use Scalar::Util qw( refaddr );
Subroutine BEGIN: called CC=1 SCAR=0.0
17 66 ▶use Error::TypeTiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 66 ▶use Error::TypeTiny::Assertion;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 66 ▶use Error::TypeTiny::WrongNumberOfParameters;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 66 ▶use Types::Standard ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 66 ▶use Types::TypeTiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 66 require Exporter::Tiny;
24 66 our @ISA = 'Exporter::Tiny';
25  
26 66 our @EXPORT = qw(
27 compile compile_named
28 );
29  
30 66 our @EXPORT_OK = qw(
31 compile_named_oo
32 validate validate_named
33 multisig
34 Invocant ArgsObject
35 wrap_subs wrap_methods
36 signature signature_for signature_for_func signature_for_method
37 );
38  
39 66 our %EXPORT_TAGS = (
40 compile => [ qw( compile compile_named compile_named_oo ) ],
41 wrap => [ qw( wrap_subs wrap_methods ) ],
42 sigs => [ qw( signature signature_for ) ],
43 validate => [ qw( validate validate_named ) ],
44 sigplus => [ qw( signature signature_for signature_for_func signature_for_method ) ],
45
46 v1 => [ qw( compile compile_named ) ], # Old default
47 v2 => [ qw( signature signature_for ) ], # New recommendation
48 );
49  
50 66 ▶BEGIN {
Subroutine BEGIN: called CC=7 SCAR=20.2
51 66 my $pfx = $ENV{'PERL_TYPE_PARAMS_SUBNAME_PREFIX'};
52 66 ▶ eval sprintf(
Branch: 2 branches
BranchTrueFalseTotal
defined $pfx && $pfx =~ /::\z/ ? : 0 66 66
$pfx ? : 1 65 66
Condition66%2/3
defined $pfx and $pfx =~ /::\z/
!ll&&!rl&&r
6510
MC/DC0%0/2
defined $pfx and $pfx =~ /::\z/
defined $pfx $pfx =~ /::\z/
Truth table66%2/3
A and B
A= defined $pfxB= $pfx =~ /::\z/
ABresult
0X0
100
111
53 'sub SIGNATURE_SUBNAME_PREFIX () { %s }',
54 B::perlstring(
55 ( defined $pfx and $pfx =~ /::\z/ ) ? $pfx : $pfx ? 'SIGNATURE_FOR::' : '',
56 )
57 );
58  
59 66 my $sfx = $ENV{'PERL_TYPE_PARAMS_SUBNAME_SUFFIX'};
60 66 ▶ eval sprintf(
Branch: 2 branches
BranchTrueFalseTotal
defined $sfx && $sfx =~ /\A_/ ? : 0 66 66
$sfx ? : 1 65 66
Condition66%2/3
defined $sfx and $sfx =~ /\A_/
!ll&&!rl&&r
6510
MC/DC0%0/2
defined $sfx and $sfx =~ /\A_/
defined $sfx $sfx =~ /\A_/
Truth table66%2/3
A and B
A= defined $sfxB= $sfx =~ /\A_/
ABresult
0X0
100
111
61 'sub SIGNATURE_SUBNAME_SUFFIX () { %s }',
62 B::perlstring(
63 ( defined $sfx and $sfx =~ /\A_/ ) ? $sfx : $sfx ? '_SIGNATURE' : '',
64 )
65 );
66 };
67  
68 {
69 66 my $Invocant;
70
71 1 ▶ sub Invocant () {
Subroutine Invocant: called CC=2 SCAR=7.6
Pod documented
72 1 ▶ $Invocant ||= do {
Condition33%1/3
$Invocant ||= do { require Type::Tiny::Union; "Type::Tiny::Union"->new("name", "Invocant", "type_constraints", [&Types::Standard::Object(), &Types::Standard::ClassName()]) }
l!l&&r!l&&!r
010
MC/DC0%0/2
$Invocant ||= do { require Type::Tiny::Union; "Type::Tiny::Union"->new("name", "Invocant", "type_constraints", [&Types::Standard::Object(), &Types::Standard::ClassName()]) }
$Invocant do { require Type::Tiny::Union; "Type::Tiny::Union"->new("name", "Invocant", "type_constraints", [&Types::Standard::Object(), &Types::Standard::ClassName()]) }
Truth table33%1/3
A ||= B
A= $InvocantB= do { require Type::Tiny::Union; "Type::Tiny::Union"->new("name", "Invocant", "type_constraints", [&Types::Standard::Object(), &Types::Standard::ClassName()]) }
ABresult
1X1
011
000
73 1 require Type::Tiny::Union;
74 1 'Type::Tiny::Union'->new(
75 name => 'Invocant',
76 type_constraints => [
77 Types::Standard::Object(),
78 Types::Standard::ClassName(),
79 ],
80 );
81 };
82 } #/ sub Invocant
83
84 my $ArgsObject;
85
86 5 ▶ sub ArgsObject (;@) {
Subroutine ArgsObject: called CC=3 SCAR=11.8
Pod documented
87 5 ▶ $ArgsObject ||= do {
Condition66%2/3
$ArgsObject ||= do { "Type::Tiny"->new("name", "ArgsObject", "parent", &Types::Standard::Object(), "constraint", " ref(\$_) =~ qr/^Type::Params::OO::/ ", "constraint_generator", sub { Type::Tiny::check_parameter_count_for_parameterized_type("Type::Params", "ArgsObject", \@_, 1, 1); my $param = Types::Standard::assert_Str(shift()); sub { defined $_->{"~~caller"} and $_->{"~~caller"} eq $param; } ; } , "inline_generator", sub { my $param = shift(); my $quoted = B::perlstring($param); sub { my $var = pop(); return &Types::Standard::Object()->inline_check($var), sprintf(' ref(%s) =~ qr/^Type::Params::OO::/ ', $var), sprintf(q[ do { use Scalar::Util (); Scalar::Util::reftype(%s) eq 'HASH' } ], $var), sprintf(q[ defined((%s)->{'~~caller'}) && ((%s)->{'~~caller'} eq %s) ], $var, $var, $quoted); } ; } ) }
l!l&&r!l&&!r
320
MC/DC0%0/2
$ArgsObject ||= do { "Type::Tiny"->new("name", "ArgsObject", "parent", &Types::Standard::Object(), "constraint", " ref(\$_) =~ qr/^Type::Params::OO::/ ", "constraint_generator", sub { Type::Tiny::check_parameter_count_for_parameterized_type("Type::Params", "ArgsObject", \@_, 1, 1); my $param = Types::Standard::assert_Str(shift()); sub { defined $_->{"~~caller"} and $_->{"~~caller"} eq $param; } ; } , "inline_generator", sub { my $param = shift(); my $quoted = B::perlstring($param); sub { my $var = pop(); return &Types::Standard::Object()->inline_check($var), sprintf(' ref(%s) =~ qr/^Type::Params::OO::/ ', $var), sprintf(q[ do { use Scalar::Util (); Scalar::Util::reftype(%s) eq 'HASH' } ], $var), sprintf(q[ defined((%s)->{'~~caller'}) && ((%s)->{'~~caller'} eq %s) ], $var, $var, $quoted); } ; } ) }
$ArgsObject do { "Type::Tiny"->new("name", "ArgsObject", "parent", &Types::Standard::Object(), "constraint", " ref(\$_) =~ qr/^Type::Params::OO::/ ", "constraint_generator", sub { Type::Tiny::check_parameter_count_for_parameterized_type("Type::Params", "ArgsObject", \@_, 1, 1); my $param = Types::Standard::assert_Str(shift()); sub { defined $_->{"~~caller"} and $_->{"~~caller"} eq $param; } ; } , "inline_generator", sub { my $param = shift(); my $quoted = B::perlstring($param); sub { my $var = pop(); return &Types::Standard::Object()->inline_check($var), sprintf(' ref(%s) =~ qr/^Type::Params::OO::/ ', $var), sprintf(q[ do { use Scalar::Util (); Scalar::Util::reftype(%s) eq 'HASH' } ], $var), sprintf(q[ defined((%s)->{'~~caller'}) && ((%s)->{'~~caller'} eq %s) ], $var, $var, $quoted); } ; } ) }
Truth table66%2/3
A ||= B
A= $ArgsObjectB= do { "Type::Tiny"->new("name", "ArgsObject", "parent", &Types::Standard::Object(), "constraint", " ref(\$_) =~ qr/^Type::Params::OO::/ ", "constraint_generator", sub { Type::Tiny::check_parameter_count_for_parameterized_type("Type::Params", "ArgsObject", \@_, 1, 1); my $param = Types::Standard::assert_Str(shift()); sub { defined $_->{"~~caller"} and $_->{"~~caller"} eq $param; } ; } , "inline_generator", sub { my $param = shift(); my $quoted = B::perlstring($param); sub { my $var = pop(); return &Types::Standard::Object()->inline_check($var), sprintf(' ref(%s) =~ qr/^Type::Params::OO::/ ', $var), sprintf(q[ do { use Scalar::Util (); Scalar::Util::reftype(%s) eq 'HASH' } ], $var), sprintf(q[ defined((%s)->{'~~caller'}) && ((%s)->{'~~caller'} eq %s) ], $var, $var, $quoted); } ; } ) }
ABresult
1X1
011
000
88 'Type::Tiny'->new(
89 name => 'ArgsObject',
90 parent => Types::Standard::Object(),
91 constraint => q{ ref($_) =~ qr/^Type::Params::OO::/ },
92 3 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=1.2
93 3 Type::Tiny::check_parameter_count_for_parameterized_type( 'Type::Params', 'ArgsObject', \@_, 1, 1 );
94 3 my $param = Types::Standard::assert_Str( shift );
95 0 ▶ sub { defined( $_->{'~~caller'} ) and $_->{'~~caller'} eq $param };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
defined $_->{"~~caller"} and $_->{"~~caller"} eq $param 0 0 0
96 },
97 3 ▶ inline_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
98 3 my $param = shift;
99 3 my $quoted = B::perlstring( $param );
100 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
101 3 my $var = pop;
102 return (
103 3 Types::Standard::Object()->inline_check( $var ),
104 sprintf( q{ ref(%s) =~ qr/^Type::Params::OO::/ }, $var ),
105 sprintf(
106 q{ do { use Scalar::Util (); Scalar::Util::reftype(%s) eq 'HASH' } }, $var
107 ),
108 sprintf(
109 q{ defined((%s)->{'~~caller'}) && ((%s)->{'~~caller'} eq %s) }, $var, $var,
110 $quoted
111 ),
112 );
113 3 };
114 },
115 2 );
116 };
117
118 0 ▶ @_ ? $ArgsObject->parameterize( @{ $_[0] } ) : $ArgsObject;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 5 5
119 } #/ sub ArgsObject (;@)
120
121 66 &Scalar::Util::set_prototype( \&ArgsObject, ';$' )
122 if Eval::TypeTiny::NICE_PROTOTYPES;
123 }
124  
125 255 ▶sub signature {
Subroutine signature: called CC=9 SCAR=23.1
Pod documented
126 255 ▶ if ( @_ % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2) 1 254 255
127 1 require Error::TypeTiny;
128 1 Error::TypeTiny::croak( "Expected even-sized list of arguments" );
129 }
130 254 my ( %opts ) = @_;
131 254 ▶ $opts{next} ||= delete $opts{goto_next} if exists $opts{goto_next};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"goto_next"} 0 254 254
Condition0%0/3
$opts{"next"} ||= delete $opts{"goto_next"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"next"} ||= delete $opts{"goto_next"}
$opts{"next"} delete $opts{"goto_next"}
Truth table0%0/3
A ||= B
A= $opts{"next"}B= delete $opts{"goto_next"}
ABresult
1X1
011
000
132  
133 254 ▶ my $for = [ caller( 1 + ( $opts{caller_level} || 0 ) ) ]->[3] || ( ( $opts{package} || '__ANON__' ) . '::__ANON__' );
Condition83%5/6
[caller 1 + ($opts{'caller_level'} || 0)]->[3] || ($opts{'package'} || '__ANON__') . '::__ANON__'
l!l
21242
$opts{'caller_level'} || 0
l!l
37217
$opts{'package'} || '__ANON__'
l!l
042
MC/DC100%1/1
[caller 1 + ($opts{'caller_level'} || 0)]->[3] || ($opts{'package'} || '__ANON__') . '::__ANON__'
[caller 1 + ($opts{'caller_level'} || 0)]->[3]
MC/DC100%1/1
$opts{'caller_level'} || 0
$opts{'caller_level'}
Truth table100%2/2
A
A= [caller 1 + ($opts{'caller_level'} || 0)]->[3]
Aresult
11
00
Truth table100%2/2
A
A= $opts{'caller_level'}
Aresult
11
00
134 254 my ( $pkg, $sub ) = ( $for =~ /^(.+)::(\w+)$/ );
135 254 ▶ $opts{package} ||= $pkg;
Condition66%2/3
$opts{"package"} ||= $pkg
l!l&&r!l&&!r
22520
MC/DC0%0/2
$opts{"package"} ||= $pkg
$opts{"package"} $pkg
Truth table66%2/3
A ||= B
A= $opts{"package"}B= $pkg
ABresult
1X1
011
000
136 254 ▶ $opts{subname} ||= $sub;
Condition66%2/3
$opts{"subname"} ||= $sub
l!l&&r!l&&!r
22520
MC/DC0%0/2
$opts{"subname"} ||= $sub
$opts{"subname"} $sub
Truth table66%2/3
A ||= B
A= $opts{"subname"}B= $sub
ABresult
1X1
011
000
137  
138 254 require Type::Params::Signature;
139 254 'Type::Params::Signature'->new_from_v2api( \%opts )->return_wanted;
140 }
141  
142 39 ▶sub signature_for {
Subroutine signature_for: called CC=23 SCAR=31.9
Pod documented
143 39 ▶ if ( not @_ % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_ % 2) 1 38 39
144 1 require Error::TypeTiny;
145 1 Error::TypeTiny::croak( "Expected odd-sized list of arguments; did you forget the function name?" );
146 }
147 38 my ( $function, %opts ) = @_;
148 38 ▶ my $package = $opts{package} || caller( $opts{caller_level} || 0 );
Condition60%3/5
$opts{'package'} || caller($opts{'caller_level'} || 0)
l!l&&r!l&&!r
6320
$opts{'caller_level'} || 0
l!l
032
MC/DC50%1/2
$opts{'package'} || caller($opts{'caller_level'} || 0)
$opts{'package'} $opts{'caller_level'}
Truth table66%2/3
A || B
A= $opts{'package'}B= $opts{'caller_level'}
ABresult
1X1
011
000
149 38 ▶ $opts{next} ||= delete $opts{goto_next} if exists $opts{goto_next};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"goto_next"} 1 37 38
Condition33%1/3
$opts{"next"} ||= delete $opts{"goto_next"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$opts{"next"} ||= delete $opts{"goto_next"}
$opts{"next"} delete $opts{"goto_next"}
Truth table33%1/3
A ||= B
A= $opts{"next"}B= delete $opts{"goto_next"}
ABresult
1X1
011
000
150  
151 38 ▶ if ( ref($function) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $function eq "ARRAY") 3 35 38
152 3 $opts{package} = $package;
153 3 return map { signature_for( $_, %opts ) } @$function;
154 }
155
156 35 $opts{_is_signature_for} = 1;
157  
158 35 ▶ my $fullname = ( $function =~ /::/ ) ? $function : "$package\::$function";
Branch: 1 branch
BranchTrueFalseTotal
$function =~ /::/ ? : 0 35 35
159 35 ▶ $opts{package} ||= $package;
Condition66%2/3
$opts{"package"} ||= $package
l!l&&r!l&&!r
6290
MC/DC0%0/2
$opts{"package"} ||= $package
$opts{"package"} $package
Truth table66%2/3
A ||= B
A= $opts{"package"}B= $package
ABresult
1X1
011
000
160 35 ▶ $opts{subname} ||= ( $function =~ /::(\w+)$/ ) ? $1 : $function;
Branch: 1 branch
BranchTrueFalseTotal
$function =~ /::(\w+)$/ ? : 0 35 35
Condition33%1/3
$opts{"subname"} ||= $function =~ /::(\w+)$/ ? $1 : $function
l!l&&r!l&&!r
0350
MC/DC0%0/2
$opts{"subname"} ||= $function =~ /::(\w+)$/ ? $1 : $function
$opts{"subname"} $function =~ /::(\w+)$/ ? $1 : $function
Truth table33%1/3
A ||= B
A= $opts{"subname"}B= $function =~ /::(\w+)$/ ? $1 : $function
ABresult
1X1
011
000
161 66 ▶ $opts{next} ||= do { no strict 'refs'; exists(&$fullname) ? \&$fullname : undef; };
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
exists &$fullname ? : 27 3 30
Condition100%3/3
$opts{"next"} ||= do { no strict 'refs'; exists &$fullname ? \&$fullname : undef }
l!l&&r!l&&!r
5273
MC/DC100%2/2
$opts{"next"} ||= do { no strict 'refs'; exists &$fullname ? \&$fullname : undef }
$opts{"next"} do { no strict 'refs'; exists &$fullname ? \&$fullname : undef }
Truth table100%3/3
A ||= B
A= $opts{"next"}B= do { no strict 'refs'; exists &$fullname ? \&$fullname : undef }
ABresult
1X1
011
000
162 35 ▶ if ( $opts{method} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"method"}) 5 30 35
163 5 ▶ $opts{next} ||= eval { $package->can( $opts{subname} ) };
Condition66%2/3
$opts{"next"} ||= eval { do { $package->can($opts{"subname"}) } }
l!l&&r!l&&!r
410
MC/DC0%0/2
$opts{"next"} ||= eval { do { $package->can($opts{"subname"}) } }
$opts{"next"} eval { do { $package->can($opts{"subname"}) } }
Truth table66%2/3
A ||= B
A= $opts{"next"}B= eval { do { $package->can($opts{"subname"}) } }
ABresult
1X1
011
000
164 }
165 35 ▶ if ( $opts{fallback} and not $opts{next} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"fallback"} and not $opts{"next"}) 1 34 35
Condition100%3/3
$opts{"fallback"} and not $opts{"next"}
!ll&&!rl&&r
3311
MC/DC100%2/2
$opts{"fallback"} and not $opts{"next"}
$opts{"fallback"} not $opts{"next"}
Truth table100%3/3
A and not(B)
A= $opts{"fallback"}B= not $opts{"next"}
ABresult
0X0
100
111
166 1 ▶ $opts{next} = ref( $opts{fallback} ) ? $opts{fallback} : sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
ref $opts{'fallback'} ? : 1 0 1
167 }
168 35 ▶ if ( not $opts{next} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"next"}) 1 34 35
169 1 require Error::TypeTiny;
170 1 return Error::TypeTiny::croak( "Function '$function' not found to wrap!" );
171 }
172  
173 34 require Type::Params::Signature;
174 34 my $sig = 'Type::Params::Signature'->new_from_v2api( \%opts );
175 # Delay compilation
176 32 my $compiled;
177 30 ▶ my $coderef = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
Subroutine f: called CC=2 SCAR=7.1
178 30 ▶ $compiled ||= $sig->coderef->compile;
Condition33%2/6
$compiled ||= $sig->coderef->compile
l!l&&r!l&&!r
0300
$compiled ||= $sig->coderef->compile
l!l&&r!l&&!r
010
MC/DC0%0/2
$compiled ||= $sig->coderef->compile
$compiled $sig->coderef->compile
MC/DC0%0/2
$compiled ||= $sig->coderef->compile
$compiled $sig->coderef->compile
Truth table33%1/3
A ||= B
A= $compiledB= $sig->coderef->compile
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $compiledB= $sig->coderef->compile
ABresult
1X1
011
000
179
180 66 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
181 66 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
182 30 *$fullname = set_subname( SIGNATURE_SUBNAME_PREFIX . $fullname . SIGNATURE_SUBNAME_SUFFIX, $compiled );
183
184 30 goto( $compiled );
185 32 };
186  
187 32 our ( %PRE_INSTALL, %POST_INSTALL );
188 32 ▶ if ( my $cb = $PRE_INSTALL{$package} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $Type::Params::PRE_INSTALL{$package}) 1 31 32
189 1 Types::Standard::assert_ArrayRef( $cb );
190 1 $_->( $sig ) for @$cb;
191 }
192  
193 66 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
194 66 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
195 32 *$fullname = set_subname( SIGNATURE_SUBNAME_PREFIX . $fullname . SIGNATURE_SUBNAME_SUFFIX, $coderef );
196  
197 32 ▶ if ( my $cb = $POST_INSTALL{$package} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $Type::Params::POST_INSTALL{$package}) 1 31 32
198 1 Types::Standard::assert_ArrayRef( $cb );
199 1 $_->( $sig ) for @$cb;
200 }
201  
202 32 return $sig;
203 }
204  
205 2 ▶sub signature_for_func {
Subroutine signature_for_func: called CC=2 SCAR=6.9
Pod documented
206 2 ▶ if ( not @_ % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_ % 2) 1 1 2
207 1 require Error::TypeTiny;
208 1 Error::TypeTiny::croak( "Expected odd-sized list of arguments; did you forget the function name?" );
209 }
210 1 my ( $function, %opts ) = @_;
211 1 my $N = !!$opts{named};
212 1 @_ = ( $function, method => 0, allow_dash => $N, list_to_named => $N, %opts );
213 1 goto \&signature_for;
214 }
215  
216 2 ▶sub signature_for_method {
Subroutine signature_for_method: called CC=2 SCAR=6.9
Pod documented
217 2 ▶ if ( not @_ % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_ % 2) 1 1 2
218 1 require Error::TypeTiny;
219 1 Error::TypeTiny::croak( "Expected odd-sized list of arguments; did you forget the function name?" );
220 }
221 1 my ( $function, %opts ) = @_;
222 1 my $N = !!$opts{named};
223 1 @_ = ( $function, method => 1, allow_dash => $N, list_to_named => $N, %opts );
224 1 goto \&signature_for;
225 }
226  
227 83 ▶sub compile {
Subroutine compile: called CC=1 SCAR=0.0
Pod documented
228 83 my @args = @_;
229 83 @_ = ( positional => \@args );
230 83 goto \&signature;
231 }
232  
233 85 ▶sub compile_named {
Subroutine compile_named: called CC=1 SCAR=0.0
Pod documented
234 85 my @args = @_;
235 85 @_ = ( bless => 0, named => \@args );
236 85 goto \&signature;
237 }
238  
239 20 ▶sub compile_named_oo {
Subroutine compile_named_oo: called CC=1 SCAR=0.0
Pod documented
240 20 my @args = @_;
241 20 @_ = ( bless => 1, named => \@args );
242 20 goto \&signature;
243 }
244  
245 # Would be faster to inline this into validate and validate_named, but
246 # that would complicate them. :/
247 933 ▶sub _mk_key {
Subroutine _mk_key: called CC=5 SCAR=16.1
248 933 local $_;
249 join ':', map {
250 933 Types::Standard::is_HashRef( $_ ) ? do {
251 488 my %h = %$_;
252 488 ▶ sprintf( '{%s}', _mk_key( map { ; $_ => $h{$_} } sort keys %h ) );
Branch: 3 branches
BranchTrueFalseTotal
Types::TypeTiny::is_TypeTiny($_) ? : 1465 2670 4135
Types::Standard::is_Ref($_) ? : 122 2548 2670
Types::Standard::is_Undef($_) ? : 0 2548 2548
253 } :
254 4623 ▶ Types::TypeTiny::is_TypeTiny( $_ ) ? sprintf( 'TYPE=%s', $_->{uniq} ) :
Branch: 1 branch
BranchTrueFalseTotal
Types::Standard::is_HashRef($_) ? : 488 4135 4623
255 Types::Standard::is_Ref( $_ ) ? sprintf( 'REF=%s', refaddr( $_ ) ) :
256 Types::Standard::is_Undef( $_ ) ? sprintf( 'UNDEF' ) :
257 B::perlstring( $_ )
258 } @_;
259 } #/ sub _mk_key
260  
261 {
262 66 my %compiled;
263 15 ▶ sub validate {
Subroutine validate: called CC=3 SCAR=11.2
Pod documented
264 15 my $arg = shift;
265 my $sub = (
266 $compiled{ _mk_key( @_ ) } ||= signature(
267 caller_level => 1,
268 15 ▶ %{ ref( $_[0] ) eq 'HASH' ? shift( @_ ) : +{} },
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 9 9
Condition66%2/3
$compiled{_mk_key(@_)} ||= signature("caller_level", 1, %{ref $_[0] eq "HASH" ? shift @_ : {};}, "positional", [@_])
l!l&&r!l&&!r
690
MC/DC0%0/2
$compiled{_mk_key(@_)} ||= signature("caller_level", 1, %{ref $_[0] eq "HASH" ? shift @_ : {};}, "positional", [@_])
$compiled{_mk_key(@_)} signature("caller_level", 1, %{ref $_[0] eq "HASH" ? shift @_ : {};}, "positional", [@_])
Truth table66%2/3
A ||= B
A= $compiled{_mk_key(@_)}B= signature("caller_level", 1, %{ref $_[0] eq "HASH" ? shift @_ : {};}, "positional", [@_])
ABresult
1X1
011
000
269 positional => [ @_ ],
270 )
271 );
272 15 @_ = @$arg;
273 15 goto $sub;
274 } #/ sub validate
275 }
276  
277 {
278 66 my %compiled;
279 430 ▶ sub validate_named {
Subroutine validate_named: called CC=3 SCAR=11.0
Pod documented
280 430 my $arg = shift;
281 my $sub = (
282 $compiled{ _mk_key( @_ ) } ||= signature(
283 caller_level => 1,
284 bless => 0,
285 430 ▶ %{ ref( $_[0] ) eq 'HASH' ? shift( @_ ) : +{} },
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 16 12 28
Condition66%2/3
$compiled{_mk_key(@_)} ||= signature("caller_level", 1, "bless", 0, %{ref $_[0] eq "HASH" ? shift @_ : {};}, "named", [@_])
l!l&&r!l&&!r
402280
MC/DC0%0/2
$compiled{_mk_key(@_)} ||= signature("caller_level", 1, "bless", 0, %{ref $_[0] eq "HASH" ? shift @_ : {};}, "named", [@_])
$compiled{_mk_key(@_)} signature("caller_level", 1, "bless", 0, %{ref $_[0] eq "HASH" ? shift @_ : {};}, "named", [@_])
Truth table66%2/3
A ||= B
A= $compiled{_mk_key(@_)}B= signature("caller_level", 1, "bless", 0, %{ref $_[0] eq "HASH" ? shift @_ : {};}, "named", [@_])
ABresult
1X1
011
000
286 named => [ @_ ],
287 )
288 );
289 430 @_ = @$arg;
290 430 goto $sub;
291 } #/ sub validate_named
292 }
293  
294 66 ▶sub multisig {
Subroutine multisig: called CC=2 SCAR=6.9
Pod documented
295 7 ▶ my %options = ( ref( $_[0] ) eq "HASH" ) ? %{ +shift } : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 3 4 7
296 7 signature(
297 %options,
298 multi => \@_,
299 );
300 } #/ sub multisig
301  
302 2 ▶sub wrap_methods {
Subroutine wrap_methods: called CC=3 SCAR=11.6
Pod documented
303 2 ▶ my $opts = ref( $_[0] ) eq 'HASH' ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 2 2
304 2 ▶ $opts->{caller} ||= caller;
Condition33%1/3
$opts->{"caller"} ||= caller
l!l&&r!l&&!r
020
MC/DC0%0/2
$opts->{"caller"} ||= caller
$opts->{"caller"} caller
Truth table33%1/3
A ||= B
A= $opts->{"caller"}B= caller
ABresult
1X1
011
000
305 2 $opts->{skip_invocant} = 1;
306 2 $opts->{use_can} = 1;
307 2 unshift @_, $opts;
308 2 goto \&_wrap_subs;
309 }
310  
311 1 ▶sub wrap_subs {
Subroutine wrap_subs: called CC=3 SCAR=11.6
Pod documented
312 1 ▶ my $opts = ref( $_[0] ) eq 'HASH' ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 1 1
313 1 ▶ $opts->{caller} ||= caller;
Condition33%1/3
$opts->{"caller"} ||= caller
l!l&&r!l&&!r
010
MC/DC0%0/2
$opts->{"caller"} ||= caller
$opts->{"caller"} caller
Truth table33%1/3
A ||= B
A= $opts->{"caller"}B= caller
ABresult
1X1
011
000
314 1 $opts->{skip_invocant} = 0;
315 1 $opts->{use_can} = 0;
316 1 unshift @_, $opts;
317 1 goto \&_wrap_subs;
318 }
319  
320 3 ▶sub _wrap_subs {
Subroutine _wrap_subs: called CC=9 SCAR=22.0
321 3 my $opts = shift;
322 3 ▶ while ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 8 3 11
323 8 my ( $name, $proto ) = splice @_, 0, 2;
324 8 ▶ my $fullname = ( $name =~ /::/ ) ? $name : sprintf( '%s::%s', $opts->{caller}, $name );
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /::/ ? : 0 8 8
325 8 my $orig = do {
326 66 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
327 exists &$fullname ? \&$fullname
328 2 ▶ : $opts->{use_can} ? ( $opts->{caller}->can( $name ) || sub { } )
Subroutine __ANON__: called CC=1 SCAR=0.0
329 1 ▶ : sub { }
Subroutine __ANON__: called CC=1 SCAR=0.0
330 8 ▶ };
Branch: 2 branches
BranchTrueFalseTotal
exists &$fullname ? : 4 4 8
$opts->{'use_can'} ? : 3 1 4
Condition66%2/3
$opts->{"caller"}->can($name) or sub { }
l!l&&r!l&&!r
210
MC/DC0%0/2
$opts->{"caller"}->can($name) or sub { }
$opts->{"caller"}->can($name) sub { }
Truth table66%2/3
A or B
A= $opts->{"caller"}->can($name)B= sub { }
ABresult
1X1
011
000
331 8 my $new;
332 8 ▶ if ( ref $proto eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $proto eq 'CODE') { } 2 6 8
333 $new = $opts->{skip_invocant}
334 4 ▶ ? sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
335 4 my $s = shift;
336 4 @_ = ( $s, &$proto );
337 2 goto $orig;
338 }
339 2 ▶ : sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
340 2 @_ = &$proto;
341 1 goto $orig;
342 2 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'skip_invocant'} ? : 1 1 2
343 }
344 else {
345 $new = compile(
346 {
347 'package' => $opts->{caller},
348 'subname' => $name,
349 'next' => $orig,
350 6 ▶ 'head' => $opts->{skip_invocant} ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'skip_invocant'} ? : 4 2 6
351 },
352 @$proto,
353 );
354 }
355 66 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
356 66 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
357 8 *$fullname = set_subname( $fullname, $new );
358 } #/ while ( @_ )
359 3 1;
360 } #/ sub _wrap_subs
361  
362 66 1;
363  
364 __END__
« blib/lib/Type/Coercion.pm ↑ Summary blib/lib/Type/Coercion/FromMoose.pm »