diff options
-rw-r--r-- | lib/WebCoso/Config.pm | 5 | ||||
-rw-r--r-- | lib/WebCoso/Config/Collection.pm | 33 | ||||
-rw-r--r-- | t/01-config.t | 36 |
3 files changed, 72 insertions, 2 deletions
diff --git a/lib/WebCoso/Config.pm b/lib/WebCoso/Config.pm index 74c150b..929b071 100644 --- a/lib/WebCoso/Config.pm +++ b/lib/WebCoso/Config.pm @@ -73,9 +73,12 @@ sub res { } sub coll { - my ($name)=@_; + my ($name,$parents,$children,$resources)=@_; WebCoso::Config::Collection->new({ name=>$name, + parents=>$parents||[], + children=>$children||[], + resources=>$resources||[], }); } diff --git a/lib/WebCoso/Config/Collection.pm b/lib/WebCoso/Config/Collection.pm index 6b5d201..28e1892 100644 --- a/lib/WebCoso/Config/Collection.pm +++ b/lib/WebCoso/Config/Collection.pm @@ -6,6 +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> ); sub BUILD { my ($self,$ident,$args_ref)=@_; @@ -15,6 +18,14 @@ sub BUILD { $names={''=>$names} unless ref($names) eq 'HASH'; $names_of{$ident}=$names; + my $parents=$args_ref->{parents}; + $_->add_child($self) for @$parents; + $parents_of{$ident}=$parents; + + my $children=$args_ref->{children}; + $_->add_parent($self) for @$children; + $children_of{$ident}=$children; + WebCoso::Config->add_collection($self); } @@ -49,6 +60,28 @@ sub properties { } } +sub add_child { + my ($self,$child)=@_; + push @{ $children_of{ ident($self) } },$child; +} +sub add_parent { + my ($self,$parent)=@_; + push @{ $parents_of{ ident($self) } },$parent; +} + +sub get_parents { + my ($self)=@_; + return @{ $parents_of{ ident($self) } }; +} +sub get_children { + my ($self)=@_; + return @{ $children_of{ ident($self) } }; +} +sub get_resources { + my ($self)=@_; + return @{ $resources_of{ ident($self) } }; +} + } 1; diff --git a/t/01-config.t b/t/01-config.t index c10dad6..4393eef 100644 --- a/t/01-config.t +++ b/t/01-config.t @@ -100,6 +100,19 @@ is_deeply( $props, {name=>'coll1'}, 'solo il nome'); + +is_deeply( + [$collections[0]->get_parents()], + [], + 'no parents'); +is_deeply( + [$collections[0]->get_children()], + [], + 'no children'); +is_deeply( + [$collections[0]->get_resources()], + [], + 'no resources'); } WebCoso::Config->clear(); @@ -107,7 +120,7 @@ WebCoso::Config->clear(); { my $conf_file=<<'EOF'; my $c1=coll({it=>'coll1',en=>'coll1-en'}); -coll('coll2',[$c1]); +coll('coll2',[],[$c1]); EOF ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"), @@ -116,6 +129,9 @@ ok(WebCoso::Config->read_scalar($conf_file,"$thisdir/config-in-test"), my @collections=WebCoso::Config->get_all_collections(); is(scalar @collections,2,'due collezioni'); +# qui sto assumendo che le collezioni vengano registrate in ordine di +# definizione. Forse non sarĂ sempre vero + is_deeply( [sort $collections[0]->axis('language')], ['en', 'it'], @@ -128,4 +144,22 @@ is( $collections[0]->properties(language=>'it')->{name}, 'coll1', 'nome it'); + +is_deeply( + [$collections[0]->get_parents()], + [$collections[1]], + 'c2 padre di c1'); +is_deeply( + [$collections[0]->get_children()], + [], + 'c1 no children'); +is_deeply( + [$collections[1]->get_parents()], + [], + 'c2 no parents'); +is_deeply( + [$collections[1]->get_children()], + [$collections[0]], + 'c1 figlio di c2'); + } |