| 1 | # INTERNAL MODULE: guts for ScalarRef type from Types::Standard. | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Types::Standard::ScalarRef; | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | $Types::Standard::ScalarRef::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | $Types::Standard::ScalarRef::VERSION = '2.010001'; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | $Types::Standard::ScalarRef::VERSION =~ tr/_//d; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | use Types::Standard (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | ▶ | use Types::TypeTiny (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_croak: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 8 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 8 | ▶ | use Exporter::Tiny 1.004001 (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | our @ISA = qw( Exporter::Tiny ); | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | sub _exporter_fail { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exporter_fail: called CC=10 SCAR=24.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | my ( $class, $type_name, $values, $globals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | my $caller = $globals->{into}; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | my $of = exists( $values->{of} ) ? $values->{of} : $values->{type}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | defined $of or _croak( qq{Expected option "of" for type "$type_name"} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | if ( not Types::TypeTiny::is_TypeTiny($of) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | require Type::Utils; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | $of = Type::Utils::dwim_type( $of, for => $caller ); | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | my $type = Types::Standard::ScalarRef->of( $of ); | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | $type = $type->create_child_type( | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | name => $type_name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | $type->has_coercion ? ( coercion => 1 ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | exists( $values->{where} ) ? ( constraint => $values->{where} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | $INC{'Type/Registry.pm'} | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ? 'Type::Registry'->for_class( $caller )->add_type( $type, $type_name ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | : ( $Type::Registry::DELAYED{$caller}{$type_name} = $type ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | ▶ | unless( ref($caller) or $caller eq '-lexical' or $globals->{'lexical'} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
ref $caller or $caller eq "-lexical" or $globals->{"lexical"}
ref $caller or $caller eq "-lexical"
MC/DC0%0/3
ref $caller or $caller eq "-lexical" or $globals->{"lexical"}
ref $caller
$caller eq "-lexical"
$globals->{"lexical"}
Truth table25%1/4
A or B or C
A= ref $callerB= $caller eq "-lexical"C= $globals->{"lexical"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | return map +( $_->{name} => $_->{code} ), @{ $type->exportables }; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 16 | ▶ | sub __constraint_generator { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__constraint_generator: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 16 | ▶ | return Types::Standard::ScalarRef unless @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 15 | Type::Tiny::check_parameter_count_for_parameterized_type( 'Types::Standard', 'ScalarRef', \@_, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 15 | my $param = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 15 | ▶ | Types::TypeTiny::is_TypeTiny( $param ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | or _croak( | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | "Parameter to ScalarRef[`a] expected to be a type constraint; got $param" ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 19 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 19 | my $ref = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 19 | ▶ | $param->check( $$ref ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 10 | return !!1; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | } #/ sub __constraint_generator | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 13 | ▶ | sub __inline_generator { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__inline_generator: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 13 | my $param = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 13 | ▶ | return unless $param->can_be_inlined; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 76 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 76 | my $v = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | 76 | my $param_check = $param->inline_check( "\${$v}" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 76 | "(ref($v) eq 'SCALAR' or ref($v) eq 'REF') and $param_check"; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | ▶ | sub __deep_explanation { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__deep_explanation: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | my ( $type, $value, $varname ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | my $param = $type->parameters->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | for my $item ( $$value ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | next if $param->check( $item ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | '"%s" constrains the referenced scalar value with "%s"', $type, $param | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | @{ $param->validate_explain( $item, sprintf( '${%s}', $varname ) ) }, | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # This should never happen... | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | return; # uncoverable statement | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | } #/ sub __deep_explanation | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 8 | ▶ | sub __coercion_generator { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__coercion_generator: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 8 | my ( $parent, $child, $param ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 8 | ▶ | return unless $param->has_coercion; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | my $coercable_item = $param->coercion->_source_type_union; | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | my $C = "Type::Coercion"->new( type_constraint => $child ); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 4 | ▶ | if ( $param->coercion->can_be_inlined and $coercable_item->can_be_inlined ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$param->coercion->can_be_inlined and $coercable_item->can_be_inlined
MC/DC50%1/2
$param->coercion->can_be_inlined and $coercable_item->can_be_inlined
$param->coercion->can_be_inlined
$coercable_item->can_be_inlined
Truth table66%2/3
A and B
A= $param->coercion->can_be_inlinedB= $coercable_item->can_be_inlined
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | $C->add_type_coercions( | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | ▶ | $parent => Types::Standard::Stringable { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | my @code; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | push @code, 'do { my ($orig, $return_orig, $new) = ($_, 0);'; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 3 | push @code, 'for ($$orig) {'; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | push @code, | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | '++$return_orig && last unless (%s);', | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | $coercable_item->inline_check( '$_' ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | push @code, | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | '$new = (%s);', | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | $param->coercion->inline_coercion( '$_' ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | push @code, '}'; | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | push @code, '$return_orig ? $orig : \\$new'; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | push @code, '}'; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | "@code"; | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | } #/ if ( $param->coercion->...) | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | $C->add_type_coercions( | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | $parent => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | ▶ | my $value = @_ ? $_[0] : $_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | my $new; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | for my $item ( $$value ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | 2 | ▶ | return $value unless $coercable_item->check( $item ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | $new = $param->coerce( $item ); | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | return \$new; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | } #/ else [ if ( $param->coercion->...)] | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | return $C; | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | } #/ sub __coercion_generator | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||