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

Posted on Wed Nov 30 02:08:48 2005 by je44ery
How To Deal With Arrays Passed Into Objects During Initialization
Sorry to post this simple how-to question, but this is my first time using Perl as anything other than a glorified awk.

I am passing in an array ref during object creation:

use warnings; use strict; use Hashtest; my $arrref = [ "hunger", "pain", "misery", ]; my $newobj = Hashtest->new( 'test1' => $arrref); exit 0;

Now, in order to encapsulate my data, I need to make a copy of this array inside the object, and modify that instead. It is doing this simple task that is confounding me. Here is my attempt-of-the-moment with my debug statments-of-the-moment:

package Hashtest; use strict; use warnings; use Object::InsideOut; my @test1 :Field; my %init_args :InitArgs = ( 'TEST1' => { 'Regex' => qr/^test1/i, 'Type' => 'ARRAY', # 'Field' => \@test1, }, ); sub _init :Init { my ($self, $args) = @_; my $tmpref = $args->{TEST1}; $test1[$$self] = @$tmpref; my $tmparr = $test1[$$self]; print "MADE IT = $tmparr\n"; print "MADE IT =? $test1[$$self]\n"; } 1;
Direct Responses: 1425 | Write a response