burninate documentation for DOM::Tiny
[catagits/DOM-Tiny.git] / lib / DOM / Tiny / _Collection.pm
index a053563..547946c 100644 (file)
@@ -6,11 +6,9 @@ use Carp 'croak';
 use List::Util;
 use Scalar::Util 'blessed';
 
-our $VERSION = '0.001';
+use constant REDUCE => ($] >= 5.008009 ? \&List::Util::reduce : \&_reduce);
 
-=for Pod::Coverage *EVERYTHING*
-
-=cut
+our $VERSION = '0.004';
 
 sub new {
   my $class = shift;
@@ -48,7 +46,7 @@ sub grep {
 }
 
 sub join {
-  join $_[1] // '', map {"$_"} @{$_[0]};
+  join +(defined($_[1]) ? $_[1] : ''), map {"$_"} @{$_[0]};
 }
 
 sub last { shift->[-1] }
@@ -61,7 +59,7 @@ sub map {
 sub reduce {
   my $self = shift;
   @_ = (@_, @$self);
-  goto &List::Util::reduce;
+  goto &{REDUCE()};
 }
 
 sub reverse { $_[0]->new(reverse @{$_[0]}) }
@@ -108,6 +106,31 @@ sub _flatten {
   map { _ref($_) ? _flatten(@$_) : $_ } @_;
 }
 
+# For perl < 5.8.9
+sub _reduce (&@) {
+  my $code = shift;
+
+  return shift unless @_ > 1;
+
+  my $caller = caller;
+
+  no strict 'refs';
+
+  local (*{"${caller}::a"}, *{"${caller}::b"}) = (\my $x, \my $y);
+
+  $x = shift;
+  foreach my $e (@_) {
+    $y = $e;
+    $x = $code->();
+  }
+
+  $x;
+}
+
 sub _ref { ref $_[0] eq 'ARRAY' || blessed $_[0] && $_[0]->isa(__PACKAGE__) }
 
 1;
+
+=for Pod::Coverage *EVERYTHING*
+
+=cut