line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Function::Interface::Types; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
225418
|
use v5.14.0; |
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.05"; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
|
|
9
|
use Type::Library -base, |
9
|
1
|
|
|
1
|
|
430
|
-declare => qw( ImplOf ); |
|
1
|
|
|
|
|
22416
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
975
|
use Types::Standard -types; |
|
1
|
|
|
|
|
48629
|
|
|
1
|
|
|
|
|
11
|
|
12
|
1
|
|
|
1
|
|
4697
|
use Class::Load qw(is_class_loaded); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
61
|
|
13
|
1
|
|
|
1
|
|
7
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
298
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
__PACKAGE__->add_type({ |
16
|
|
|
|
|
|
|
name => 'ImplOf', |
17
|
|
|
|
|
|
|
parent => ClassName | Object, |
18
|
|
|
|
|
|
|
constraint_generator => sub { |
19
|
|
|
|
|
|
|
my $self = $Type::Tiny::parameterize_type; |
20
|
|
|
|
|
|
|
my @interfaces = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $display_name = $self->name_generator->($self, @interfaces); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my %options = ( |
25
|
|
|
|
|
|
|
constraint => sub { |
26
|
|
|
|
|
|
|
my ($package) = @_; |
27
|
|
|
|
|
|
|
for (@interfaces) { |
28
|
|
|
|
|
|
|
return unless Function::Interface::Impl::impl_of($package, $_); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
return !!1; |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
display_name => $display_name, |
33
|
|
|
|
|
|
|
parameters => [@interfaces], |
34
|
|
|
|
|
|
|
message => sub { |
35
|
|
|
|
|
|
|
my $package = ref $_ ? blessed($_) : $_; |
36
|
|
|
|
|
|
|
return "$package is not loaded" if !is_class_loaded($package); |
37
|
|
|
|
|
|
|
return sprintf '%s did not pass type constraint "%s"', Type::Tiny::_dd($_), $display_name; |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return $self->create_child_type(%options); |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
}); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |