Changeset 21350
- Timestamp:
- 10/15/08 11:51:42 (5 years ago)
- Files:
-
- 1 modified
-
lang/perl/List-Rubyish/trunk/lib/List/Rubyish.pm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/List-Rubyish/trunk/lib/List/Rubyish.pm
r21322 r21350 2 2 use strict; 3 3 use warnings; 4 use overload 5 '<<' => 'push', 6 '+' => 'add', 7 fallback => 1; 8 4 9 our $VERSION = '0.01'; 5 10 … … 10 15 sub new { 11 16 my ($class, $array) = @_; 12 $class = ref $class ||$class;17 $class = ref $class if ref $class; 13 18 $array ||= []; 14 19 croak sprintf("Argument must be an array reference (%s)", ref $array) … … 47 52 sub slice { 48 53 my $self = CORE::shift; 49 my ($s , $e) = @_;54 my ($start, $end) = @_; 50 55 my $last = $#{$self}; 51 # warn "s: $s, e: $e, last: $last"; 52 if (defined $e) { 53 if ($s == 0 && $last <= $e) { 56 if (defined $end) { 57 if ($start == 0 && $last <= $end) { 54 58 return $self; 55 59 } else { 56 $e = $last if ($last < $e);57 return $self->new([ @$self[ $s .. $e] ]);60 $end = $last if $last < $end; 61 return $self->new([ @$self[ $start .. $end ] ]); 58 62 } 59 } elsif (defined $s && 0 < $s && $last <= $s) { 60 # warn $self->first . "s: $s, e: $e, self:" . $#{$self}; 63 } elsif (defined $start && 0 < $start && $last <= $start) { 61 64 return $self->new([]); 62 65 } else { … … 203 206 204 207 sub find { 205 my ($self, $code) = @_; 206 croak "Argument must be a code" unless ref $code eq 'CODE'; 208 my ($self, $cond) = @_; 209 my $code = (ref $cond and ref $cond eq 'CODE') 210 ? $cond 211 : sub { $_ eq $cond }; 212 207 213 for (@$self) { &$code and return $_ } 214 return; 208 215 } 209 216 … … 211 218 my ($self, $target) = @_; 212 219 my $code = (ref $target eq 'CODE') ? $target : sub { CORE::shift eq $target }; 220 213 221 for (my $i = 0; $i < $self->length; $i++) { 214 &$code($self->[$i]) and return $i;222 $code->($self->[$i]) and return $i; 215 223 } 224 return; 216 225 } 217 226
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)