[Bps-public-commit] r15799 - Data-Hierarchy/trunk

clkao at bestpractical.com clkao at bestpractical.com
Mon Sep 8 06:52:46 EDT 2008


Author: clkao
Date: Mon Sep  8 06:52:46 2008
New Revision: 15799

Modified:
   Data-Hierarchy/trunk/   (props changed)
   Data-Hierarchy/trunk/Hierarchy.pm

Log:
 r35256 at mtl (orig r191):  clkao | 2004-09-14 07:44:20 +0800
 More constructor fixes and allowing empty key. [Autrijus Tang]


Modified: Data-Hierarchy/trunk/Hierarchy.pm
==============================================================================
--- Data-Hierarchy/trunk/Hierarchy.pm	(original)
+++ Data-Hierarchy/trunk/Hierarchy.pm	Mon Sep  8 06:52:46 2008
@@ -41,14 +41,13 @@
 
     my $self = bless {@_}, $class;
     $self->{sep} ||= '/';
-    $self->{hash} = shift || {};
-    $self->{sticky} = {};
+    $self->{hash} ||= {};
+    $self->{sticky} ||= {};
     return $self;
 }
 
 sub key_safe {
     use Carp;
-    confess 'key unsafe' unless $_[1];
     confess 'key unsafe'
 	if length ($_[1]) > 1 && substr ($_[1], -1, 1) eq $_[0]->{sep};
 
@@ -111,6 +110,10 @@
     my ($self, $key) = @_;
     use Carp;
     my $both = {%{$self->{hash}}, %{$self->{sticky} || {}}};
+
+    # If finding for everything, don't bother grepping
+    return sort keys %$both unless length($key);
+
     return sort grep {$key.$self->{sep} eq substr($_.$self->{sep}, 0,
 						  length($key)+1)}
 	keys %$both;



More information about the Bps-public-commit mailing list