line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Function::Interface::Types; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
231988
|
use v5.14.0; |
|
1
|
|
|
|
|
9
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.06"; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
|
|
10
|
use Type::Library -base, |
9
|
1
|
|
|
1
|
|
424
|
-declare => qw( ImplOf ); |
|
1
|
|
|
|
|
22447
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
978
|
use Types::Standard -types; |
|
1
|
|
|
|
|
48876
|
|
|
1
|
|
|
|
|
10
|
|
12
|
1
|
|
|
1
|
|
4717
|
use Class::Load qw(is_class_loaded); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
89
|
|
13
|
1
|
|
|
1
|
|
7
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
290
|
|
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__ |