From c212d75031ee8b5c87551b7f025e6224d1e7fd6e Mon Sep 17 00:00:00 2001 From: dakkar Date: Wed, 19 Oct 2005 10:18:44 +0000 Subject: aggiornamento delle relazioni tra collezioni, e relazioni circolari git-svn-id: svn://luxion/repos/WebCoso/trunk@7 fcb26f47-9200-0410-b104-b98ab5b095f3 --- lib/WebCoso/Config.pm | 1 + lib/WebCoso/Config/Collection.pm | 32 ++++++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) (limited to 'lib/WebCoso') diff --git a/lib/WebCoso/Config.pm b/lib/WebCoso/Config.pm index 929b071..3fbc597 100644 --- a/lib/WebCoso/Config.pm +++ b/lib/WebCoso/Config.pm @@ -10,6 +10,7 @@ sub read_scalar { $WebCoso::Config::Helpers::FILENAME=$filename; $content=<<'EOF'.$content; package WEBCOSO::CONFIG; +no strict; WebCoso::Config::Helpers->import(); EOF eval $content; diff --git a/lib/WebCoso/Config/Collection.pm b/lib/WebCoso/Config/Collection.pm index 28e1892..367a53e 100644 --- a/lib/WebCoso/Config/Collection.pm +++ b/lib/WebCoso/Config/Collection.pm @@ -6,9 +6,9 @@ use WebCoso::Config; { my %names_of :ATTR( :get ); -my %parents_of :ATTR; -my %children_of :ATTR; -my %resources_of :ATTR( :init_arg ); +my %parents_of :ATTR( :get ); +my %children_of :ATTR( :get ); +my %resources_of :ATTR( :init_arg :get ); sub BUILD { my ($self,$ident,$args_ref)=@_; @@ -18,13 +18,13 @@ sub BUILD { $names={''=>$names} unless ref($names) eq 'HASH'; $names_of{$ident}=$names; - my $parents=$args_ref->{parents}; - $_->add_child($self) for @$parents; + my $parents=$args_ref->{parents} || []; $parents_of{$ident}=$parents; + $_->add_child($self) for @$parents; - my $children=$args_ref->{children}; - $_->add_parent($self) for @$children; + my $children=$args_ref->{children} || []; $children_of{$ident}=$children; + $_->add_parent($self) for @$children; WebCoso::Config->add_collection($self); } @@ -62,24 +62,32 @@ sub properties { sub add_child { my ($self,$child)=@_; - push @{ $children_of{ ident($self) } },$child; + + return if grep { $_ eq $child } @{ $self->get_children_ref() }; + + push @{ $self->get_children_ref() },$child; + $child->add_parent($self); } sub add_parent { my ($self,$parent)=@_; - push @{ $parents_of{ ident($self) } },$parent; + + return if grep { $_ eq $parent } @{ $self->get_parents_ref() }; + + push @{ $self->get_parents_ref() },$parent; + $parent->add_child($self); } sub get_parents { my ($self)=@_; - return @{ $parents_of{ ident($self) } }; + return @{ $self->get_parents_ref() }; } sub get_children { my ($self)=@_; - return @{ $children_of{ ident($self) } }; + return @{ $self->get_children_ref() }; } sub get_resources { my ($self)=@_; - return @{ $resources_of{ ident($self) } }; + return @{ $self->get_resources_ref() }; } } -- cgit v1.2.3