| 1 | package Type::Coercion::Union; | ||||||||||
| 2 | |||||||||||
| 3 | 22 | ▶ | use 5.008001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 22 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 22 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 22 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 22 | $Type::Coercion::Union::AUTHORITY = 'cpan:TOBYINK'; | |||||||||
| 9 | 22 | $Type::Coercion::Union::VERSION = '2.010001'; | |||||||||
| 10 | } | ||||||||||
| 11 | |||||||||||
| 12 | 22 | $Type::Coercion::Union::VERSION =~ tr/_//d; | |||||||||
| 13 | |||||||||||
| 14 | 22 | ▶ | use Scalar::Util qw< blessed >; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 22 | ▶ | use Types::TypeTiny (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 1 | ▶ | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||||||
|
Subroutine
_croak: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 22 | require Type::Coercion; | |||||||||
| 20 | 22 | our @ISA = 'Type::Coercion'; | |||||||||
| 21 | |||||||||||
| 22 | 65 | ▶ | sub _preserve_type_constraint { | ||||||||
|
Subroutine
_preserve_type_constraint: called CC=2 SCAR=7.2
| |||||||||||
| 23 | 65 | my $self = shift; | |||||||||
| 24 | $self->{_union_of} = $self->{type_constraint}->type_constraints | ||||||||||
| 25 | 65 | ▶ | if $self->{type_constraint}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 1 | ▶ | sub _maybe_restore_type_constraint { | ||||||||
|
Subroutine
_maybe_restore_type_constraint: called CC=2 SCAR=7.0
| |||||||||||
| 29 | 1 | my $self = shift; | |||||||||
| 30 | 1 | ▶ | if ( my $union = $self->{_union_of} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 1 | return Type::Tiny::Union->new( type_constraints => $union ); | |||||||||
| 32 | } | ||||||||||
| 33 | 0 | return; # uncoverable statement | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 17 | ▶ | sub type_coercion_map { | ||||||||
|
Subroutine
type_coercion_map: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 37 | 17 | my $self = shift; | |||||||||
| 38 | |||||||||||
| 39 | 17 | Types::TypeTiny::assert_TypeTiny( my $type = $self->type_constraint ); | |||||||||
| 40 | 17 | ▶ | $type->isa( 'Type::Tiny::Union' ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | or _croak | ||||||||||
| 42 | "Type::Coercion::Union must be used in conjunction with Type::Tiny::Union"; | ||||||||||
| 43 | |||||||||||
| 44 | 17 | my @c; | |||||||||
| 45 | 17 | for my $tc ( @$type ) { | |||||||||
| 46 | 34 | ▶ | next unless $tc->has_coercion; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 32 | push @c, @{ $tc->coercion->type_coercion_map }; | |||||||||
| 48 | } | ||||||||||
| 49 | 17 | return \@c; | |||||||||
| 50 | } #/ sub type_coercion_map | ||||||||||
| 51 | |||||||||||
| 52 | 1 | ▶ | sub add_type_coercions { | ||||||||
|
Subroutine
add_type_coercions: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 53 | 1 | my $self = shift; | |||||||||
| 54 | 1 | ▶ | _croak "Adding coercions to Type::Coercion::Union not currently supported" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | if @_; | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 0 | ▶ | sub _build_moose_coercion { | ||||||||
|
Subroutine
_build_moose_coercion: not called CC=2 SCAR=17.9
| |||||||||||
| 59 | 0 | my $self = shift; | |||||||||
| 60 | |||||||||||
| 61 | 0 | my %options = (); | |||||||||
| 62 | 0 | ▶ | $options{type_constraint} = $self->type_constraint | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | if $self->has_type_constraint; | ||||||||||
| 64 | |||||||||||
| 65 | 0 | require Moose::Meta::TypeCoercion::Union; | |||||||||
| 66 | 0 | my $r = "Moose::Meta::TypeCoercion::Union"->new( %options ); | |||||||||
| 67 | |||||||||||
| 68 | 0 | return $r; | |||||||||
| 69 | } #/ sub _build_moose_coercion | ||||||||||
| 70 | |||||||||||
| 71 | 3 | ▶ | sub can_be_inlined { | ||||||||
|
Subroutine
can_be_inlined: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||
| 72 | 3 | my $self = shift; | |||||||||
| 73 | |||||||||||
| 74 | 3 | Types::TypeTiny::assert_TypeTiny( my $type = $self->type_constraint ); | |||||||||
| 75 | |||||||||||
| 76 | 3 | for my $tc ( @$type ) { | |||||||||
| 77 | 6 | ▶ | next unless $tc->has_coercion; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 6 | ▶ | return !!0 unless $tc->coercion->can_be_inlined; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 3 | !!1; | |||||||||
| 82 | } #/ sub can_be_inlined | ||||||||||
| 83 | |||||||||||
| 84 | 22 | 1; | |||||||||
| 85 | |||||||||||
| 86 | __END__ | ||||||||||