aboutsummaryrefslogtreecommitdiff
path: root/lib/WebCoso
diff options
context:
space:
mode:
authordakkar <dakkar@luxion>2005-10-26 09:33:39 +0000
committerdakkar <dakkar@luxion>2005-10-26 09:33:39 +0000
commit57f05eac1683d0b56e54ac9fdb117120169be9aa (patch)
treefac769453ca960db5590a6ab1aa13439c1d1acda /lib/WebCoso
parentaggiornamento delle relazioni tra collezioni, e relazioni circolari (diff)
downloadWebCoso-57f05eac1683d0b56e54ac9fdb117120169be9aa.tar.gz
WebCoso-57f05eac1683d0b56e54ac9fdb117120169be9aa.tar.bz2
WebCoso-57f05eac1683d0b56e54ac9fdb117120169be9aa.zip
creato contenitore collezioni, migliorata gestione lingue
git-svn-id: svn://luxion/repos/WebCoso/trunk@18 fcb26f47-9200-0410-b104-b98ab5b095f3
Diffstat (limited to 'lib/WebCoso')
-rw-r--r--lib/WebCoso/Config.pm11
-rw-r--r--lib/WebCoso/Config/Collection.pm20
-rw-r--r--lib/WebCoso/Config/Collections.pm74
3 files changed, 95 insertions, 10 deletions
diff --git a/lib/WebCoso/Config.pm b/lib/WebCoso/Config.pm
index 3fbc597..9cef6a3 100644
--- a/lib/WebCoso/Config.pm
+++ b/lib/WebCoso/Config.pm
@@ -1,9 +1,10 @@
package WebCoso::Config;
use strict;
use warnings;
+use WebCoso::Config::Collections;
my @resources;
-my @collections;
+my $collections=WebCoso::Config::Collections->new();
sub read_scalar {
my ($class,$content,$filename)=@_;
@@ -33,16 +34,16 @@ sub get_all_resources {
sub add_collection {
my ($class,$collection)=@_;
- push @collections,$collection;
+ $collections->add_collection($collection);
}
-sub get_all_collections {
- return @collections;
+sub get_collections {
+ return $collections;
}
sub clear {
@resources=();
- @collections=();
+ $collections=WebCoso::Config::Collections->new();
}
package WebCoso::Config::Helpers;
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);
}
diff --git a/lib/WebCoso/Config/Collections.pm b/lib/WebCoso/Config/Collections.pm
new file mode 100644
index 0000000..7d4d9e0
--- /dev/null
+++ b/lib/WebCoso/Config/Collections.pm
@@ -0,0 +1,74 @@
+package WebCoso::Config::Collections;
+use strict;
+use warnings;
+use Class::Std;
+use List::MoreUtils 'any';
+
+{
+my %collections_of :ATTR( :get<collections_ref> );
+
+sub BUILD {
+ my ($self,$ident,$args_ref)=@_;
+
+ $collections_of{$ident} = [];
+}
+
+sub add_collection {
+ my ($self, $collection)=@_;
+
+ return if any { $_ eq $collection } $self->get_all_collections();
+
+ push @{ $self->get_collections_ref() }, $collection;
+}
+
+sub get_all_collections {
+ my ($self)=@_;
+ return @{ $self->get_collections_ref() };
+}
+
+sub get_root_collections {
+ my ($self)=@_;
+
+ return grep {
+ $_->get_parents() == 0
+ } $self->get_all_collections();
+}
+
+sub get_leaf_collections {
+ my ($self)=@_;
+
+ return grep {
+ $_->get_children() == 0
+ } $self->get_all_collections();
+}
+
+sub axes {
+ return 'language';
+}
+
+sub axis {
+ my ($self,$axis_name)=@_;
+ if ($axis_name eq 'language') {
+ return $self->_get_languages();
+ }
+ else {
+ return;
+ }
+}
+
+sub _get_languages {
+ my ($self)=@_;
+ my %langs=();
+
+ for my $collection ($self->get_all_collections()) {
+ @langs{ $collection->axis('language') } = ();
+ }
+
+ delete $langs{''};
+
+ return keys %langs;
+}
+
+}
+
+1;