From ceb37da2d2b6a0c13b396bd8fc2c519e46c5d5fc Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 10 Jan 2006 14:21:01 +0000 Subject: [PATCH] added an insert_method function for attaching functions to objects updated "insert" to allow function insertion miker fixed a bug in the array insert code for fieldmapper getter / setters git-svn-id: svn://svn.open-ils.org/ILS/trunk@2669 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Utils/SpiderMonkey.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/SpiderMonkey.pm b/Open-ILS/src/perlmods/OpenILS/Utils/SpiderMonkey.pm index f52abd5923..87ba29d78b 100644 --- a/Open-ILS/src/perlmods/OpenILS/Utils/SpiderMonkey.pm +++ b/Open-ILS/src/perlmods/OpenILS/Utils/SpiderMonkey.pm @@ -76,6 +76,13 @@ sub retrieve { return $self->context->property_get($key); } +sub insert_method { + my( $self, $obj_key, $meth_name, $sub ) = @_; + my $obj = $self->context->object_by_path( $obj_key ); + $self->context->function_set( $meth_name, $sub, $obj ) if $obj; +} + + sub insert { my( $self, $key, $val ) = @_; return unless defined($val); @@ -86,6 +93,8 @@ sub insert { $self->insert_array($key, $val); } elsif (ref($val) and $val =~ /HASH/o) { $self->insert_hash($key, $val); + } elsif (ref($val) and $val =~ /CODE/o) { + $self->context->function_set( $key, $val ); } elsif (!ref($val)) { $self->context->property_by_path( $key, $val, @@ -152,6 +161,7 @@ sub insert_hash { } } +my $__array_id = 0; sub insert_array { my( $self, $key, $array ) = @_; @@ -163,9 +173,10 @@ sub insert_array { my $ind = 0; for my $v ( @$array ) { if (ref $v) { - my $elobj = $ctx->object_by_path('__tmp_arr_el'); - $self->insert('__tmp_arr_el', $v); + my $elobj = $ctx->object_by_path('__tmp_arr_el'.$__array_id); + $self->insert('__tmp_arr_el'.$__array_id, $v); $ctx->array_set_element_as_object( $a, $ind, $elobj ); + $__array_id++; } else { $ctx->array_set_element( $a, $ind, $v ) if defined($v); } -- 2.43.2