Object-InsideOut - Re: How To Deal With Arrays Passed Into Objects During Initialization

Posted on Thu Dec 1 01:48:07 2005 by je44ery in response to 1425 (See the whole thread of 6)
Re: How To Deal With Arrays Passed Into Objects During Initialization
OK, this is my second response.

After posting yesterday, I finally figured out the right syntax to copy one array to another using an array reference. Thanks for the syntax, also. Confirmation is nice.

But that still leaves me with another conundrum. Take a look at this. It seems to be what I want.

$ cat Arraytest.pm package Arraytest; use strict; use warnings; use Object::InsideOut; my @data :Field('Std' => 'data'); my %init_args :InitArgs = ( 'DATA' => { 'Regex' => qr/^data/i, 'Type' => 'ARRAY', }, ); sub _init :Init { my ($self, $args) = @_; my $tmpref = $args->{DATA}; my @tmpdata = @$tmpref; $data[$$self] = \@tmpdata; } 1;

I have created a copy of the array, and now I have assigned the object field to point to it. However, since I created the array copy inside of a subroutine and declared it with my, doesn't the actual array that I'm pointing to get garbage collected after that subroutine ends? Won't I rapidly risk pointing to garbage when _init ends?

If that is true, and I don't see why it isn't, then how do I make the array copy itself persistent with the object?
Direct Responses: 1432 | Write a response