aboutsummaryrefslogtreecommitdiff
path: root/lib/WebCoso/Collections.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/WebCoso/Collections.pm')
-rw-r--r--lib/WebCoso/Collections.pm74
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/WebCoso/Collections.pm b/lib/WebCoso/Collections.pm
new file mode 100644
index 0000000..f0f9815
--- /dev/null
+++ b/lib/WebCoso/Collections.pm
@@ -0,0 +1,74 @@
+package WebCoso::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 get_axes {
+ return 'language';
+}
+
+sub get_axis_values {
+ 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->get_axis_values('language') } = ();
+ }
+
+ delete $langs{''};
+
+ return keys %langs;
+}
+
+}
+
+1;