Loading ...
Sorry, an error occurred while loading the content.

deep objects_by_reference

Expand Messages
  • Steve Fink
    I am using SOAP::Lite to expose an API that is implemented using Inline::CPP, so I *have* to use the objects_by_reference stuff. But I noticed that the
    Message 1 of 2 , Jul 8, 2003
    • 0 Attachment
      I am using SOAP::Lite to expose an API that is implemented using
      Inline::CPP, so I *have* to use the objects_by_reference stuff. But I
      noticed that the referencing only happens on the top-level return
      value. Because of the way Inline::CPP works, I quite often have ARRAY
      refs that contain several objects that I need to access via reference.

      For now, I have patched my SOAP::Lite as given in the bottom of this
      message, so that any non-blessed references are traversed into when
      hunting for things to convert from objects to references for
      serialization. Is this a reasonable thing to be doing? Is there a
      clean way of getting this behavior without hacking on SOAP::Lite
      itself, perhaps by subclassing a serializer or something? This
      approach definitely incurs a performance penalty, but when using
      nonserializable objects like I am, something is necessary.

      I'm not sure why I picked non-blessed references. Perhaps any class
      not in the objects_by_reference list ought to be descended into.

      I have a related question, but I'll send it under a different subject
      line.

      --- /home/CPAN/build/SOAP-Lite-0.55/lib/SOAP/Lite.pm Tue Apr 16
      00:42:48 2002+++ /usr/lib/perl5/site_perl/5.6.1/SOAP/Lite.pm Mon Jul
      7 15:27:38 2003
      @@ -1919,10 +1920,25 @@
      bless { id => $id } => ref $object;
      }

      +sub maybe_reference {
      + my ($self, $obj) = @_;
      + my $ref = ref($obj) or return $obj;
      + if ($ref eq 'ARRAY') {
      + return [ $self->references(@$obj) ];
      + } elsif ($ref eq 'SCALAR') {
      + return \$self->maybe_reference($$obj);
      + } elsif ($ref eq 'HASH') {
      + $_ = $self->maybe_reference($_) for (values %$obj);
      + return $obj;
      + } else {
      + return exists $alive{$ref} ? $self->reference($obj) : $obj;
      + }
      +}
      +
      sub references {
      my $self = shift;
      return @_ unless %alive; # small optimization
      - map { ref($_) && exists $alive{ref $_} ? $self->reference($_) : $_
      } @_;
      + map { $self->maybe_reference($_) } @_;
      }

      sub object {
    • Steve Fink
      I am using SOAP::Lite to expose an API that is implemented using Inline::CPP, so I *have* to use the objects_by_reference stuff. But I noticed that the
      Message 2 of 2 , Jul 8, 2003
      • 0 Attachment
        I am using SOAP::Lite to expose an API that is implemented using
        Inline::CPP, so I *have* to use the objects_by_reference stuff. But I
        noticed that the referencing only happens on the top-level return
        value. Because of the way Inline::CPP works, I quite often have ARRAY
        refs that contain several objects that I need to access via reference.

        For now, I have patched my SOAP::Lite as given in the bottom of this
        message, so that any non-blessed references are traversed into when
        hunting for things to convert from objects to references for
        serialization. Is this a reasonable thing to be doing? Is there a
        clean way of getting this behavior without hacking on SOAP::Lite
        itself, perhaps by subclassing a serializer or something? This
        approach definitely incurs a performance penalty, but when using
        nonserializable objects like I am, something is necessary.

        I'm not sure why I picked non-blessed references. Perhaps any class
        not in the objects_by_reference list ought to be descended into.

        I have a related question, but I'll send it under a different subject
        line.

        --- /home/CPAN/build/SOAP-Lite-0.55/lib/SOAP/Lite.pm Tue Apr 16
        00:42:48 2002+++ /usr/lib/perl5/site_perl/5.6.1/SOAP/Lite.pm Mon Jul
        7 15:27:38 2003
        @@ -1919,10 +1920,25 @@
        bless { id => $id } => ref $object;
        }

        +sub maybe_reference {
        + my ($self, $obj) = @_;
        + my $ref = ref($obj) or return $obj;
        + if ($ref eq 'ARRAY') {
        + return [ $self->references(@$obj) ];
        + } elsif ($ref eq 'SCALAR') {
        + return \$self->maybe_reference($$obj);
        + } elsif ($ref eq 'HASH') {
        + $_ = $self->maybe_reference($_) for (values %$obj);
        + return $obj;
        + } else {
        + return exists $alive{$ref} ? $self->reference($obj) : $obj;
        + }
        +}
        +
        sub references {
        my $self = shift;
        return @_ unless %alive; # small optimization
        - map { ref($_) && exists $alive{ref $_} ? $self->reference($_) : $_
        } @_;
        + map { $self->maybe_reference($_) } @_;
        }

        sub object {
      Your message has been successfully submitted and would be delivered to recipients shortly.