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