my $f = Foo->new(); # normal creation print ref $f; # prints "Foo" print $f; # prints "Foo=HASH(0x19a0ef8)" my $aref = $f->getVariants(); # reference to array containing many Foos print ref $aref->[0]; # prints "Foo" print $aref->[0]; # prints "Foo=SCALAR(0x19c8290)" #### package Bar::Foo; use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); @ISA = qw( Bar ); %OWNER = (); %ITERATORS = (); sub new { my $pkg = shift; my $self = Barc::new_Foo(@_); bless $self, $pkg if defined($self); } sub DESTROY { return unless $_[0]->isa('HASH'); my $self = tied(%{$_[0]}); return unless defined $self; delete $ITERATORS{$self}; if (exists $OWNER{$self}) { Barc::delete_Foo($self); delete $OWNER{$self}; } } *AllVariants = *Barc::Foo_AllVariants; sub DISOWN { my $self = shift; my $ptr = tied(%$self); delete $OWNER{$ptr}; } sub ACQUIRE { my $self = shift; my $ptr = tied(%$self); $OWNER{$ptr} = 1; } #### SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Foo, SWIG_OWNER | SWIG_SHADOW) SWIG_NewPointerObj(x, SWIGTYPE_p_Foo, 0) #### %perlcode %{ sub getAllVariants { my ($self) = @_; my $fv = FooVariants->new($self); my $aref = []; while ( my $foo = $fv->getNext() ) { $foo->ACQUIRE(); # C++ code does not delete this, so ensure delete_ method is called push( @$aref, $foo ); } return $aref; } %}