This is mostly a Perl question, I suspect.

I have a Rose::Object that represents a collection of files.  Call it
a "Collection".  Now, one of the attributes of a Collection is an
array called "files".  That array holds info about individual files as
Collection::File objects.

First, a Collection::File object needs access to the parent Collection
object.  So I have this method in Collection::File to save a weakened
reference to the parent:

    sub parent {
        my ( $self, $parent ) = @_;

        if ( $parent ) {
            return Scalar::Util::weaken( $self->{parent} = $parent );
        }

        return $self->{parent};
    }


And of course I use a bunch of methods like

    my $meta_data = $file->parent->meta_data;


So, now files can be containers, too.  So, I'm wondering about a
recursive structure.  So a Collection::File object can have a
"collection" attribute that would hold another Collection object.

The problem is I want to share the same meta data from the original
Collection.  So, one way might to to clone the parent

    if ( $file->is_zip_file ) {
        my $clone = $file->parent->clone;
        $clone->reset_files; # it's a clone w/o any files.

        $file->container( $clone );  # Save in this file

        for ( $file->zip_contents ) {
            $clone->add_to_files( $_ );
        }
    }

With the advantage that I can recursively process all the files in the
tree then (say if a zip file contains another zip file).


What's making my head hurt is I suspect that the clone will cause
circular links and prevent the destruction of the object.

Is there a better way to approach this -- or a way to weaken just the
right things when cloning?

Thanks,




-- 
Bill Moseley
[EMAIL PROTECTED]


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to