aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@luxion>2005-10-19 10:18:44 +0000
committerdakkar <dakkar@luxion>2005-10-19 10:18:44 +0000
commitc212d75031ee8b5c87551b7f025e6224d1e7fd6e (patch)
treee850c106721ce7221c1ba4192151e34449d79094
parentaggiunto supporto per parent/child tra collezioni (diff)
downloadWebCoso-c212d75031ee8b5c87551b7f025e6224d1e7fd6e.tar.gz
WebCoso-c212d75031ee8b5c87551b7f025e6224d1e7fd6e.tar.bz2
WebCoso-c212d75031ee8b5c87551b7f025e6224d1e7fd6e.zip
aggiornamento delle relazioni tra collezioni, e relazioni circolari
git-svn-id: svn://luxion/repos/WebCoso/trunk@7 fcb26f47-9200-0410-b104-b98ab5b095f3
-rw-r--r--lib/WebCoso/Config.pm1
-rw-r--r--lib/WebCoso/Config/Collection.pm32
-rw-r--r--t/01-config.t33
3 files changed, 54 insertions, 12 deletions
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<names> );
-my %parents_of :ATTR;
-my %children_of :ATTR;
-my %resources_of :ATTR( :init_arg<resources> );
+my %parents_of :ATTR( :get<parents_ref> );
+my %children_of :ATTR( :get<children_ref> );
+my %resources_of :ATTR( :init_arg<resources> :get<resources_ref> );
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() };
}
}
diff --git a/t/01-config.t b/t/01-config.t
index 4393eef..78000a3 100644
--- a/t/01-config.t
+++ b/t/01-config.t
@@ -163,3 +163,36 @@ is_deeply(
'c1 figlio di c2');
}
+
+WebCoso::Config->clear();
+
+{
+my $conf_file=<<'EOF';
+$c1=coll({it=>'coll1',en=>'coll1-en'});
+$c2=coll('coll2',[],[$c1]);
+$c1->add_child($c2);
+EOF
+
+ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"),
+ 'eseguita la configurazione (no strict)');
+
+my @collections=WebCoso::Config->get_all_collections();
+is(scalar @collections,2,'due collezioni');
+
+is_deeply(
+ [$collections[1]->get_children()],
+ [$collections[0]],
+ 'c1 figlio di c2');
+is_deeply(
+ [$collections[0]->get_parents()],
+ [$collections[1]],
+ 'c2 padre di c1');
+ is_deeply(
+ [$collections[0]->get_children()],
+ [$collections[1]],
+ 'c2 figlio di c1');
+is_deeply(
+ [$collections[1]->get_parents()],
+ [$collections[0]],
+ 'c1 padre di c2');
+}