File tree Expand file tree Collapse file tree 4 files changed +31
-1
lines changed
Expand file tree Collapse file tree 4 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -653,6 +653,8 @@ These methods start and end with double underscores to reduce the chance
653653that they'll conflict with the name of a named parameter, however they are
654654considered part of the public, supported API.
655655
656+ The object overloads C<< @{} >> to call C<< __TO_ARRAYREF__ >>.
657+
656658=head4 C<< named_to_list >> B<< ArrayRef|Bool >>
657659
658660The C<named_to_list > option is ignored for signatures using positional
Original file line number Diff line number Diff line change @@ -1220,6 +1220,13 @@ sub make_extra_methods {
12201220 my $code = $coderef -> code;
12211221 local $@ ;
12221222 eval ( $code ) or die ( $@ );
1223+
1224+ Type::Tiny::_install_overloads(
1225+ $self -> bless ,
1226+ ' bool' => sub { 1 },
1227+ ' @{}' => ' __TO_ARRAYREF__' ,
1228+ ' fallback' => !!1,
1229+ );
12231230}
12241231
12251232sub return_wanted {
Original file line number Diff line number Diff line change 15531553 a dcs:Addition;
15541554 label "Type::Params now provides hooks for the event of wrapping a sub in a signature.";
15551555 ];
1556+ item [
1557+ a dcs:Addition;
1558+ label "Type::Params args objects now provide __TO_LIST__, __TO_ARRAYREF__, and __TO_HASHREF__ methods.";
1559+ ];
15561560 ].
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ use Types::Common -all;
3030
3131our @ARGS ;
3232
33- signature_for [ qw/ get_list get_arrayref get_hashref / ] => (
33+ signature_for [ qw/ get_list get_arrayref get_hashref be_arraylike / ] => (
3434 named => [
3535 foo => Int, { alias => ' fool' },
3636 bar => Optional[Int],
@@ -151,4 +151,21 @@ subtest '__TO_HASHREF__' => sub {
151151 );
152152};
153153
154+ sub be_arraylike {
155+ my $args = shift ;
156+ [ @{$args } ];
157+ }
158+
159+ subtest ' @{}' => sub {
160+ is_deeply(
161+ be_arraylike( foo => 66, bar => 99 ),
162+ [ 66, 99 ],
163+ );
164+
165+ is_deeply(
166+ be_arraylike( fool => 66 ),
167+ [ 66, undef ],
168+ );
169+ };
170+
154171done_testing;
You can’t perform that action at this time.
0 commit comments