diff options
Diffstat (limited to 'lib/WebCoso/Config/Collection.pm')
-rw-r--r-- | lib/WebCoso/Config/Collection.pm | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/WebCoso/Config/Collection.pm b/lib/WebCoso/Config/Collection.pm index 367a53e..c4b6347 100644 --- a/lib/WebCoso/Config/Collection.pm +++ b/lib/WebCoso/Config/Collection.pm @@ -2,6 +2,8 @@ package WebCoso::Config::Collection; use strict; use warnings; use Class::Std; +use Scalar::Util 'weaken'; +use List::MoreUtils 'any'; use WebCoso::Config; { @@ -36,7 +38,7 @@ sub axes { sub axis { my ($self,$axis_name)=@_; if ($axis_name eq 'language') { - return keys %{ $self->get_names() } + return grep { $_ } keys %{ $self->get_names() } } else { return; @@ -47,13 +49,18 @@ sub properties { my ($self,$axis_name,$axis_value,@rest)=@_; if (@rest==0 and $axis_name eq 'language') { - if ( grep { $_ eq $axis_value } + if ( any { $_ eq $axis_value } keys %{ $self->get_names() } ) { return { name => $self->get_names()->{$axis_value} }; } + elsif (exists ${$self->get_names()}{''}) { + return { + name => $self->get_names()->{''} + }; + } else { return; } @@ -63,7 +70,7 @@ sub properties { sub add_child { my ($self,$child)=@_; - return if grep { $_ eq $child } @{ $self->get_children_ref() }; + return if any { $_ eq $child } @{ $self->get_children_ref() }; push @{ $self->get_children_ref() },$child; $child->add_parent($self); @@ -71,9 +78,12 @@ sub add_child { sub add_parent { my ($self,$parent)=@_; - return if grep { $_ eq $parent } @{ $self->get_parents_ref() }; + return if any { $_ eq $parent } @{ $self->get_parents_ref() }; + + my $weak_parent=$parent; + weaken $weak_parent; - push @{ $self->get_parents_ref() },$parent; + push @{ $self->get_parents_ref() },$weak_parent; $parent->add_child($self); } |