adding a tree filter for future common use
authormiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Thu, 22 Jun 2006 19:06:47 +0000 (19:06 +0000)
committermiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Thu, 22 Jun 2006 19:06:47 +0000 (19:06 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@739 9efc2488-bf62-4759-914b-345cdb29e865

src/perlmods/OpenSRF/Utils.pm

index 36e794d..90c73f4 100644 (file)
@@ -39,7 +39,7 @@ our $date_parser = DateTime::Format::ISO8601->new;
 #$Storable::forgive_me = 1;
 
 %EXPORT_TAGS = (
-       common          => [qw(interval_to_seconds seconds_to_interval sendmail)],
+       common          => [qw(interval_to_seconds seconds_to_interval sendmail tree_filter)],
        daemon          => [qw(safe_fork set_psname daemonize)],
        datetime        => [qw(clense_ISO8601 gmtime_ISO8601 interval_to_seconds seconds_to_interval)],
 );
@@ -77,6 +77,19 @@ sub _sub_builder {
        }
 }
 
+sub tree_filter {
+       my $tree = shift;
+       my $field = shift;
+       my $filter = shift;
+
+       my @things = $filter->($tree);
+       for my $v ( @{$tree->$field} ){
+               push @things, $filter->($v);
+               push @things, tree_filter($v, $field, $filter);
+       }
+       return @things
+}
+
 #sub standalone_ipc_cache {
 #      my $self = shift;
 #      my $class = ref($self) || $self;