Skip to content

Commit 1c9754b

Browse files
committed
Revert "revert the Sub::Defer changes again temporarily (see RT#119534, RT#120129)"
This reverts commit c8f752e.
1 parent 115d10e commit 1c9754b

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lib/MooseX/Types.pm

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use MooseX::Types::Util qw( filter_tags );
1212
use MooseX::Types::UndefinedType;
1313
use MooseX::Types::CheckedUtilExports ();
1414
use Carp::Clan qw( ^MooseX::Types );
15+
use Sub::Defer qw( defer_sub );
1516
use Sub::Name;
1617
use Scalar::Util qw( reftype );
1718
use Sub::Exporter::ForMethods 0.100052 'method_installer'; # for 'rebless'
@@ -486,17 +487,20 @@ This generates a coercion handler function, e.g. C<to_Int($value)>.
486487

487488
sub coercion_export_generator {
488489
my ($class, $type, $full, $undef_msg) = @_;
489-
return sub {
490+
return defer_sub undef, sub {
490491
my ($value) = @_;
491492

492493
# we need a type object
493494
my $tobj = find_type_constraint($full) or croak $undef_msg;
494-
my $return = $tobj->coerce($value);
495495

496-
# non-successful coercion returns false
497-
return unless $tobj->check($return);
496+
return sub {
497+
my $return = $tobj->coerce($_[0]);
498498

499-
return $return;
499+
# non-successful coercion returns false
500+
return unless $tobj->check($return);
501+
502+
return $return;
503+
};
500504
}
501505
}
502506

@@ -508,13 +512,16 @@ Generates a constraint check closure, e.g. C<is_Int($value)>.
508512

509513
sub check_export_generator {
510514
my ($class, $type, $full, $undef_msg) = @_;
511-
return sub {
515+
516+
return defer_sub undef, sub {
512517
my ($value) = @_;
513518

514519
# we need a type object
515520
my $tobj = find_type_constraint($full) or croak $undef_msg;
516521

517-
return $tobj->check($value);
522+
# This method will actually compile an inlined sub if possible. If
523+
# not, it will return something like sub { $tobj->check($_[0]) }
524+
return $tobj->_compiled_type_constraint;
518525
}
519526
}
520527

0 commit comments

Comments
 (0)