=head2 C<mapper>
+A code reference that maps an object class name to the name of the package in which the coercion can be found, or C<undef> to disable coercion for this class name.
+It is called with the type constraint object as first argument, followed by the class name.
+
=cut
has 'mapper' => (
# If $thing isn't even an object, don't bother trying to autoload a coercion
my $class = blessed($thing);
if (defined $class) {
- # Find the file to autoload
- my $mapper = $tc->mapper;
- my $pm = $class = $tc->$mapper($class);
- $pm =~ s{::}{/}g;
- $pm .= '.pm';
-
- unless ($INC{$pm}) { # Not loaded yet
- local $@;
- eval {
- # We die often here, even though we're not really interested in the error.
- # However, if a die handler is set (e.g. to \&Carp::confess), this can get
- # very slow. Resetting the handler shows a 10% total time improvement for
- # the geodyn app.
- local $SIG{__DIE__};
- require $pm;
- };
+ $class = $tc->mapper->($tc, $class);
+
+ if (defined $class) {
+ # Find the file to autoload
+ (my $pm = $class) =~ s{::}{/}g;
+ $pm .= '.pm';
+
+ unless ($INC{$pm}) { # Not loaded yet
+ local $@;
+ eval {
+ # We die often here, even though we're not really interested in the error.
+ # However, if a die handler is set (e.g. to \&Carp::confess), this can get
+ # very slow. Resetting the handler shows a 10% total time improvement for
+ # the geodyn app.
+ local $SIG{__DIE__};
+ require $pm;
+ };
+ }
}
}