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?


Bill Moseley

This email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
Rose-db-object mailing list

Reply via email to