diff options
author | Toby Inkster <mail@tobyinkster.co.uk> | 2022-10-17 19:21:13 +0100 |
---|---|---|
committer | Toby Inkster <mail@tobyinkster.co.uk> | 2022-10-17 19:21:13 +0100 |
commit | e5603ff26dfe7fb7cb0e634a256065d3c71817cb (patch) | |
tree | 0505419a666204b4e06b382c842aafaa89675c38 /lib/Type/Library.pm | |
parent | 45a6a8846dbecd348db7afe1b8d636ea05b93a3b (diff) |
Get better at detecting conflicting functions in Type::Library if two types try to export functions with the same name
Diffstat (limited to 'lib/Type/Library.pm')
-rw-r--r-- | lib/Type/Library.pm | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/Type/Library.pm b/lib/Type/Library.pm index 682225fc..84ddcd59 100644 --- a/lib/Type/Library.pm +++ b/lib/Type/Library.pm @@ -223,7 +223,12 @@ sub add_type { "Type::Tiny"->new( library => $class, @_ ); my $name = $type->{name}; - _croak( 'Type %s already exists in this library', $name ) if $meta->has_type( $name ); + if ( $meta->has_type( $name ) ) { + my $existing = $meta->get_type( $name ); + return if $type->{uniq} == $existing->{uniq}; + _croak( 'Type %s already exists in this library', $name ); + } + _croak( 'Type %s conflicts with coercion of same name', $name ) if $meta->has_coercion( $name ); _croak( 'Cannot add anonymous type to a library' ) if $type->is_anon; $meta->{types} ||= {}; @@ -236,6 +241,8 @@ sub add_type { my $name = $exportable->{name}; my $code = $exportable->{code}; my $tags = $exportable->{tags}; + _croak( 'Function %s is provided by types %s and %s', $name, $meta->{'functions'}{$name}{'type'}->name, $type->name ) + if $meta->{'functions'}{$name}; *{"$class\::$name"} = set_subname( "$class\::$name", $code ); push @{"$class\::EXPORT_OK"}, $name; push @{ ${"$class\::EXPORT_TAGS"}{$_} ||= [] }, $name for @$tags; |