Skip to content

Commit e20a83e

Browse files
committed
Delay croaking until use. Fixes RT #119534.
This is to maintain compatibility with modules that declare types but never use them. In 0.49, this could cause an exception if Sub::Defer::undefer_all was called.
1 parent a8b100c commit e20a83e

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

Changes

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ Revision history for MooseX-Types
22

33
{{$NEXT}}
44

5+
- re-added the is_Foo and to_Food refactoring after resolving
6+
RT #119534
7+
58
0.50 2017-02-07 18:59:30Z
69
- reverted the is_Foo and to_Foo refactoring again temporarily to
710
resolve issues with Sub::Defer
811

912
0.49 2016-12-23 00:12:12Z
1013
- made the exported is_Foo and to_Foo subs much faster, especially for
1114
type constraints which can be inlined. (Dave Rolsky) [reverted in
12-
0.50)
15+
0.50]
1316

1417
0.48 2016-12-07 01:15:14Z
1518
- reverted is_Foo and to_Foo refactoring [from 0.47] for now, so they

lib/MooseX/Types.pm

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,11 @@ sub coercion_export_generator {
491491
my ($value) = @_;
492492

493493
# we need a type object
494-
my $tobj = find_type_constraint($full) or croak $undef_msg;
494+
my $tobj = find_type_constraint($full);
495495

496496
return sub {
497+
croak $undef_msg unless $tobj;
498+
497499
my $return = $tobj->coerce($_[0]);
498500

499501
# non-successful coercion returns false
@@ -517,11 +519,15 @@ sub check_export_generator {
517519
my ($value) = @_;
518520

519521
# we need a type object
520-
my $tobj = find_type_constraint($full) or croak $undef_msg;
522+
my $tobj = find_type_constraint($full);
521523

522524
# This method will actually compile an inlined sub if possible. If
523525
# not, it will return something like sub { $tobj->check($_[0]) }
524-
return $tobj->_compiled_type_constraint;
526+
#
527+
# If $tobj is undef, we delay the croaking until the check is
528+
# actually used for backward compatibility reasons. See
529+
# RT #119534.
530+
return $tobj ? $tobj->_compiled_type_constraint : sub { croak $undef_msg};
525531
}
526532
}
527533

t/27-sub-defer.t

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,17 @@ unlike(
2525
'is_Int sub is now undeferred'
2626
);
2727

28+
{
29+
package MyTypes;
30+
31+
use MooseX::Types -declare => ['Unused'];
32+
33+
}
34+
35+
is(
36+
exception { undefer_all() },
37+
undef,
38+
'Sub::Defer::undefer_all does not throw an exception with unused type declaration'
39+
);
40+
2841
done_testing();

0 commit comments

Comments
 (0)