Skip Menu |

This queue is for tickets about the Class-MakeMethods CPAN distribution.

Report information
The Basics
Id: 13835
Status: new
Priority: 0/
Queue: Class-MakeMethods

People
Owner: Nobody in particular
Requestors: natg [...] shore.net
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.01
Fixed in: (no value)



Subject: slice and splice broken in Class::MakeMethods::Standard::Hash
The slice and splice operations described in the POD given an "Unexpected arguments to array accessor" error. See test program below. The problem seems to be the elsif's on lines 155 (for slice) and 159 (for splice) in Utility/ArraySplicer.pm. Current code: # SLICE } elsif ( ! scalar(@_) == 2 and ! defined $_[0] and ref $_[1] eq 'ARRAY' ) { ... # SPLICE } elsif ( ! scalar(@_) % 2 and ref $_[0] eq 'ARRAY' ) { ... Should be (I think): # SLICE } elsif ( scalar(@_) == 2 and ! defined $_[0] and ref $_[1] eq 'ARRAY' ) { ... # SPLICE } elsif ( !( scalar(@_) % 2 ) and ref $_[0] eq 'ARRAY' ) { ... The test program below fails on the code as released and passes on the code as patched above. I reran the test suite from the release but have not tested any other scenarios in detail, and cannot state with much confidence whether this breaks something else. Best, Nat Goodman -------------------- #!/usr/bin/perl use Test; BEGIN { plan tests => 7 } ######################################################################## package MyObject; use Class::MakeMethods::Standard::Hash ( new => 'new', array => 'items', ); ######################################################################## package main; ok( $obj_3 = MyObject->new() ); ok( $obj_3->items( ['apple', 'banana', 'cabbage'] ) ); # slice ok( join( ' ', $obj_3->items( undef, [1, 2] ) ) eq 'banana cabbage' ); # splice 1 element ok( $obj_3->items( [1, 1], 'kiwi' ) eq 'banana' ); ok( $obj_3->items( 1 ) eq 'kiwi' ); # splice 2 elements ok( $obj_3->items( [1, 1], 'strawberry', [2, 1], 'sauerkraut' ) ); # splice ok( join( ' ', $obj_3->items( undef, [1, 2] ) ) eq 'strawberry sauerkraut' ); --------------------