package WebCoso::Collections; use strict; use warnings; use Class::Std; use List::MoreUtils 'any'; { my %collections_of :ATTR( :get ); 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;