adding a tree filter for future common use
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 22 Jun 2006 19:06:47 +0000 (19:06 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 22 Jun 2006 19:06:47 +0000 (19:06 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@4716 dcc99617-32d9-48b4-a31d-7c20da2025e4

OpenSRF/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;