Skip Menu |

This queue is for tickets about the Struct-Dumb CPAN distribution.

Report information
The Basics
Id: 107583
Status: resolved
Priority: 0/
Queue: Struct-Dumb

People
Owner: Nobody in particular
Requestors: leonerd-cpan [...] leonerd.org.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.04
Fixed in: 0.06



Subject: Dumb structs allow ARRAY unpacking
This could be said to be an internal implementation detail. Users shouldn't be @$struct'ing. It can lead to subtle bugs, especially if they were expecting it to fail. Should probably overload it with failure. -- Paul Evans
Fixed -- Paul Evans
Subject: rt107583.patch
=== modified file 'lib/Struct/Dumb.pm' --- lib/Struct/Dumb.pm 2015-09-30 17:31:56 +0000 +++ lib/Struct/Dumb.pm 2015-10-06 21:24:25 +0000 @@ -152,6 +152,7 @@ my %subs; foreach ( 0 .. $#$fields ) { my $idx = $_; + no overloading; $subs{$fields->[$idx]} = $lvalue ? sub :lvalue { shift->[$idx] } : sub { shift->[$idx] }; } @@ -192,6 +193,11 @@ if( my $predicate = $opts{predicate} ) { *{"${caller}::$predicate"} = sub { ( ref($_[0]) // "" ) eq $pkg }; } + + require overload; + $pkg->overload::OVERLOAD( + '@{}' => sub { croak "Cannot use $pkg as an ARRAY reference" }, + ); } =head2 struct === modified file 't/01point.t' --- t/01point.t 2014-07-24 08:49:50 +0000 +++ t/01point.t 2015-10-06 21:24:25 +0000 @@ -28,4 +28,8 @@ qr/^usage: main::Point\(\$x, \$y\) at \S+ line \d+\.?\n/, 'Point(30) throws usage exception' ); +like( exception { @{ Point(0, 0) } }, + qr/^Cannot use main::Point as an ARRAY reference at \S+ line \d+\.?\n/, + 'Array deref throws exception' ); + done_testing;
Patch released in 0.05. Critical bug about forgetting 'bool' overloading fixed in 0.06. -- Paul Evans