1use Test::More; 2use strict; use warnings FATAL => 'all'; 3 4use List::Objects::WithUtils 'array'; 5 6my $arr = array( 1 .. 7 ); 7my $sliced = $arr->sliced(0, 2); 8is_deeply 9 [ $sliced->all ], 10 [ 1, 3 ], 11 'sliced (2 element) ok'; 12 13$sliced = $arr->sliced(0, 2, 4); 14is_deeply 15 [ $sliced->all ], 16 [ 1, 3, 5 ], 17 'sliced (3 element) ok'; 18 19is_deeply 20 [ $arr->slice(0, 2, 4)->all ], 21 [ $sliced->all ], 22 'slice alias ok'; 23 24my $empty = array; 25is_deeply 26 [ $empty->sliced(2, 4)->all ], 27 [ undef, undef ], 28 'sliced (nonexistant elements) ok'; 29ok $empty->is_empty, 'empty array intact after slice ok' 30 or diag explain $empty; 31 32done_testing 33