| 1 | package Type::Library; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 278 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 278 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 278 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 278 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 278 | $Type::Library::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 278 | $Type::Library::VERSION = '2.010001'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 278 | $Type::Library::VERSION =~ tr/_//d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 278 | ▶ | use Eval::TypeTiny qw< eval_closure set_subname type_to_coderef NICE_PROTOTYPES >; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 278 | ▶ | use Scalar::Util qw< blessed refaddr >; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 278 | ▶ | use Type::Tiny (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 278 | ▶ | use Types::TypeTiny (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 278 | require Exporter::Tiny; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 278 | our @ISA = 'Exporter::Tiny'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 8 | ▶ | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_croak: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | #### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | #### Hooks for Exporter::Tiny | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | #### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # Handling for -base, -extends, and -utils tags. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1190 | ▶ | sub _exporter_validate_opts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exporter_validate_opts: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1190 | my ( $class, $opts ) = ( shift, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 443 | $class->setup_type_library( @{$opts}{qw/ into utils extends /}, $opts ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1190 | ▶ | if $_[0]{base} || $_[0]{extends}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_[0]{"base"} or $_[0]{"extends"}
MC/DC100%2/2
$_[0]{"base"} or $_[0]{"extends"}
$_[0]{"base"}
$_[0]{"extends"}
Truth table100%3/3
A or B
A= $_[0]{"base"}B= $_[0]{"extends"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1190 | return $class->SUPER::_exporter_validate_opts( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # In Exporter::Tiny, this method takes a sub name, a 'value' (i.e. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # potentially an options hashref for the export), and some global | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # options, and returns a list of name+coderef pairs to actually | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # export. We override it to provide some useful features. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 21130 | ▶ | sub _exporter_expand_sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exporter_expand_sub: called CC=17 SCAR=28.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 21130 | my ( $class, $name, $value, $globals ) = ( shift, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # Handle exporting '+Type'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # Note that this recurses, so if used in conjunction with the other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # special cases handled by this method, will still work. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 21130 | ▶ | if ( $name =~ /^\+(.+)/ and $class->has_type( "$1" ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$name =~ /^\+(.+)/ and $class->has_type("$1")
MC/DC50%1/2
$name =~ /^\+(.+)/ and $class->has_type("$1")
$name =~ /^\+(.+)/
$class->has_type("$1")
Truth table66%2/3
A and B
A= $name =~ /^\+(.+)/B= $class->has_type("$1")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 13 | my $type = $class->get_type( "$1" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 13 | my $exported = $type->exportables; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | return map $class->_exporter_expand_sub( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | $_->{name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 13 | ▶ | +{ %{ $value || {} } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$value || {}
MC/DC0%0/1
$value || {}
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | $globals, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ), @$exported; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # Is the function being exported one which is associated with a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # type constraint? If so, which one. If not, then forget the rest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # and just use the superclass method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 21117 | ▶ | if ( my $f = $class->meta->{'functions'}{$name} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
my $f = $class->meta->{"functions"}{$name} and defined $class->meta->{"functions"}{$name}{"type"}
MC/DC100%2/2
my $f = $class->meta->{"functions"}{$name} and defined $class->meta->{"functions"}{$name}{"type"}
my $f = $class->meta->{"functions"}{$name}
defined $class->meta->{"functions"}{$name}{"type"}
Truth table100%3/3
A and B
A= my $f = $class->meta->{"functions"}{$name}B= defined $class->meta->{"functions"}{$name}{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | and defined $class->meta->{'functions'}{$name}{'type'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 19928 | my $type = $f->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 19928 | my $tag = $f->{tags}[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 19928 | my $typename = $type->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # If $value has `of` or `where` options, then this is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # custom type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 19928 | my $custom_type = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 19928 | for my $param ( qw/ of where / ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 39856 | ▶ | exists $value->{$param} or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | ▶ | defined $value->{-as} or _croak( "Parameter '-as' not supplied" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | $type = $type->$param( $value->{$param} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | $name = $value->{-as}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | ++$custom_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # If we're exporting a type itself, then export a custom | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # function if they customized the type or want a Moose/Mouse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # type constraint. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 19928 | ▶ | if ( $tag eq 'types' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 10076 | my $post_method = q(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 10076 | ▶ | $post_method = '->mouse_type' if $globals->{mouse}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 10076 | ▶ | $post_method = '->moose_type' if $globals->{moose}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 10076 | ▶ | return ( $name => type_to_coderef( $type, post_method => $post_method ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$post_method or $custom_type
MC/DC50%1/2
$post_method or $custom_type
$post_method
$custom_type
Truth table66%2/3
A or B
A= $post_methodB= $custom_type
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | if $post_method || $custom_type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # If they're exporting some other type of function, like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # 'to', 'is', or 'assert', then find the correct exportable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # by tag name, and return that. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # XXX: this will fail for tags like 'constants' where there | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # will be multiple exportables which match! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 19926 | ▶ | if ( $custom_type and $tag ne 'types' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$custom_type and $tag ne "types"
MC/DC50%1/2
$custom_type and $tag ne "types"
$custom_type
$tag ne "types"
Truth table66%2/3
A and B
A= $custom_typeB= $tag ne "types"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | my $exportable = $type->exportables_by_tag( $tag, $typename ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | ▶ | return ( $value->{-as} || $exportable->{name}, $exportable->{code} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$value->{'-as'} || $exportable->{'name'}
MC/DC0%0/2
$value->{'-as'} || $exportable->{'name'}
$value->{'-as'}
$exportable->{'name'}
Truth table33%1/3
A || B
A= $value->{'-as'}B= $exportable->{'name'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # In all other cases, the superclass method will work. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 21114 | return $class->SUPER::_exporter_expand_sub( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # Mostly just rely on superclass to do the actual export, but add | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # a couple of useful behaviours. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 21115 | ▶ | sub _exporter_install_sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exporter_install_sub: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 21115 | my ( $class, $name, $value, $globals, $sym ) = ( shift, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 21115 | my $into = $globals->{into}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 21115 | my $type = $class->meta->{'functions'}{$name}{'type'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 21115 | my $tags = $class->meta->{'functions'}{$name}{'tags'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # Issue a warning if exporting a deprecated type constraint. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | Exporter::Tiny::_carp( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | "Exporting deprecated type %s to %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | $type->qualified_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ref( $into ) ? "reference" : "package $into", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 21115 | ▶ | ) if ( defined $type and $type->deprecated and not $globals->{allow_deprecated} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
defined $type and $type->deprecated and not $globals->{"allow_deprecated"}
defined $type and $type->deprecated
MC/DC100%3/3
defined $type and $type->deprecated and not $globals->{"allow_deprecated"}
defined $type
$type->deprecated
not $globals->{"allow_deprecated"}
Truth table100%4/4
A and B and not(C)
A= defined $typeB= $type->deprecatedC= not $globals->{"allow_deprecated"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # If exporting a type constraint into a real package, then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # add it to the package's type registry. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 21115 | ▶ | if ( !ref $into | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
not ref $into and $into ne "-lexical" and defined $type and grep(($_ eq "types"), @$tags)
not ref $into and $into ne "-lexical" and defined $type
not ref $into and $into ne "-lexical"
MC/DC75%3/4
not ref $into and $into ne "-lexical" and defined $type and grep(($_ eq "types"), @$tags)
not ref $into
$into ne "-lexical"
defined $type
grep(($_ eq "types"), @$tags)
Truth table80%4/5
not(A) and B and C and D
A= not ref $intoB= $into ne "-lexical"C= defined $typeD= grep(($_ eq "types"), @$tags)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | and $into ne '-lexical' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | and defined $type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | and grep $_ eq 'types', @$tags ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # If they're renaming it, figure out what name, and use that. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # XXX: `-as` can be a coderef, and can be in $globals in that case. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 9374 | my ( $prefix ) = grep defined, $value->{-prefix}, $globals->{prefix}, q(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 9374 | my ( $suffix ) = grep defined, $value->{-suffix}, $globals->{suffix}, q(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 9374 | ▶ | my $as = $prefix . ( $value->{-as} || $name ) . $suffix; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$value->{'-as'} || $name
MC/DC0%0/2
$value->{'-as'} || $name
$value->{'-as'}
$name
Truth table66%2/3
A || B
A= $value->{'-as'}B= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | $INC{'Type/Registry.pm'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ? 'Type::Registry'->for_class( $into )->add_type( $type, $as ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 9374 | ▶ | : ( $Type::Registry::DELAYED{$into}{$as} = $type ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 21115 | $class->SUPER::_exporter_install_sub( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } #/ sub _exporter_install_sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1041 | ▶ | sub _exporter_fail { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exporter_fail: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1041 | my ( $class, $name, $value, $globals ) = ( shift, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # Passing the `-declare` flag means that if a type isn't found, then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # we export a placeholder function instead of failing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1041 | ▶ | if ( $globals->{declare} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | type_to_coderef( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | type_name => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1039 | ▶ | type_library => $globals->{into} || _croak( "Parameter 'into' not supplied" ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$globals->{'into'} || &_croak(q[Parameter 'into' not supplied])
MC/DC0%0/2
$globals->{'into'} || &_croak(q[Parameter 'into' not supplied])
$globals->{'into'}
&_croak(q[Parameter 'into' not supplied])
Truth table33%1/3
A || B
A= $globals->{'into'}B= &_croak(q[Parameter 'into' not supplied])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } #/ if ( $globals->{declare...}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | return $class->SUPER::_exporter_fail( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } #/ sub _exporter_fail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | #### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | #### Type library functionality | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | #### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 443 | ▶ | sub setup_type_library { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup_type_library: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 443 | my ( $class, $type_library, $install_utils, $extends, $opts ) = ( shift, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 443 | ▶ | my @extends = ref( $extends ) ? @$extends : $extends ? $extends : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 443 | ▶ | unshift @extends, $class if $class ne __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 443 | ▶ | if ( not ref $type_library ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 278 | ▶ | no strict "refs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 443 | push @{"$type_library\::ISA"}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 443 | ( my $file = $type_library ) =~ s{::}{/}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 443 | ▶ | $INC{"$file.pm"} ||= __FILE__; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$INC{"$file.pm"} ||= __FILE__
MC/DC100%1/1
$INC{"$file.pm"} ||= __FILE__
$INC{"$file.pm"}
Truth table100%2/2
A
A= $INC{"$file.pm"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 443 | ▶ | if ( $install_utils ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 4 | require Type::Utils; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 4 | 'Type::Utils'->import( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | { %$opts, into => $type_library }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | '-default', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 443 | ▶ | if ( @extends and not ref $type_library ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@extends and not ref $type_library
MC/DC50%1/2
@extends and not ref $type_library
@extends
not ref $type_library
Truth table66%2/3
A and not(B)
A= @extendsB= not ref $type_library
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 28 | require Type::Utils; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 28 | my $wrapper = eval "sub { package $type_library; &Type::Utils::extends; }"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 28 | $wrapper->( @extends ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 134198 | ▶ | sub meta { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
meta: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 278 | ▶ | no strict "refs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 278 | ▶ | no warnings "once"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 134198 | ▶ | return $_[0] if blessed $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 88229 | ▶ | ${"$_[0]\::META"} ||= bless {}, $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
${"$_[0]::META";} ||= bless({}, $_[0])
MC/DC100%1/1
${"$_[0]::META";} ||= bless({}, $_[0])
${"$_[0]::META";}
Truth table100%2/2
A
A= ${"$_[0]::META";}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 13817 | ▶ | sub add_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_type: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 13817 | my $meta = shift->meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 13817 | my $class = blessed( $meta ) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 13817 | ▶ | _croak( 'Type library is immutable' ) if $meta->{immutable}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | my $type = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | ref( $_[0] ) =~ /^Type::Tiny\b/ ? $_[0] : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | blessed( $_[0] ) ? Types::TypeTiny::to_TypeTiny( $_[0] ) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 13813 | ▶ | ref( $_[0] ) eq q(HASH) ? 'Type::Tiny'->new( library => $class, %{ $_[0] } ) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | "Type::Tiny"->new( library => $class, @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 13813 | my $name = $type->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 13813 | ▶ | if ( $meta->has_type( $name ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | my $existing = $meta->get_type( $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | ▶ | return if $type->{uniq} == $existing->{uniq}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | _croak( 'Type %s already exists in this library', $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 13812 | ▶ | _croak( 'Type %s conflicts with coercion of same name', $name ) if $meta->has_coercion( $name ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 13812 | ▶ | _croak( 'Cannot add anonymous type to a library' ) if $type->is_anon; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 13811 | ▶ | $meta->{types} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$meta->{"types"} ||= {}
MC/DC0%0/1
$meta->{"types"} ||= {}
$meta->{"types"}
Truth table50%1/2
A
A= $meta->{"types"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 13811 | $meta->{types}{$name} = $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 278 | ▶ | no strict "refs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 278 | ▶ | no warnings "redefine", "prototype"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 13811 | for my $exportable ( @{ $type->exportables } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 55253 | my $name = $exportable->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 55253 | my $code = $exportable->{code}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 55253 | my $tags = $exportable->{tags}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | _croak( 'Function %s is provided by types %s and %s', $name, $meta->{'functions'}{$name}{'type'}->name, $type->name ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 55253 | ▶ | if $meta->{'functions'}{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 55252 | *{"$class\::$name"} = set_subname( "$class\::$name", $code ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 55252 | push @{"$class\::EXPORT_OK"}, $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 55252 | ▶ | push @{ ${"$class\::EXPORT_TAGS"}{$_} ||= [] }, $name for @$tags; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
do {
"${class}::EXPORT_TAGS"
}->{$_} ||= []
MC/DC100%1/1
do {
"${class}::EXPORT_TAGS"
}->{$_} ||= []
do {
"${class}::EXPORT_TAGS"
}->{$_}
Truth table100%2/2
A
A= do {
"${class}::EXPORT_TAGS"
}->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 55252 | $meta->{'functions'}{$name} = { type => $type, tags => $tags }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | $INC{'Type/Registry.pm'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | ? 'Type::Registry'->for_class( $class )->add_type( $type, $name ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 13810 | ▶ | : ( $Type::Registry::DELAYED{$class}{$name} = $type ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 13810 | return $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } #/ sub add_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # For Type::TinyX::Facets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # Only use this if you know what you're doing! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | sub _remove_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_type: not called CC=6 SCAR=33.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | my $meta = shift->meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | my $type = $meta->get_type( $_[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $class = ref $meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | _croak( 'Type library is immutable' ) if $meta->{immutable}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | delete $meta->{types}{$type->name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 278 | ▶ | no strict "refs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 278 | ▶ | no warnings "redefine", "prototype"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my @clean; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | my $_scrub = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my ( $arr, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | @$arr = grep $_ ne $name, @$arr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | for my $exportable ( @{ $type->exportables } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my $name = $exportable->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | push @clean, $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | &$_scrub( \@{"$class\::EXPORT_OK"}, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | for my $t ( @{ $exportable->{tags} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | &$_scrub( ${"$class\::EXPORT_TAGS"}{$t} ||= [], $name ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
do {
"${class}::EXPORT_TAGS"
}->{$t} ||= []
MC/DC0%0/1
do {
"${class}::EXPORT_TAGS"
}->{$t} ||= []
do {
"${class}::EXPORT_TAGS"
}->{$t}
Truth table0%0/2
A
A= do {
"${class}::EXPORT_TAGS"
}->{$t}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | delete $meta->{'functions'}{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | require namespace::clean; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | 'namespace::clean'->clean_subroutines( $class, @clean ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | delete 'Type::Registry'->for_class( $class )->{$type->name} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | if $INC{'Type/Registry.pm'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | delete $Type::Registry::DELAYED{$class}{$type->name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | return $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } #/ sub _remove_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 4202 | ▶ | sub get_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 4202 | my $meta = shift->meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 4202 | $meta->{types}{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 14889 | ▶ | sub has_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 14889 | my $meta = shift->meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 14889 | exists $meta->{types}{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 114 | ▶ | sub type_names { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 114 | my $meta = shift->meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 114 | keys %{ $meta->{types} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 989 | ▶ | sub add_coercion { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_coercion: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 989 | my $meta = shift->meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 989 | my $class = blessed( $meta ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 989 | ▶ | _croak( 'Type library is immutable' ) if $meta->{immutable}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 989 | require Type::Coercion; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 989 | ▶ | my $c = blessed( $_[0] ) ? $_[0] : "Type::Coercion"->new( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 989 | my $name = $c->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 989 | ▶ | _croak( 'Coercion %s already exists in this library', $name ) if $meta->has_coercion( $name ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 989 | ▶ | _croak( 'Coercion %s conflicts with type of same name', $name ) if $meta->has_type( $name ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 988 | ▶ | _croak( 'Cannot add anonymous type to a library' ) if $c->is_anon; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 988 | ▶ | $meta->{coercions} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$meta->{"coercions"} ||= {}
MC/DC0%0/1
$meta->{"coercions"} ||= {}
$meta->{"coercions"}
Truth table50%1/2
A
A= $meta->{"coercions"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 988 | $meta->{coercions}{$name} = $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 278 | ▶ | no strict "refs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 278 | ▶ | no warnings "redefine", "prototype"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 988 | *{"$class\::$name"} = type_to_coderef( $c ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 988 | push @{"$class\::EXPORT_OK"}, $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 988 | ▶ | push @{ ${"$class\::EXPORT_TAGS"}{'coercions'} ||= [] }, $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
do {
"${class}::EXPORT_TAGS"
}->{"coercions"} ||= []
MC/DC100%1/1
do {
"${class}::EXPORT_TAGS"
}->{"coercions"} ||= []
do {
"${class}::EXPORT_TAGS"
}->{"coercions"}
Truth table100%2/2
A
A= do {
"${class}::EXPORT_TAGS"
}->{"coercions"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 988 | $meta->{'functions'}{$name} = { coercion => $c, tags => [ 'coercions' ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 988 | return $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } #/ sub add_coercion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 135 | ▶ | sub get_coercion { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_coercion: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 135 | my $meta = shift->meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 135 | $meta->{coercions}{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 14801 | ▶ | sub has_coercion { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_coercion: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 14801 | my $meta = shift->meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 14801 | exists $meta->{coercions}{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 114 | ▶ | sub coercion_names { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
coercion_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 114 | my $meta = shift->meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 114 | keys %{ $meta->{coercions} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 390 | ▶ | sub make_immutable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_immutable: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 390 | my $meta = shift->meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 390 | my $class = ref( $meta ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 278 | ▶ | no strict "refs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 278 | ▶ | no warnings "redefine", "prototype"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 390 | for my $type ( values %{ $meta->{types} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 12875 | $type->coercion->freeze; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 12875 | ▶ | next unless $type->has_coercion && $type->coercion->frozen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type->has_coercion and $type->coercion->frozen
MC/DC50%1/2
$type->has_coercion and $type->coercion->frozen
$type->has_coercion
$type->coercion->frozen
Truth table66%2/3
A and B
A= $type->has_coercionB= $type->coercion->frozen
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 735 | for my $e ( $type->exportables_by_tag( 'to' ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 735 | my $qualified_name = $class . '::' . $e->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 735 | *$qualified_name = set_subname( $qualified_name, $e->{code} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 390 | $meta->{immutable} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 278 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||