File Coverage

blib/lib/Types/Sub.pm
Criterion Covered Total %
statement 38 38 100.0
branch 4 4 100.0
condition n/a
subroutine 13 13 100.0
pod n/a
total 55 55 100.0


line stmt bran cond sub pod time code
1             package Types::Sub;
2 2     2   225196 use 5.010;
  2         14  
3 2     2   10 use strict;
  2         4  
  2         38  
4 2     2   13 use warnings;
  2         2  
  2         87  
5              
6             our $VERSION = "0.14";
7              
8 2     2   484 use Sub::Meta;
  2         6  
  2         58  
9 2     2   447 use Sub::Meta::Type;
  2         6  
  2         66  
10 2     2   501 use Sub::Meta::TypeSub;
  2         5  
  2         51  
11 2     2   381 use Sub::Meta::CreatorFunction;
  2         6  
  2         76  
12              
13 2     2   13 use Types::Standard qw(Ref);
  2         4  
  2         15  
14             use Type::Library
15 2         20 -base,
16             -declare => qw(
17             Sub
18             StrictSub
19             SubMeta
20             StrictSubMeta
21 2     2   1271 );
  2         5  
22              
23             __PACKAGE__->meta->add_type(
24             name => 'Sub',
25             constraint_generator => _gen_sub_constraint_generator(strict => 0),
26             );
27              
28             __PACKAGE__->meta->add_type(
29             name => 'StrictSub',
30             constraint_generator => _gen_sub_constraint_generator(strict => 1),
31             );
32              
33             __PACKAGE__->meta->add_type(
34             name => 'SubMeta',
35             constraint_generator => _gen_submeta_constraint_generator(strict => 0),
36             );
37              
38             __PACKAGE__->meta->add_type(
39             name => 'StrictSubMeta',
40             constraint_generator => _gen_submeta_constraint_generator(strict => 1),
41             );
42              
43             sub _gen_sub_constraint_generator {
44 4     4   60 my (%options) = @_;
45 4         8 my $strict = $options{strict};
46              
47 4         20 my $CodeRef = Ref['CODE'];
48              
49             return sub {
50 5 100   5   19848 return $CodeRef unless @_;
51              
52 3 100       28 my $SubMeta = $strict ? StrictSubMeta[@_] : SubMeta[@_];
53              
54 3         2560 return Sub::Meta::TypeSub->new(
55             parent => $CodeRef,
56             submeta_type => $SubMeta
57             )
58             }
59 4         613 }
60              
61             sub _gen_submeta_constraint_generator {
62 4     4   66 my (%options) = @_;
63 4         9 my $strict = $options{strict};
64              
65             return sub {
66 8     8   11419 my $submeta = Sub::Meta->new(@_);
67              
68 4         64 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         25 }
75              
76              
77             1;
78             __END__