| 1 | package Types::Sub; | ||||||||||
| 2 | 2 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | our $VERSION = "0.15"; | |||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use Sub::Meta; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use Sub::Meta::Type; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Sub::Meta::TypeSub; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use Sub::Meta::CreatorFunction; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 2 | ▶ | use Types::Standard qw(Ref); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | use Type::Library | ||||||||||
| 15 | 2 | ▶ | -base, | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | -declare => qw( | ||||||||||
| 17 | Sub | ||||||||||
| 18 | StrictSub | ||||||||||
| 19 | SubMeta | ||||||||||
| 20 | StrictSubMeta | ||||||||||
| 21 | 2 | ); | |||||||||
| 22 | |||||||||||
| 23 | 2 | __PACKAGE__->meta->add_type( | |||||||||
| 24 | name => 'Sub', | ||||||||||
| 25 | constraint_generator => _gen_sub_constraint_generator(strict => 0), | ||||||||||
| 26 | ); | ||||||||||
| 27 | |||||||||||
| 28 | 2 | __PACKAGE__->meta->add_type( | |||||||||
| 29 | name => 'StrictSub', | ||||||||||
| 30 | constraint_generator => _gen_sub_constraint_generator(strict => 1), | ||||||||||
| 31 | ); | ||||||||||
| 32 | |||||||||||
| 33 | 2 | __PACKAGE__->meta->add_type( | |||||||||
| 34 | name => 'SubMeta', | ||||||||||
| 35 | constraint_generator => _gen_submeta_constraint_generator(strict => 0), | ||||||||||
| 36 | ); | ||||||||||
| 37 | |||||||||||
| 38 | 2 | __PACKAGE__->meta->add_type( | |||||||||
| 39 | name => 'StrictSubMeta', | ||||||||||
| 40 | constraint_generator => _gen_submeta_constraint_generator(strict => 1), | ||||||||||
| 41 | ); | ||||||||||
| 42 | |||||||||||
| 43 | 4 | ▶ | sub _gen_sub_constraint_generator { | ||||||||
|
Subroutine
_gen_sub_constraint_generator: called CC=1 SCAR=0.0
| |||||||||||
| 44 | 4 | my (%options) = @_; | |||||||||
| 45 | 4 | my $strict = $options{strict}; | |||||||||
| 46 | |||||||||||
| 47 | 4 | my $CodeRef = Ref['CODE']; | |||||||||
| 48 | |||||||||||
| 49 | 5 | ▶ | return sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 50 | 5 | ▶ | return $CodeRef unless @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | 3 | ▶ | my $SubMeta = $strict ? StrictSubMeta[@_] : SubMeta[@_]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | |||||||||||
| 54 | 3 | return Sub::Meta::TypeSub->new( | |||||||||
| 55 | parent => $CodeRef, | ||||||||||
| 56 | submeta_type => $SubMeta | ||||||||||
| 57 | ) | ||||||||||
| 58 | } | ||||||||||
| 59 | 4 | } | |||||||||
| 60 | |||||||||||
| 61 | 4 | ▶ | sub _gen_submeta_constraint_generator { | ||||||||
|
Subroutine
_gen_submeta_constraint_generator: called CC=1 SCAR=0.0
| |||||||||||
| 62 | 4 | my (%options) = @_; | |||||||||
| 63 | 4 | my $strict = $options{strict}; | |||||||||
| 64 | |||||||||||
| 65 | 8 | ▶ | return sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 66 | 8 | my $submeta = Sub::Meta->new(@_); | |||||||||
| 67 | |||||||||||
| 68 | 4 | return Sub::Meta::Type->new( | |||||||||
| 69 | submeta => $submeta, | ||||||||||
| 70 | submeta_strict_check => $strict, | ||||||||||
| 71 | find_submeta => \&Sub::Meta::CreatorFunction::find_submeta, | ||||||||||
| 72 | ); | ||||||||||
| 73 | } | ||||||||||
| 74 | 4 | } | |||||||||
| 75 | |||||||||||
| 76 | |||||||||||
| 77 | 2 | 1; | |||||||||
| 78 | __END__ | ||||||||||